-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaf.py
89 lines (61 loc) · 2.96 KB
/
leaf.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
89
#Import necessary libraries
from flask import Flask, render_template, request
import numpy as np
import os
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.models import load_model
filepath = 'C:/Users/Balapriya/AppData/Local/Programs/Python/Python311/Plant-Leaf-Disease-Prediction-main/model.h5'
model = load_model(filepath)
print(model)
print("Model Loaded Successfully")
def pred_tomato_dieas(tomato_plant):
test_image = load_img(tomato_plant, target_size = (128, 128)) # load image
print("@@ Got Image for prediction")
test_image = img_to_array(test_image)/255 # convert image to np array and normalize
test_image = np.expand_dims(test_image, axis = 0) # change dimention 3D to 4D
result = model.predict(test_image) # predict diseased palnt or not
print('@@ Raw result = ', result)
pred = np.argmax(result, axis=1)
print(pred)
if pred==0:
return "Tomato - Bacteria Spot Disease", 'Tomato-Bacteria Spot.html'
elif pred==1:
return "Tomato - Early Blight Disease", 'Tomato-Early_Blight.html'
elif pred==2:
return "Tomato - Healthy and Fresh", 'Tomato-Healthy.html'
elif pred==3:
return "Tomato - Late Blight Disease", 'Tomato - Late_blight.html'
elif pred==4:
return "Tomato - Leaf Mold Disease", 'Tomato - Leaf_Mold.html'
elif pred==5:
return "Tomato - Septoria Leaf Spot Disease", 'Tomato - Septoria_leaf_spot.html'
elif pred==6:
return "Tomato - Target Spot Disease", 'Tomato - Target_Spot.html'
elif pred==7:
return "Tomato - Tomoato Yellow Leaf Curl Virus Disease", 'Tomato - Tomato_Yellow_Leaf_Curl_Virus.html'
elif pred==8:
return "Tomato - Tomato Mosaic Virus Disease", 'Tomato - Tomato_mosaic_virus.html'
elif pred==9:
return "Tomato - Two Spotted Spider Mite Disease", 'Tomato - Two-spotted_spider_mite.html'
# Create flask instance
app = Flask(__name__)
# render index.html page
@app.route("/", methods=['GET', 'POST'])
def home():
return render_template('index.html')
# get input image from client then predict class and render respective .html page for solution
@app.route("/predict", methods = ['GET','POST'])
def predict():
if request.method == 'POST':
file = request.files['image'] # fet input
filename = file.filename
print("@@ Input posted = ", filename)
file_path = os.path.join('C:/Users/Balapriya/AppData/Local/Programs/Python/Python311/Plant-Leaf-Disease-Prediction-main/static/upload/', filename)
file.save(file_path)
print("@@ Predicting class......")
pred, output_page = pred_tomato_dieas(tomato_plant=file_path)
return render_template(output_page, pred_output = pred, user_image = file_path)
# For local system & cloud
if __name__ == "__main__":
app.run(threaded=False,port=8080)