levi15 commited on
Commit
82d4752
1 Parent(s): 75ed1be

Upload app (5).py

Browse files
Files changed (1) hide show
  1. app (5).py +45 -0
app (5).py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from keras.models import load_model
3
+ from keras.preprocessing import image
4
+
5
+ app = Flask(__name__)
6
+
7
+ dic = {0 : 'Cat', 1 : 'Dog'}
8
+
9
+ model = load_model('model.h5')
10
+
11
+ model.make_predict_function()
12
+
13
+ def predict_label(img_path):
14
+ i = image.load_img(img_path, target_size=(100,100))
15
+ i = image.img_to_array(i)/255.0
16
+ i = i.reshape(1, 100,100,3)
17
+ p = model.predict_classes(i)
18
+ return dic[p[0]]
19
+
20
+
21
+ # routes
22
+ @app.route("/", methods=['GET', 'POST'])
23
+ def main():
24
+ return render_template("index.html")
25
+
26
+ @app.route("/about")
27
+ def about_page():
28
+ return "Please subscribe Artificial Intelligence Hub..!!!"
29
+
30
+ @app.route("/submit", methods = ['GET', 'POST'])
31
+ def get_output():
32
+ if request.method == 'POST':
33
+ img = request.files['my_image']
34
+
35
+ img_path = "static/" + img.filename
36
+ img.save(img_path)
37
+
38
+ p = predict_label(img_path)
39
+
40
+ return render_template("index.html", prediction = p, img_path = img_path)
41
+
42
+
43
+ if __name__ =='__main__':
44
+ #app.debug = True
45
+ app.run(debug = True)