Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,11 @@ from keras.models import load_model
|
|
4 |
import numpy as np
|
5 |
|
6 |
# Load the pre-trained model from the local path
|
7 |
-
model_path = '
|
8 |
model = load_model(model_path) # Load the model here
|
9 |
|
10 |
def predict_disease(image_file, model, all_labels):
|
11 |
-
|
12 |
try:
|
13 |
# Load and preprocess the image
|
14 |
img = load_img(image_file, target_size=(224, 224)) # Use load_img from tensorflow.keras.utils
|
@@ -24,53 +24,11 @@ def predict_disease(image_file, model, all_labels):
|
|
24 |
predicted_label = all_labels[predicted_class]
|
25 |
|
26 |
# Print the predicted label to the console
|
27 |
-
|
28 |
-
if predicted_label=='Mango Anthracrose':
|
29 |
-
predicted_label = """<style>
|
30 |
-
li{
|
31 |
-
font-size: 15px;
|
32 |
-
margin-left: 90px;
|
33 |
-
margin-top: 15px;
|
34 |
-
margin-bottom: 15px;
|
35 |
-
}
|
36 |
-
h4{
|
37 |
-
font-size: 17px;
|
38 |
-
margin-top: 15px;
|
39 |
-
}
|
40 |
-
h4:hover{
|
41 |
-
cursor: pointer;
|
42 |
-
}
|
43 |
-
|
44 |
-
h3:hover{
|
45 |
-
cursor: pointer;
|
46 |
-
color: blue;
|
47 |
-
transform: scale(1.3);
|
48 |
-
}
|
49 |
-
.note{
|
50 |
-
text-align: center;
|
51 |
-
font-size: 16px;
|
52 |
-
}
|
53 |
-
p{
|
54 |
-
font-size: 13px;
|
55 |
-
text-align: center;
|
56 |
-
}
|
57 |
-
|
58 |
-
</style>
|
59 |
-
<h3><center><b>Mango Anthracrose</b></center></h3>
|
60 |
-
<h4>PESTICIDES TO BE USED:</h4>
|
61 |
-
<ul>
|
62 |
-
<li>1. Mancozeb</li>
|
63 |
-
<li>2. Azoxystrobin</li>
|
64 |
-
<li>3. carbendazim</li>
|
65 |
-
<li>4. Propiconazole</li>
|
66 |
-
<li>5. Thiophanate-methyl</li>
|
67 |
-
<li>6. Copper Sulfate</li>
|
68 |
-
</ul><br>
|
69 |
-
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
70 |
-
<p>Be sure to follow local regulations and guidelines for application</p>
|
71 |
|
72 |
-
|
73 |
-
|
|
|
|
|
74 |
predicted_label = """
|
75 |
<style>
|
76 |
li{
|
@@ -102,70 +60,23 @@ def predict_disease(image_file, model, all_labels):
|
|
102 |
}
|
103 |
|
104 |
</style>
|
105 |
-
<h3><center><b>
|
106 |
<h4>PESTICIDES TO BE USED:</h4>
|
107 |
<ul>
|
108 |
-
<li>1.
|
109 |
-
<li>2.
|
110 |
-
<li>3.
|
111 |
-
<li>4.
|
112 |
-
<li>5.
|
113 |
-
<li>6. Garlic oil</li>
|
114 |
-
</ul>
|
115 |
-
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
116 |
-
<p>Be sure to follow local regulations and guidelines for application</p>
|
117 |
-
|
118 |
-
|
119 |
-
"""
|
120 |
-
elif predicted_label=='Mango Cutting Weevil':
|
121 |
-
predicted_label = """
|
122 |
-
<style>
|
123 |
-
li{
|
124 |
-
font-size: 15px;
|
125 |
-
margin-left: 90px;
|
126 |
-
margin-top: 15px;
|
127 |
-
margin-bottom: 15px;
|
128 |
-
}
|
129 |
-
h4{
|
130 |
-
font-size: 17px;
|
131 |
-
margin-top: 15px;
|
132 |
-
}
|
133 |
-
h4:hover{
|
134 |
-
cursor: pointer;
|
135 |
-
}
|
136 |
|
137 |
-
h3:hover{
|
138 |
-
cursor: pointer;
|
139 |
-
color: blue;
|
140 |
-
transform: scale(1.3);
|
141 |
-
}
|
142 |
-
.note{
|
143 |
-
text-align: center;
|
144 |
-
font-size: 16px;
|
145 |
-
}
|
146 |
-
p{
|
147 |
-
font-size: 13px;
|
148 |
-
text-align: center;
|
149 |
-
}
|
150 |
|
151 |
-
</style>
|
152 |
-
<h3><center><b>Mango Cutting Weevil</b></center></h3>
|
153 |
-
<h4>PESTICIDES TO BE USED:</h4>
|
154 |
-
<ul>
|
155 |
-
<li>1. Imidacloprid</li>
|
156 |
-
<li>2. Thiamethoxam</li>
|
157 |
-
<li>3. Chlorpyrifos</li>
|
158 |
-
<li>4. Lambda-cyhalothrin</li>
|
159 |
-
<li>5. Fipronil</li>
|
160 |
-
<li>6. Neem oil</li>
|
161 |
</ul>
|
162 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
163 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
164 |
|
165 |
|
166 |
"""
|
167 |
-
|
168 |
-
elif predicted_label=='Mango Die Back':
|
169 |
predicted_label = """
|
170 |
<style>
|
171 |
li{
|
@@ -197,22 +108,22 @@ def predict_disease(image_file, model, all_labels):
|
|
197 |
}
|
198 |
|
199 |
</style>
|
200 |
-
<h3><center><b>
|
201 |
<h4>PESTICIDES TO BE USED:</h4>
|
202 |
<ul>
|
203 |
-
<li>1.
|
204 |
-
<li>2. Mancozeb</li>
|
205 |
<li>3. Azoxystrobin</li>
|
206 |
-
<li>4.
|
207 |
-
|
208 |
-
|
209 |
</ul>
|
210 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
211 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
212 |
|
213 |
|
214 |
"""
|
215 |
-
elif predicted_label=='
|
216 |
predicted_label = """
|
217 |
<style>
|
218 |
li{
|
@@ -244,22 +155,22 @@ def predict_disease(image_file, model, all_labels):
|
|
244 |
}
|
245 |
|
246 |
</style>
|
247 |
-
<h3><center><b>
|
248 |
<h4>PESTICIDES TO BE USED:</h4>
|
249 |
<ul>
|
250 |
-
<li>1.
|
251 |
-
<li>2.
|
252 |
-
<li>3.
|
253 |
-
<li>4.
|
254 |
-
|
255 |
-
|
256 |
</ul>
|
257 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
258 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
259 |
|
260 |
|
261 |
"""
|
262 |
-
elif predicted_label=='
|
263 |
predicted_label = """
|
264 |
<style>
|
265 |
li{
|
@@ -291,72 +202,26 @@ def predict_disease(image_file, model, all_labels):
|
|
291 |
}
|
292 |
|
293 |
</style>
|
294 |
-
<h3><center><b>
|
295 |
<h4>PESTICIDES TO BE USED:</h4>
|
296 |
<ul>
|
297 |
-
<li>1.
|
298 |
-
<li>2.
|
299 |
-
<li>3.
|
300 |
-
<li>4.
|
301 |
-
<li>5. Propiconazole</li>
|
302 |
-
<li>6. Azoxystrobin</li>
|
303 |
-
</ul>
|
304 |
-
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
305 |
-
<p>Be sure to follow local regulations and guidelines for application</p>
|
306 |
-
|
307 |
-
|
308 |
-
"""
|
309 |
-
|
310 |
-
elif predicted_label=='Mango Sooty Mould':
|
311 |
-
predicted_label = """
|
312 |
-
<style>
|
313 |
-
li{
|
314 |
-
font-size: 15px;
|
315 |
-
margin-left: 90px;
|
316 |
-
margin-top: 15px;
|
317 |
-
margin-bottom: 15px;
|
318 |
-
}
|
319 |
-
h4{
|
320 |
-
font-size: 17px;
|
321 |
-
margin-top: 15px;
|
322 |
-
}
|
323 |
-
h4:hover{
|
324 |
-
cursor: pointer;
|
325 |
-
}
|
326 |
|
327 |
-
h3:hover{
|
328 |
-
cursor: pointer;
|
329 |
-
color: blue;
|
330 |
-
transform: scale(1.3);
|
331 |
-
}
|
332 |
-
.note{
|
333 |
-
text-align: center;
|
334 |
-
font-size: 16px;
|
335 |
-
}
|
336 |
-
p{
|
337 |
-
font-size: 13px;
|
338 |
-
text-align: center;
|
339 |
-
}
|
340 |
|
341 |
-
</style>
|
342 |
-
<h3><center><b>Mango Sooty Mould</b></center></h3>
|
343 |
-
<h4>PESTICIDES TO BE USED:</h4>
|
344 |
-
<ul>
|
345 |
-
<li>1. Imidacloprid (Neonicotinoid)</li>
|
346 |
-
<li>2. Thiamethoxam (Neonicotinoid)</li>
|
347 |
-
<li>3. Bifenthrin (Pyrethroid)</li>
|
348 |
-
<li>4. Lambda-cyhalothrin (Pyrethroid)</li>
|
349 |
-
<li>5. Insecticidal soap</li>
|
350 |
-
<li>6. Horticultural oil</li>
|
351 |
</ul>
|
352 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
353 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
354 |
|
355 |
|
356 |
"""
|
|
|
|
|
357 |
else:
|
358 |
-
predicted_label = """<h3 align="center">
|
359 |
-
|
360 |
|
361 |
return predicted_label
|
362 |
|
@@ -367,14 +232,10 @@ def predict_disease(image_file, model, all_labels):
|
|
367 |
|
368 |
# List of class labels
|
369 |
all_labels = [
|
370 |
-
'
|
371 |
-
'
|
372 |
-
'
|
373 |
-
'
|
374 |
-
'Mango Gall Midge',
|
375 |
-
'Mango Healthy',
|
376 |
-
'Mango Powdery Mildew',
|
377 |
-
'Mango Sooty Mould'
|
378 |
]
|
379 |
|
380 |
# Define the Gradio interface
|
@@ -386,7 +247,7 @@ gr_interface = gr.Interface(
|
|
386 |
fn=gradio_predict, # Function to call for predictions
|
387 |
inputs=gr.Image(type="filepath"), # Upload image as file path
|
388 |
outputs="html", # Output will be the class label as text
|
389 |
-
title="
|
390 |
description="Upload an image of a plant to predict the disease.",
|
391 |
)
|
392 |
|
|
|
4 |
import numpy as np
|
5 |
|
6 |
# Load the pre-trained model from the local path
|
7 |
+
model_path = 'chilli.h5'
|
8 |
model = load_model(model_path) # Load the model here
|
9 |
|
10 |
def predict_disease(image_file, model, all_labels):
|
11 |
+
|
12 |
try:
|
13 |
# Load and preprocess the image
|
14 |
img = load_img(image_file, target_size=(224, 224)) # Use load_img from tensorflow.keras.utils
|
|
|
24 |
predicted_label = all_labels[predicted_class]
|
25 |
|
26 |
# Print the predicted label to the console
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
if predicted_label=='Chilli Healthy':
|
29 |
+
predicted_label = predicted_label = """<h3 align="center">Chilli Healthy</h3><br><br>
|
30 |
+
<center>No need use Pesticides</center>"""
|
31 |
+
elif predicted_label=='Chilli Yellowish':
|
32 |
predicted_label = """
|
33 |
<style>
|
34 |
li{
|
|
|
60 |
}
|
61 |
|
62 |
</style>
|
63 |
+
<h3><center><b>Chilli Yellowish</b></center></h3>
|
64 |
<h4>PESTICIDES TO BE USED:</h4>
|
65 |
<ul>
|
66 |
+
<li>1. Chlorothalonil (Daconil)</li>
|
67 |
+
<li>2. Mancozeb (Dithane)</li>
|
68 |
+
<li>3. Copper oxychloride (Kocide)</li>
|
69 |
+
<li>4. Azoxystrobin (Heritage)</li>
|
70 |
+
<li>5. Pyraclostrobin (Cabrio)</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
</ul>
|
74 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
75 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
76 |
|
77 |
|
78 |
"""
|
79 |
+
elif predicted_label=='Chilli whitefly':
|
|
|
80 |
predicted_label = """
|
81 |
<style>
|
82 |
li{
|
|
|
108 |
}
|
109 |
|
110 |
</style>
|
111 |
+
<h3><center><b>Chilli whitefly</b></center></h3>
|
112 |
<h4>PESTICIDES TO BE USED:</h4>
|
113 |
<ul>
|
114 |
+
<li>1. Copper oxychloride (Kocide)</li>
|
115 |
+
<li>2. Mancozeb(Dithane)</li>
|
116 |
<li>3. Azoxystrobin</li>
|
117 |
+
<li>4. Chlorothalonil</li>
|
118 |
+
|
119 |
+
|
120 |
</ul>
|
121 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
122 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
123 |
|
124 |
|
125 |
"""
|
126 |
+
elif predicted_label=='Chilli leaf Spot':
|
127 |
predicted_label = """
|
128 |
<style>
|
129 |
li{
|
|
|
155 |
}
|
156 |
|
157 |
</style>
|
158 |
+
<h3><center><b>Chilli leaf Spot</b></center></h3>
|
159 |
<h4>PESTICIDES TO BE USED:</h4>
|
160 |
<ul>
|
161 |
+
<li>1. Copper oxychloride (Kocide)</li>
|
162 |
+
<li>2. Mancozeb(Dithane)</li>
|
163 |
+
<li>3. Azoxystrobin</li>
|
164 |
+
<li>4. Chlorothalonil</li>
|
165 |
+
|
166 |
+
|
167 |
</ul>
|
168 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
169 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
170 |
|
171 |
|
172 |
"""
|
173 |
+
elif predicted_label=='Chilli Leaf Curl':
|
174 |
predicted_label = """
|
175 |
<style>
|
176 |
li{
|
|
|
202 |
}
|
203 |
|
204 |
</style>
|
205 |
+
<h3><center><b>Chilli Leaf Curl</b></center></h3>
|
206 |
<h4>PESTICIDES TO BE USED:</h4>
|
207 |
<ul>
|
208 |
+
<li>1. Copper oxychloride (Kocide)</li>
|
209 |
+
<li>2. Mancozeb(Dithane)</li>
|
210 |
+
<li>3. Azoxystrobin</li>
|
211 |
+
<li>4. Chlorothalonil</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
</ul>
|
215 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
216 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
217 |
|
218 |
|
219 |
"""
|
220 |
+
|
221 |
+
|
222 |
else:
|
223 |
+
predicted_label = """<h3 align="center">Choose Correct image</h3><br><br>
|
224 |
+
"""
|
225 |
|
226 |
return predicted_label
|
227 |
|
|
|
232 |
|
233 |
# List of class labels
|
234 |
all_labels = [
|
235 |
+
'Chilli Yellowish',
|
236 |
+
'Chilli whitefly',
|
237 |
+
'Chilli leaf Spot','Chilli Leaf Curl',
|
238 |
+
'Chilli Healthy'
|
|
|
|
|
|
|
|
|
239 |
]
|
240 |
|
241 |
# Define the Gradio interface
|
|
|
247 |
fn=gradio_predict, # Function to call for predictions
|
248 |
inputs=gr.Image(type="filepath"), # Upload image as file path
|
249 |
outputs="html", # Output will be the class label as text
|
250 |
+
title="Chilli Disease Predictor",
|
251 |
description="Upload an image of a plant to predict the disease.",
|
252 |
)
|
253 |
|