def upload_image(): current_user = get_jwt_identity() user = User.get_or_none(User.username == current_user) data = request.files["image"].filename print( "*****************************************TESTING*******************************************" ) print(data) print( "*****************************************TESTING*******************************************" ) data_image = data if user: result = {} Images.create( image_path=f"http://krishnaybucket.s3.amazonaws.com/{data_image}", user=user) result["image_url"] = data_image result["success"] = True return jsonify(result) else: result = {} result["message"] = "No image provided" result["success"] = "failed" return jsonify(result)
def info(name): image = Images.get_or_none(Images.name == name) if image: return render_template('images/info.html', image=image) else: return 'Fail'
def index(): if(current_user.is_authenticated): feed_images = Images.select().where(Images.user.in_(current_user.following())).order_by(Images.created_at.desc()) myidols = User.select().join(Follows, on=(Follows.myidol_id == User.id)).where(Follows.myfan_id == current_user.id) return render_template('home.html', feed_images = feed_images, user=myidols) else: return render_template('signin.html')
def upload_images(): try: file = request.files.get("imgs") s3.upload_fileobj(file, "krishnaybucket", file.filename, ExtraArgs={ "ACL": "public-read", "ContentType": file.content_type }) user = User.get_or_none(User.id == current_user.id) Images.create( image_path= f"http://krishnaybucket.s3.amazonaws.com/{file.filename}", user=user) return redirect(url_for("home")) except Exception as e: print("Something Happened: ", e) flash("Cannot upload nothing") return redirect(url_for("home"))
def facts(id): image = Images.get_or_none(Images.id == id) facts = Facts.select().where(Facts.place == image.name) results = [] for fact in facts: results.append({ "username": User.get_or_none(User.id == fact.user_id).username, "title": fact.title, "text": fact.text, "id": fact.id }) return jsonify(results)
def upload_postfile(): # A if "user_file" not in request.files: return "No user_file key in request.files" # B file = request.files["user_file"] """ These attributes are also available file.filename # The actual name of the file file.content_type file.content_length file.mimetype """ # C. if file.filename == "": return "Please select a file" # D. if file: # file.filename = secure_filename(file.filename) # breakpoint() output = upload_file_to_s3(file, "hipster-bucket", acl="public-read") # return str(output) # breakpoint() new_image = Images(user=current_user.id, image_url=file.filename) # breakpoint() new_image.save() return render_template('my_profile.html') else: return render_template('my_profile.html')
def newfact(id): current_user_id = get_jwt_identity() image = Images.get_by_id(id) fact = Facts( # images_id=image.id, title=request.json.get('title'), text=request.json.get('text'), user_id=current_user_id, place=image.name) if fact.save(): result = {"title": fact.title, "text": fact.text, "place": fact.place} return jsonify(result) else: return jsonify(fact.errors, {"status": "failed"}), 400
def getuserimages(id): images = [] for image in Images.select().where(Images.user_id == id): images.append({ "src": f'https://{os.environ.get("S3_BUCKET")}.s3-eu-west-2.amazonaws.com/' + image.image, "width": image.width, "height": image.height, "id": image.id, "title": image.name }) return jsonify(images)
def getimage(id): # result = [] image = Images.get_or_none(Images.id == id) user = User.get_or_none(User.id == image.user_id) if image: response = { 'name': image.name, 'url': f'https://{os.environ.get("S3_BUCKET")}.s3-eu-west-2.amazonaws.com/' + image.image, 'description': image.description, 'latitude': image.latitude, 'longitude': image.longitude, 'user': user.username, 'profileImage': user.profile_image_path } # result.append(response) return jsonify(response)
def location(): placename = request.form.get('placename') images = Images.select().where(Images.name.contains(placename)) results = [] if images: for image in images: results.append({ "src": f'https://{os.environ.get("S3_BUCKET")}.s3-eu-west-2.amazonaws.com/' + image.image, "width": image.width, "height": image.height, "title": image.name, "id": image.id }) return jsonify(results) else: flash('no images for this location yet.') return jsonify({"status": "failed"}), 400
def detect_landmarks_uri(): """Detects landmarks in the file.""" picture = request.files.get('user_image') current_user_id = get_jwt_identity() randomString = uuid.uuid4().hex randomString = randomString[0:8] picture.filename = randomString + '.png' try: s3.upload_fileobj( picture, os.environ.get('S3_BUCKET'), picture.filename, ExtraArgs={ "ACL": 'public-read', "ContentType": picture.content_type } ) except: flash('Upload unsuccessful') cred = service_account.Credentials.from_service_account_info({"type": "service_account","project_id": "landmarkit-1574492827189","private_key_id": "8516f1b9582bb8c3f93bf28e8ecf68db09a7e379","private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDQzLJb+EU62HYR\n8nAvypuitRc8gL7zFMiCwzGLpXVwZ9WcmEfYp7gcItKiYExk6t7CPjezulUx/mSR\nsWXMk4k9L87rgUS/SBsLjC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RnGJEUkgEzCxacRH2+nf4nn4\nCe95xgV8Q1Pr1A6jueA4f0NcLUgIUU6LEWkxlUuYMSxpSEsAuNkIQOPk4QKBgGaY\nsrlZrI4jWrjhSzYg3XTHpRXJUJ+hhvKuVYgsXHladLJFErS9wul376/1gHIqI4T2\nE7eNj+IIUOHQKewRkic1VoRcyhNG3ARHv/IE+a1UURXwZ5ZqQh9cROmxcMGga34q\nWIHhN9vvO89ROrVAH/hZciaNnPpdFk9dHEDoTDgDAoGBAPTrLSWomEonyoMCj/lm\noh16QM8fZqd9f0M47e3bIlxzailwF3ddYZ1xM3M6l5eGqnpfatNa8Sc+u0vXyjTb\n9WvmqZNJylkyC+FJuH5wy+BDnVtXUOR1mAZE5NgYUOSZC28T0n6sd0c6L7rt6iX1\nr2TEikVRckD69R1GmVDMVxCc\n-----END PRIVATE KEY-----\n","client_email": "*****@*****.**","client_id": "104823819347629366265","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/starting-account-2xyb6t56zwpw%40landmarkit-1574492827189.iam.gserviceaccount.com"}) client = vision.ImageAnnotatorClient(credentials=cred) image = vision.types.Image() path = f'https://{os.environ.get("S3_BUCKET")}.s3-eu-west-2.amazonaws.com/' + \ picture.filename image.source.image_uri = path response = client.landmark_detection(image=image) landmarks = response.landmark_annotations # print('Landmarks:') # kg_id = landmarks[0].mid # kg_request = requests.get( # f"https://kgsearch.googleapis.com/v1/entities:search?ids={kg_id}&key={os.environ.get('GOOGLE_KG_API_KEY')}&limit=1&indent=True") # kg = kg_request.json() result = [ { "mid": landmark.mid, "name": landmark.description, "score": landmark.score, "locations": [ { "lat_lng": { "latitude": landmark.locations[0].lat_lng.latitude, "longitude": landmark.locations[0].lat_lng.longitude } } ], # "description": kg["itemListElement"][0]["result"]["detailedDescription"]["articleBody"] } for landmark in landmarks ] name1 = result[0]["name"] wiki = wikipedia.summary(name1) width = random.randint(3, 4) height = random.randint(3, 4) add = Images(image=picture.filename, name=result[0]["name"], description=wiki, latitude=result[0]["locations"][0]["lat_lng"]["latitude"], longitude=result[0]["locations"][0]["lat_lng"]["longitude"], user_id=current_user_id, width=width, height=height) add.save() result2 = [ { "mid": landmark.mid, "name": landmark.description, "score": landmark.score, "id": add.id, "locations": [ { "lat_lng": { "latitude": landmark.locations[0].lat_lng.latitude, "longitude": landmark.locations[0].lat_lng.longitude } } ], # "description": kg["itemListElement"][0]["result"]["detailedDescription"]["articleBody"] } for landmark in landmarks ] return jsonify(result2)
def home(): user=User.select() images=Images.select() return render_template('home.html',user=user,images=images)