-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
66 lines (52 loc) · 1.81 KB
/
app.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
65
66
import tensorflow as tf
import numpy as np
from flask import Flask, render_template, request, send_from_directory
import cv2
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
from io import BytesIO
import urllib
COUNT = 0
app = Flask(__name__)
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 1
@app.route('/')
def man():
return render_template('link.html')
@app.route('/home', methods=['POST'])
def home():
if request.method == 'POST':
global COUNT
img = request.files['image']
model = tf.keras.models.load_model('model/CM_Classifier_1')
img.save('static/{}.jpg'.format(COUNT))
img_arr = image.load_img('static/{}.jpg'.format(COUNT), target_size=(150, 150))
x=image.img_to_array(img_arr)
x=np.expand_dims(x, axis=0)
images = np.vstack([x])
prediction = model.predict(images)
preds = np.array(prediction)
COUNT += 1
return render_template('prediction.html', data=preds)
@app.route('/main', methods=['POST'])
def main():
if request.method == 'POST':
model = tf.keras.models.load_model('model/CM_Classifier_1')
preds = 0
global COUNT
URL = request.form['URL']
with urllib.request.urlopen(URL) as url:
img = image.load_img(BytesIO(url.read()), target_size=(150, 150))
img.save('static/{}.jpg'.format(COUNT))
x=image.img_to_array(img)
x=np.expand_dims(x, axis=0)
images = np.vstack([x])
prediction = model.predict(images)
preds = np.array(prediction)
COUNT += 1
return render_template('prediction.html', data=preds)
@app.route('/load_imge')
def load_imge():
global COUNT
return send_from_directory('static', "{}.jpg".format(COUNT-1))
if __name__ == '__main__':
app.run(debug = True)