forked from Suphachock/Project_Snake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app2.py
49 lines (34 loc) · 1.18 KB
/
app2.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
# -*- coding: utf-8 -*-
from flask import Flask, render_template, request
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
app = Flask(__name__)
dic = {0: 'African', 1: 'Americas', 2: 'Asian', 3: 'Europe'}
model = load_model('project.h5')
model.make_predict_function()
def predict_label(img_path):
i = image.load_img(img_path, target_size=(100,100))
i = image.img_to_array(i)/255
i = i.reshape(1, 100, 100, 3)
predict_x = model.predict(i)
classes_x = np.argmax(predict_x, axis=1)
return dic[classes_x[0]]
# routes
@app.route("/", methods=['GET', 'POST'])
def main():
return render_template("index.html")
@app.route("/about")
def about_page():
return "Please subscribe Artificial Intelligence Hub..!!!"
@app.route("/submit", methods=['GET', 'POST'])
def get_output():
if request.method == 'POST':
img = request.files['my_image']
img_path = "static/" + img.filename
img.save(img_path)
p = predict_label(img_path)
return render_template("index.html", prediction=p, img_path=img_path, prediction2=p.split(" "))
if __name__ == '__main__':
#app.debug = True
app.run(debug=True)