-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (53 loc) · 1.68 KB
/
main.py
File metadata and controls
72 lines (53 loc) · 1.68 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Flask, request, redirect, render_template
import numpy as np
from PIL import Image
import base64
import json
from io import BytesIO
import requests
app = Flask(__name__)
app.secret_key = "counter=0"
# a route where we will display a welcome message via an HTML template
message = "Home"
@app.route("/")
def index():
return render_template('home.html', message="Home")
app.config["TEMPLATES_AUTO_RELOAD"] = True
url = 'http://5db6c444c5a9.ngrok.io/predict'
@app.route('/predict', methods=['GET', 'POST'])
@app.route("/model")
def predict():
chk = requests.get(url).status_code
if chk == 404:
return render_template('model.html', message="404")
files = request.files.getlist('uploadFile')
pred = {}
if len(files) > 10:
return redirect('/model')
for file in files:
img = Image.open(file)
img = img.resize((256, 256))
buffered = BytesIO()
img.save(buffered, format="PNG")
pim = base64.b64encode(buffered.getvalue())
j = {"img": str(pim)}
r = requests.post(url, json=json.dumps(j)).json()
print(r)
res = r["pred"]
res = res.split()
res[1] = float(res[1])*100.0
if res[1] < 95:
res[0] = "What ?!!"
pred[str(pim)[2:-1]] = res[0]
return render_template('model.html', message=pred)
@app.route("/documentation")
def doc():
return render_template('documentation.html', message="doc")
@app.route("/user_manuals")
def user():
return render_template('user_manuals.html', message="user")
@app.route("/about_us")
def about():
return render_template('about_us.html', message="about")
if __name__ == '__main__':
app.run()