-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (57 loc) · 2.31 KB
/
Copy pathapp.py
File metadata and controls
68 lines (57 loc) · 2.31 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
from flask import Flask, render_template, Response, request
from lib.Process import VideoCamera
from lib.ModelProcess import ModelProcess
from lib.Sudoku import Sudoku
# Define const
N = 9
# Define objs
app = Flask(__name__)
mp = ModelProcess("save_model/Digit_Recognizer.h5")
model = mp.get_model()
sudoku = Sudoku(N)
default_solution = [[0 for _ in range(N)] for _ in range(N)] # N by N list
status = "Please show a puzzle to the webcam."
@app.route('/', methods=["GET", "POST"])
def index():
if request.method == "POST":
grid = sudoku.get_grid()
solution = default_solution
return render_template('index.html', grid=grid,
solution=solution, status=status)
else:
sudoku.reset()
grid = sudoku.get_grid()
solution = default_solution
return render_template('index.html', grid=grid,
solution=solution, status=status)
@app.route('/solve', methods=["GET", "POST"])
def solve():
if request.method == "POST":
fixed_nums_flatten = \
[int(digit) for digit in request.form.getlist("name")]
fixed_grid = sudoku.create_grid_from_list(fixed_nums_flatten)
status, solution = sudoku.solve(fixed_grid)
if status:
status = "Found a solution being displayed down below."
return render_template('index.html',
grid=fixed_grid,
solution=solution, status=status)
else:
status = "Could not find a solution, please try another one."
return render_template('index.html',
grid=fixed_grid,
solution=fixed_grid, status=status)
else: # ERROR: nerve called without clicking solve button
grid = sudoku.get_grid()
return render_template('index.html', grid=grid)
@app.route('/video_feed')
def video_feed():
def gen(camera):
while True:
frame = camera.sudoku_cv()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
return Response(gen(VideoCamera(model, sudoku)),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)