-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
58 lines (33 loc) · 1.25 KB
/
routes.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
from flask import Flask, render_template, request, redirect, url_for, jsonify
from model_output import *
from bokeh.plotting import figure
from bokeh.embed import components
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def main():
if request.method == 'GET':
plots = []
plots.append(make_plot([[0 for i in range(10)]]))
return render_template('paint.html', plots=plots)
if request.method == "POST":
data_url = request.form['save_image']
img = handle_image(data_url)
prediction, softmax = predict(img)
plots = []
plots.append(make_plot(softmax))
return jsonify(prediction=str(prediction), plots=plots)
def make_plot(softmax):
y = [str(i) for i in range(10)]
x = [i for i in softmax[0]]
plot = figure(title='Prediction Probabilities',
y_range=y, plot_height=400, plot_width=400,
toolbar_location=None, tools='')
plot.hbar(y=y, right=x, height=0.9, fill_alpha=0.8, fill_color='navy')
plot.ygrid.grid_line_color = None
plot.xgrid.grid_line_color = None
plot.x_range.start = 0
plot.x_range.end = 1
script, div = components(plot)
return script, div
if __name__ == '__main__':
app.run()