-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
30 lines (26 loc) · 896 Bytes
/
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
from flask import Flask, render_template, request, make_response, jsonify
import cv2
import numpy as np
import base64
import model
app = Flask(__name__)
PROBABILITY_TRESHOLD = 0.6
@app.route('/')
def index():
return render_template("index.html")
@app.route('/upload', methods=['POST'])
def upload():
img = base64.b64decode(request.data)
img = cv2.imdecode(np.frombuffer(img, np.uint8), cv2.IMREAD_UNCHANGED)
predictions = model.predict(img)
predictions = list(sorted(predictions, key=lambda x: x.get("probability"), reverse=True))
print(predictions)
if predictions and predictions[0].get("probability") > PROBABILITY_TRESHOLD:
predictions = [predictions[0]]
else:
predictions = []
print(predictions)
print("\n\n")
return jsonify({"predictions": predictions})
if __name__ == '__main__':
app.run(debug=True, port=5000)