-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (34 loc) · 1.35 KB
/
app.py
File metadata and controls
46 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"])
def rekognise():
if "image" not in request.files:
return jsonify({"error": "No file part"}), 400
file = request.files["image"]
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 __name__ == "__main__":
app.run(debug=True)