-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (44 loc) · 1.46 KB
/
main.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
from wsgiref import simple_server
from flask import Flask, request, jsonify, render_template
from flask import Response
import os
from flask_cors import CORS
from research.obj import MultiClassObj
from com_in_ineuron_ai_utils.utils import decodeImage
os.putenv('LANG', 'en_US.UTF-8')
os.putenv('LC_ALL', 'en_US.UTF-8')
app = Flask(__name__)
CORS(app)
class Api:
def __init__(self):
self.filename = "inputImage.jpg"
modelPath = 'research/ssd_mobilenet_v1_coco_2017_11_17'
self.classifier = MultiClassObj(self.filename,modelPath)
@app.route("/", methods=['GET'])
def home():
return render_template("index.html")
@app.route("/predict", methods=['POST'])
def predictRoute():
try:
image = request.json['image']
decodeImage(image, "inputImage.jpg")
#result = cliApp.classifier.getPrediction("inputImage.jpg")
result = cliApp.classifier.getPrediction()
#return jsonify(result)
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__":
cliApp = Api()
host = '0.0.0.0'
port = 5000
httpd = simple_server.make_server(host, port, app)
print("Serving on %s %d" % (host, port))
httpd.serve_forever()