-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (59 loc) · 2.9 KB
/
Copy pathapp.py
File metadata and controls
76 lines (59 loc) · 2.9 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask, render_template, request, session,redirect, url_for,jsonify
from flask_restful import Api, Resource
from prediction import getPediction
import collections
import keras
from TextToSpeech import initialiseSounds
#app initialization
app = Flask(__name__)
app.config['SECRET_KEY'] = "superdupersecretkey"
UPLOAD_FOLDER = 'static/images'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
#load model
model = keras.models.load_model("./myModel/final_save")
@app.route('/',methods=['GET','POST'])
def getIndex():
return render_template("index.html")
@app.route("/doProcess",methods=['POST'])
def doThings():
#save the image -----------------------------------------------------------------------------------------
imagefile = request.files['imagefile']
splitting = imagefile.filename.split('.')
extension = splitting[len(splitting)-1].lower()
defaultFilename = "todo."+extension
image_path ="./static/images/" + defaultFilename
imagefile.save(image_path)
#do prediction -----------------------------------------------------------------------------------------
cropped_img_name_list,label_list,bounding_for_each_label = getPediction(image_path,model)
#info dictionary for template filling ------------------------------------------------------------------
croppedImageList_andLabels = collections.OrderedDict()
for i in range(len(cropped_img_name_list)) :
croppedImageList_andLabels[cropped_img_name_list[i]] = label_list[i]
#session to pass variables to other fun ----------------------------------------------------------------
session['croppedImageList_andLabels'] = croppedImageList_andLabels
session['image_name'] = defaultFilename
return redirect(url_for('showPredictions')+"?q="+label_list[0])
@app.route('/prediction',methods=['GET'])
def showPredictions():
return render_template("prediction.html",
baseImage = session['image_name'],
croppedImageList_andLabels = session['croppedImageList_andLabels'])
#API SECTION :
#test--------------------------------------------------------------------------------------------------
api = Api(app)
todos ={}
class ObjectDetectionAPI(Resource):
def post(self):
imagefile = request.files['imagefile']
splitting = imagefile.filename.split('.')
extension = splitting[len(splitting)-1].lower()
defaultFilename = "todo."+extension
image_path ="./static/images/" + defaultFilename
imagefile.save(image_path)
#do prediction -----------------------------------------------------------------------------------------
cropped_img_name_list,label_list,bounding_for_each_label = getPediction(image_path,model,api=True)
return bounding_for_each_label
api.add_resource(ObjectDetectionAPI, "/api/detect")
if __name__=="__main__":
initialiseSounds()
app.run(host= '0.0.0.0',port=5000,debug=True)