-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
82 lines (52 loc) · 1.93 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sys,os
from signLanguage.pipeline.training_pipeline import TrainPipeline
from signLanguage.exception import SignException
from signLanguage.utils.main_utils import decodeImage, encodeImageIntoBase64
from flask import Flask, request, jsonify, render_template,Response
from flask_cors import CORS, cross_origin
from signLanguage.constant.application import APP_HOST, APP_PORT
app = Flask(__name__)
CORS(app)
class ClientApp:
def __init__(self):
self.filename = "inputImage.jpg"
@app.route("/train")
def trainRoute():
obj = TrainPipeline()
obj.run_pipeline()
return "Training Successfull!!"
@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, clApp.filename)
os.system("cd yolov5/ && python detect.py --weights my_model.pt --img 416 --conf 0.5 --source ../data/inputImage.jpg")
opencodedbase64 = encodeImageIntoBase64("yolov5/runs/detect/exp/inputImage.jpg")
result = {"image": opencodedbase64.decode('utf-8')}
os.system("rm -rf yolov5/runs")
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)
@app.route("/live", methods=['GET'])
@cross_origin()
def predictLive():
try:
os.system("cd yolov5/ && python detect.py --weights my_model.pt --img 416 --conf 0.5 --source 0")
os.system("rm -rf yolov5/runs")
return "Camera starting!!"
except ValueError as val:
print(val)
return Response("Value not found inside json data")
if __name__ == "__main__":
clApp = ClientApp()
app.run(host=APP_HOST, port=APP_PORT)