forked from henryle-n/Handwriting-Prediction-Tensorflow2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
64 lines (49 loc) · 1.85 KB
/
application.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
# Author: Henry Le
# Date: Jul. 18, 2020
# version 0 - first release
# if you somehow find this file of mine on github, please feel free to take and modify it.
# I wish you the best of luck on what you want to do.
# learning coding is not easy as it's about learning a new language but definitely FUN FUN FUN !!!
# SO, HAVE FUN !
# dependencies
import os
from predict import img_predict
import flask
from flask import Flask, jsonify, render_template, request
import tensorboard as tb
from werkzeug import serving
from werkzeug.middleware import dispatcher
import sys, os, io
import json
import time
################## Flask App set up###############
app = Flask(__name__)
##################################################
@app.route("/", methods=["GET", "POST"])
def home_page():
''' Home Page Access Route'''
return render_template("index.html")
# access route to prediction model
@app.route("/prediction", methods=["GET", "POST"])
def predict():
'''
create a 2 way communication channels between client and server
GET , POST method to take incoming data from client
'''
incoming_pkg = request.get_json()
# if the packages come in slow, may cause issue of empty package (obj)
while incoming_pkg is None:
app.logger.debug("Waiting for receiving POST package from Client ...")
time.sleep(1)
else:
app.logger.error("Package from Client has been received!")
img_b64_str_encoded = str(incoming_pkg['imgBase64'])
app.logger.error("Processing and Predicting Which Digit ...")
prediction = int(img_predict(img_b64_str_encoded))
response = f'{prediction}'
app.logger.error(jsonify(prediction=response))
return jsonify(prediction=response)
# if program is run from this file ::
if __name__ == '__main__':
app.run(debug=True)
app.logger.error("FLASK SERVER is RUNNING from ROOT!")