-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (36 loc) · 1.3 KB
/
Copy pathmain.py
File metadata and controls
46 lines (36 loc) · 1.3 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
from flask import Flask, render_template, request
import tensorflow as tf
import os
from utils import unified_predict
app = Flask(__name__)
UPLOAD_FOLDER = "static/uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
baseline_model = tf.keras.models.load_model("model/word_recognition_basline_model.keras")
transfer_model = tf.keras.models.load_model("model/word_recognition_transfer_learning_model.keras")
digit_model = tf.keras.models.load_model("model/digit_recognition_model.keras")
@app.route("/", methods=["GET", "POST"])
def index():
result, confidence, model_used, image_path = [None] * 4
if request.method == "POST":
file = request.files["image"]
if file and file.filename:
image_path = os.path.join(UPLOAD_FOLDER, file.filename)
file.save(image_path)
output = unified_predict(
image_path,
baseline_model,
transfer_model,
digit_model
)
result = output["text"]
confidence = output["confidence"]
model_used = output["model"]
return render_template(
"index.html",
result=result,
confidence=confidence,
model_used=model_used,
image=image_path
)
if __name__ == "__main__":
app.run(debug=True)