-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (47 loc) · 1.75 KB
/
app.py
File metadata and controls
61 lines (47 loc) · 1.75 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask, request, render_template, abort
from modules import face, object as obj, utility
from models import result
from waitress import serve
def create_app():
# create and configure the app
app = Flask("got it", instance_relative_config=True)
# configure max size of payload content
app.config['MAX_CONTENT_LENGTH'] = 15 * 1024 * 1024
# app routes here
@app.route("/", methods=["GET"])
def index():
return render_template('index.html')
@app.route("/api/face/detect", methods=["POST"])
def face_detection():
return face.extract_face(request.json)
@app.route("/api/face/match", methods=["POST"])
def face_recognition():
return face.recognition(request.json)
@app.route("/api/object/detect", methods=["POST"])
def object_detection():
return obj.detect(request.json)
@app.route("/api/object/match", methods=["POST"])
def object_recognition():
return obj.recognition(request.json)
@app.errorhandler(400)
def bad_request(error):
return result.failed(None, str(error), 400)
@app.errorhandler(401)
def bad_request(error):
return result.failed(None, str(error), 401)
@app.errorhandler(404)
def not_found(error):
return result.failed(None, str(error), 404)
@app.errorhandler(405)
def method_not_allowed(error):
return result.failed(None, str(error), 405)
@app.errorhandler(413)
def request_entity_too_large(error):
return result.failed(None, str(error), 413)
return app
if __name__ == "__main__":
app = create_app()
# to start server run this command
# windows: SET FLASK_APP=app.py & flask run
# linux: export FLASK_APP=app.py & flask run
serve(app)