forked from Itope84/star-spotter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (45 loc) · 1.74 KB
/
app.py
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
47
48
49
50
51
52
53
54
55
56
57
58
from find_actor import find_actor_by_image, find_actor_profile, find_actor_id
from flask import Flask, request, jsonify, Response
from flask_cors import CORS
import requests
app = Flask(__name__)
# Allow cross-origin request from all domains
CORS(app, resources={r"/*": {"origins": ["https://app.star-spotter.com"]}})
@app.route('/img_proxy')
def img_proxy():
image_url = request.args.get('url')
if not image_url:
return "No URL provided", 400
try:
response = requests.get(image_url)
return Response(response.content, content_type=response.headers['Content-Type'])
except requests.RequestException as e:
return str(e), 500
@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)