Skip to content

Commit

Permalink
add cors support for web
Browse files Browse the repository at this point in the history
  • Loading branch information
Itope84 committed Jan 8, 2024
1 parent 7b87971 commit 7b6c1aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
__pycache__
Binary file removed __pycache__/find_actor.cpython-310.pyc
Binary file not shown.
38 changes: 22 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
from find_actor import find_actor_by_image, find_actor_profile, find_actor_id
from flask import Flask, request, jsonify
from flask_cors import CORS

app = Flask(__name__)

# TODO: Enable CORS for allowed origins to enable web support.
# CORS(app, resources={r"/*": {"origins": "*"}})


@app.route("/status", methods=["GET"])
def get_status():
return jsonify({"message": "Hello world"})


@app.route("/search", methods=["GET"])
def search():
actor_name = request.args.get('name', default='')
actor_id = find_actor_id(actor_name)
if actor_id is not None:
actor_profile = find_actor_profile(actor_id)
return jsonify(actor_profile)
else:
return jsonify({"error": "Actor not found"}), 404

@app.route("/rekognise", methods =["POST"])
actor_name = request.args.get("name", default="")
actor_id = find_actor_id(actor_name)
if actor_id is not None:
actor_profile = find_actor_profile(actor_id)
return jsonify(actor_profile)
else:
return jsonify({"error": "Actor not found"}), 404


@app.route("/rekognise", methods=["POST"])
def rekognise():
if 'image' not in request.files:
if "image" not in request.files:
return jsonify({"error": "No file part"}), 400

file = request.files['image']
file = request.files["image"]

if file and file.filename != '':
if file and file.filename != "":
actor_name = find_actor_by_image(file)
if actor_name is not None:
return jsonify({"name": actor_name})
else:
return jsonify({"error": "Actor not found"}), 404
else:
# If the user does not select a file, the browser submits an empty file without a filename.
return jsonify({"error": "No selected file"}), 400
# If the user does not select a file, the browser submits an empty file without a filename.
return jsonify({"error": "No selected file"}), 400


if __name__ == "__main__":
app.run(debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ boto3==1.34.7
botocore==1.34.7
urllib3==1.26.18
zappa==0.58.0
Flask-Cors==4.0.0

0 comments on commit 7b6c1aa

Please sign in to comment.