-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
47 lines (36 loc) · 1.25 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
from flask import Flask, request, jsonify, render_template, Response
import os
from flask_cors import CORS, cross_origin
from apparel_detection.Settings import Settings
from apparel_detection.ai_utils.utils import decodeImage
from apparel_detection.yolo_detector.prediction_manager import ApparelDetection
# import sys
# sys.path.insert(0, './apparel_detection')
os.putenv('LANG', 'en_US.UTF-8')
os.putenv('LC_ALL', 'en_US.UTF-8')
app = Flask(__name__)
CORS(app)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/predict", methods=['POST', 'GET'])
@cross_origin()
def predictRoute():
try:
image = request.json['image']
decodeImage(image, Settings.input_image_name, Settings.input_image_path)
result = objectDetection.run_inference()
except ValueError as val:
print(val)
return Response("Value not found inside json data")
except KeyError:
return Response("Key value error incorrect key passed")
except Exception as e:
print(e)
result = "Invalid input"
return jsonify(result)
# port = int(os.getenv("PORT"))
if __name__ == "__main__":
objectDetection = ApparelDetection(Settings.input_image_name)
port = 9500
app.run(host='0.0.0.0', port=port)