-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlaskWebpage.py
67 lines (53 loc) · 1.62 KB
/
FlaskWebpage.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
from flask import Flask, jsonify, request, render_template
import numpy as np
import joblib
import cv2
import traceback
from Box_Character import Box_Character
from equationClass import equation
from TrainCNN import loadModel
app = Flask(__name__)
model = None
@app.route('/')
def main():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('index.html')
@app.route('/run',methods=["POST"])
def run():
global model
try:
# Initialize equation storage
LatexEq = equation([],[])
# Grab user image
image = request.files['file'].read()
arr = cv2.imdecode(np.fromstring(image,np.uint8), cv2.IMREAD_UNCHANGED)
# Need to breakup images into parts
images = Box_Character(arr)
# Predict each part and append to equation
for im in images:
im = im.reshape((1,45,45,1))
preds = model.predict(im)
print(preds)
pred = preds.argmax()
print(pred)
LatexEq.appendTerm(pred,0)
# Latex format
latex = LatexEq.printLatex()
# Send to webpage
return jsonify({
"message": f"Latex Format: {latex}",
"latex":latex
})
except Exception as e:
print(traceback.format_exc())
return jsonify({
"message" : f"An error occurred. {e}"
})
@app.route('/run-ui')
def run_ui():
return render_template("process.html")
if __name__ == '__main__':
model = loadModel((45,45,1),66,'training/cp-0016.ckpt')
app.run(debug=True)