-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (45 loc) · 1.88 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
import os
import base64
import time
import numpy as np
from flask import Flask, flash, request, redirect, url_for,render_template
from werkzeug.utils import secure_filename
from test_ml import ml_softmax_test,cnn_test,cnn_new_test
UPLOAD_FOLDER = './pics'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/")
def index():
return render_template("index.html",count=1)
# WRITE ON A 32X32 CANVAS AND GIVE IMAGE TO THE PICKLE EXPORT TO GUESS WHAT NUMBER IT IS
@app.route("/test", methods=['GET', 'POST'])
def test():
if request.method == 'POST':
if 'file' not in request.values:
flash('No file part')
return redirect(request.url)
file = request.values['file']
#remove the begining of the file
file = file.replace("data:image/png;base64,", "")
convert_and_save(file)
cnn_result,cnn_all = cnn_new_test("imageToSave.png")
sga_result,sga_all = ml_softmax_test("imageToSave.png")
total_results = {"cnn":[str(cnn_result),cnn_all.tolist()],"sga":[str(sga_result),sga_all.tolist()]}
return total_results
@app.route("/save", methods=['GET','POST'])
def save():
if request.method == 'POST':
if 'file' not in request.values:
flash('No file part')
return redirect(request.url)
file = request.values['file']
number = request.values['number']
#remove the begining of the file
file = file.replace("data:image/png;base64,", "")
convert_and_save(file,"pics/"+str(number)+"/"+str(time.time())+".png")
return 'Image saved at '+ str(number)+"/"+str(time.time())
def convert_and_save(b64_string,filename="imageToSave.png"):
with open(filename, "wb") as fh:
fh.write(base64.decodebytes(b64_string.encode()))
if __name__ == "__main__":
app.run(debug=True)