-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (74 loc) · 3.94 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
from app import app
import urllib.request
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from keras.applications.imagenet_utils import preprocess_input, decode_predictions
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def upload_form():
return render_template('upload.html')
@app.route('/', methods=['POST'])
def upload_image():
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], '1.jpg'))
#print('upload_image filename: ' + filename)
flash('Image successfully uploaded and displayed below')
return render_template('upload.html', filename='1.jpg')
else:
flash('Allowed image types are -> png, jpg, jpeg, gif')
return redirect(request.url)
@app.route('/display/<filename>')
def display_image(filename):
#print('display_image filename: ' + filename)
return redirect(url_for('static', filename='uploads/' + filename), code=301)
@app.route('/my-link/')
def my_link():
print ('I got clicked!')
MODEL_PATH = 'model.h5'
# Load your trained model
model = load_model(MODEL_PATH)
new_img = image.load_img('C:/Users/ASUS/Desktop/New folder/static/uploads/1.jpg', target_size=(256, 256))
# Preprocessing the image
img = image.img_to_array(new_img)
# x = np.true_divide(x, 255)
img = np.expand_dims(img, axis=0)
img = img/255
# Be careful how your trained model deals with the input
# otherwise, it won't make correct prediction!
prediction = model.predict(img)
d = prediction.flatten()
j = d.max()
li = ['Apple___Apple_scab','Apple___Black_rot','Apple___Cedar_apple_rust','Apple___healthy','Blueberry___healthy','Cherry_(including_sour)___Powdery_mildew','Cherry_(including_sour)___healthy','Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot','Corn_(maize)___Common_rust_','Corn_(maize)___Northern_Leaf_Blight','Corn_(maize)___healthy','Grape___Black_rot','Grape___Esca_(Black_Measles)','Grape___Leaf_blight_(Isariopsis_Leaf_Spot)','Grape___healthy','Orange___Haunglongbing_(Citrus_greening)','Peach___Bacterial_spot','Peach___healthy','Pepper,_bell___Bacterial_spot','Pepper,_bell___healthy','Potato___Early_blight','Potato___Late_blight','Potato___healthy','Raspberry___healthy','Soybean___healthy','Squash___Powdery_mildew','Strawberry___Leaf_scorch','Strawberry___healthy','Tomato___Bacterial_spot','Tomato___Early_blight','Tomato___Late_blight','Tomato___Leaf_Mold','Tomato___Septoria_leaf_spot','Tomato___Spider_mites Two-spotted_spider_mite','Tomato___Target_Spot','Tomato___Tomato_Yellow_Leaf_Curl_Virus','Tomato___Tomato_mosaic_virus','Tomato___healthy','background']
for index,item in enumerate(d):
if item == j:
class_name = li[index]
print("Following is our prediction:")
return class_name
@app.route("/", methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if request.form.get('action1') == 'VALUE1':
pass # do something
elif request.form.get('action2') == 'VALUE2':
pass # do something else
else:
pass # unknown
elif request.method == 'GET':
return render_template('index.html', form=form)
return render_template("index.html")
if __name__ == "__main__":
app.run(port=4996)