-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
136 lines (111 loc) · 3.12 KB
/
server.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from flask import Flask, render_template, Response, session, redirect,url_for, request, json
from mt_video_feed import VideoFeed
import time
from keras.models import load_model
import tensorflow as tf
from questions import Generator
from feed_back import positive_feedback
app = Flask(__name__)
model = load_model('assets/mobilenet.h5')
model._make_predict_function()
graph = tf.get_default_graph()
ans = -1
score = 0
vs = VideoFeed(model)
converter = {}
converter["NONE"] = 0
converter["ONE"] = 1
converter["TWO"] = 2
converter["THREE"] = 3
converter["FOUR"] = 4
converter["FIVE"] = 5
global counter
counter = 0
global CORRECT
CORRECT = 0
@app.route('/')
def main_page():
return render_template('main_page.html')
@app.route('/video_feed')
def video_feed():
global graph
global p1, p2
def generate(camera):
global CORRECT
global ans
global counter
while True:
img,frame = camera.get_frame()
p1, p2 = camera.get_prediction()
if p1 != "" and p2 != "":
op1 = converter[p1]
op2 = converter[p2]
user_ans = op1 + op2
else:
user_ans = -2
if user_ans == ans:
counter+=1
CORRECT = 1
if (CORRECT and counter>15):
pf = positive_feedback()
step = pf.detect_eyes(img)
for(i,y) in enumerate(step):
pf_frame = pf.gif_generator(i,y,img)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + pf_frame + b'\r\n\r\n')
time.sleep(3)
CORRECT = 0
counter = 0
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
with graph.as_default():
return app.response_class(generate(vs),
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/game_selector')
def game_selector():
return render_template('game_selector.html')
@app.route('/finger_game')
def finger_game():
return render_template('finger_game.html')
@app.route('/finger_add', methods=['GET', 'POST'])
def finger_add():
global ans
num1, num2, a = Generator().questions_generator(1)
ans =a
return render_template('finger_operation.html', num1 = num1, num2 = num2, mode = 1 )
@app.route('/finger_sub', methods=['GET', 'POST'])
def finger_sub():
global ans
num1, num2, a = Generator().questions_generator(2)
ans =a
return render_template('finger_operation.html', num1 = num1, num2 = num2, mode = 2 )
@app.route('/finger_mul', methods=['GET', 'POST'])
def finger_mul():
global ans
num1, num2, a = Generator().questions_generator(3)
ans =a
return render_template('finger_operation.html', num1 = num1, num2 = num2, mode = 3 )
@app.route('/finger_div', methods=['GET', 'POST'])
def finger_div():
global ans
num1, num2, a = Generator().questions_generator(4)
ans =a
return render_template('finger_operation.html', num1 = num1,num2 = num2,mode = 4 )
@app.route('/check')
def check():
global ans
global score
global converter
p1, p2 = vs.get_prediction()
if p1 != "" and p2 != "":
op1 = converter[p1]
op2 = converter[p2]
user_ans = op1 + op2
else:
user_ans = -2
if user_ans == ans:
global CORRECT
CORRECT = 1
return render_template('finger_score.html', score = score)
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000, debug=True)