-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflask_app.py
59 lines (47 loc) · 1.47 KB
/
flask_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
59
from flask import Flask, request, redirect, json
import flask_cors
from flask_cors import CORS
import os
from src.classifier import FAZ_Classifier
application = Flask(__name__)
CORS(application)
# IMAGE_FOLDER = os.path.abspath('images')
SOURCE = os.path.abspath("images")
# SOURCE = "/Users/macbook5/Desktop/aws/app/static/images"
IMAGE_FOLDER = os.path.join(SOURCE, "raw")
PREDICTED_FOLDER = os.path.join(SOURCE, "predict")
classifier = FAZ_Classifier()
##### checking error in server ######
@application.route("/")
def index():
return "API"
#http error
@application.errorhandler(404)
def url_error(e):
return application.response_class(
response=""" Wrong url
<pre>{}</pre>""".format(e),
status= 404,
mimetype= 'html/text'
)
# checking internal error
@application.errorhandler(500)
def url_error(e):
return application.response_class(
response=""" An internal error occured:
<pre>{}</pre>""".format(e),
status= 500,
mimetype= "html/text"
)
@application.route("/faz/predict", methods = ["GET"])
def predict():
imageID = request.args.get('id')
image_path = os.path.join(IMAGE_FOLDER, imageID)
result = classifier.predict(image_path, PREDICTED_FOLDER)
return application.response_class(
response= json.dumps({"image_path": result}),
status= 200,
mimetype= 'application/json'
)
if __name__ == "__main__":
application.run(host= '0.0.0.0', port=2000)