Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
pip install tensorflow==2.11.0
|
2 |
import gradio as gr
|
3 |
|
4 |
# Import tensorflow here
|
@@ -9,20 +8,16 @@ from tensorflow.keras.models import load_model # Use tensorflow.keras.models
|
|
9 |
import numpy as np
|
10 |
|
11 |
# Load the pre-trained model from the local path
|
12 |
-
model_path = '
|
13 |
|
14 |
# Define custom objects to handle potential incompatibilities
|
15 |
custom_objects = {'DepthwiseConv2D': tf.keras.layers.DepthwiseConv2D}
|
16 |
|
17 |
# Load the model with custom_objects
|
18 |
-
model = load_model(model_path, custom_objects=custom_objects)
|
19 |
-
|
20 |
-
# ... (rest of your code)
|
21 |
-
|
22 |
-
# ... (rest of your code) # Load the model here
|
23 |
|
24 |
def predict_disease(image_file, model, all_labels):
|
25 |
-
|
26 |
try:
|
27 |
# Load and preprocess the image
|
28 |
img = load_img(image_file, target_size=(224, 224)) # Use load_img from tensorflow.keras.utils
|
@@ -38,8 +33,8 @@ def predict_disease(image_file, model, all_labels):
|
|
38 |
predicted_label = all_labels[predicted_class]
|
39 |
|
40 |
# Print the predicted label to the console
|
41 |
-
|
42 |
-
if predicted_label=='
|
43 |
predicted_label = """<style>
|
44 |
li{
|
45 |
font-size: 15px;
|
@@ -70,20 +65,21 @@ def predict_disease(image_file, model, all_labels):
|
|
70 |
}
|
71 |
|
72 |
</style>
|
73 |
-
<h3><center><b>
|
74 |
<h4>PESTICIDES TO BE USED:</h4>
|
75 |
<ul>
|
76 |
-
<li>1.
|
77 |
-
<li>2.
|
78 |
-
<li>3.
|
79 |
-
<li>4.
|
80 |
-
|
|
|
81 |
</ul><br>
|
82 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
83 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
84 |
|
85 |
"""
|
86 |
-
elif predicted_label=='
|
87 |
predicted_label = """
|
88 |
<style>
|
89 |
li{
|
@@ -115,22 +111,22 @@ def predict_disease(image_file, model, all_labels):
|
|
115 |
}
|
116 |
|
117 |
</style>
|
118 |
-
<h3><center><b>
|
119 |
<h4>PESTICIDES TO BE USED:</h4>
|
120 |
<ul>
|
121 |
-
<li>1.
|
122 |
-
<li>2.
|
123 |
-
<li>3.
|
124 |
-
<li>4.
|
125 |
-
<li>5.
|
126 |
-
|
127 |
</ul>
|
128 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
129 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
130 |
|
131 |
|
132 |
"""
|
133 |
-
elif predicted_label=='
|
134 |
predicted_label = """
|
135 |
<style>
|
136 |
li{
|
@@ -162,15 +158,15 @@ def predict_disease(image_file, model, all_labels):
|
|
162 |
}
|
163 |
|
164 |
</style>
|
165 |
-
<h3><center><b>
|
166 |
<h4>PESTICIDES TO BE USED:</h4>
|
167 |
<ul>
|
168 |
-
<li>1.
|
169 |
-
<li>2.
|
170 |
-
<li>3.
|
171 |
-
<li>4.
|
172 |
-
|
173 |
-
<li>
|
174 |
</ul>
|
175 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
176 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
@@ -178,7 +174,7 @@ def predict_disease(image_file, model, all_labels):
|
|
178 |
|
179 |
"""
|
180 |
|
181 |
-
elif predicted_label=='
|
182 |
predicted_label = """
|
183 |
<style>
|
184 |
li{
|
@@ -210,21 +206,22 @@ def predict_disease(image_file, model, all_labels):
|
|
210 |
}
|
211 |
|
212 |
</style>
|
213 |
-
<h3><center><b>
|
214 |
<h4>PESTICIDES TO BE USED:</h4>
|
215 |
<ul>
|
216 |
-
<li>1.
|
217 |
-
<li>2.
|
218 |
-
<li>3.
|
219 |
-
<li>4.
|
220 |
-
<li>5.
|
|
|
221 |
</ul>
|
222 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
223 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
224 |
|
225 |
|
226 |
"""
|
227 |
-
elif predicted_label=='
|
228 |
predicted_label = """
|
229 |
<style>
|
230 |
li{
|
@@ -256,22 +253,22 @@ def predict_disease(image_file, model, all_labels):
|
|
256 |
}
|
257 |
|
258 |
</style>
|
259 |
-
<h3><center><b>
|
260 |
<h4>PESTICIDES TO BE USED:</h4>
|
261 |
<ul>
|
262 |
<li>1. Imidacloprid</li>
|
263 |
<li>2. Thiamethoxam</li>
|
264 |
-
<li>3.
|
265 |
-
<li>4.
|
266 |
-
<li>5.
|
267 |
-
|
268 |
</ul>
|
269 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
270 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
271 |
|
272 |
|
273 |
"""
|
274 |
-
elif predicted_label=='
|
275 |
predicted_label = """
|
276 |
<style>
|
277 |
li{
|
@@ -303,14 +300,15 @@ def predict_disease(image_file, model, all_labels):
|
|
303 |
}
|
304 |
|
305 |
</style>
|
306 |
-
<h3><center><b>
|
307 |
<h4>PESTICIDES TO BE USED:</h4>
|
308 |
<ul>
|
309 |
-
<li>1.
|
310 |
-
<li>2.
|
311 |
-
<li>3.
|
312 |
-
<li>4.
|
313 |
<li>5. Propiconazole</li>
|
|
|
314 |
</ul>
|
315 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
316 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
@@ -318,7 +316,7 @@ def predict_disease(image_file, model, all_labels):
|
|
318 |
|
319 |
"""
|
320 |
|
321 |
-
elif predicted_label=='
|
322 |
predicted_label = """
|
323 |
<style>
|
324 |
li{
|
@@ -350,106 +348,13 @@ def predict_disease(image_file, model, all_labels):
|
|
350 |
}
|
351 |
|
352 |
</style>
|
353 |
-
<h3><center><b>
|
354 |
<h4>PESTICIDES TO BE USED:</h4>
|
355 |
<ul>
|
356 |
-
<li>1.
|
357 |
-
<li>2.
|
358 |
-
<li>3.
|
359 |
-
<li>4.
|
360 |
-
<li>5. Azoxystrobin</li>
|
361 |
-
|
362 |
-
</ul>
|
363 |
-
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
364 |
-
<p>Be sure to follow local regulations and guidelines for application</p>
|
365 |
-
|
366 |
-
|
367 |
-
"""
|
368 |
-
elif predicted_label=='Tomato Early blight':
|
369 |
-
predicted_label = """
|
370 |
-
<style>
|
371 |
-
li{
|
372 |
-
font-size: 15px;
|
373 |
-
margin-left: 90px;
|
374 |
-
margin-top: 15px;
|
375 |
-
margin-bottom: 15px;
|
376 |
-
}
|
377 |
-
h4{
|
378 |
-
font-size: 17px;
|
379 |
-
margin-top: 15px;
|
380 |
-
}
|
381 |
-
h4:hover{
|
382 |
-
cursor: pointer;
|
383 |
-
}
|
384 |
-
|
385 |
-
h3:hover{
|
386 |
-
cursor: pointer;
|
387 |
-
color: blue;
|
388 |
-
transform: scale(1.3);
|
389 |
-
}
|
390 |
-
.note{
|
391 |
-
text-align: center;
|
392 |
-
font-size: 16px;
|
393 |
-
}
|
394 |
-
p{
|
395 |
-
font-size: 13px;
|
396 |
-
text-align: center;
|
397 |
-
}
|
398 |
-
|
399 |
-
</style>
|
400 |
-
<h3><center><b>Tomato blight</b></center></h3>
|
401 |
-
<h4>PESTICIDES TO BE USED:</h4>
|
402 |
-
<ul>
|
403 |
-
<li>1. Azoxystrobin</li>
|
404 |
-
<li>2. Boscalid</li>
|
405 |
-
<li>3. Mancozeb</li>
|
406 |
-
<li>4. Chlorothalonil</li>
|
407 |
-
<li>5. Propiconazole</li>
|
408 |
-
</ul>
|
409 |
-
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
410 |
-
<p>Be sure to follow local regulations and guidelines for application</p>
|
411 |
-
|
412 |
-
|
413 |
-
"""
|
414 |
-
elif predicted_label=='Tomato Bacterial spot':
|
415 |
-
predicted_label = """
|
416 |
-
<style>
|
417 |
-
li{
|
418 |
-
font-size: 15px;
|
419 |
-
margin-left: 90px;
|
420 |
-
margin-top: 15px;
|
421 |
-
margin-bottom: 15px;
|
422 |
-
}
|
423 |
-
h4{
|
424 |
-
font-size: 17px;
|
425 |
-
margin-top: 15px;
|
426 |
-
}
|
427 |
-
h4:hover{
|
428 |
-
cursor: pointer;
|
429 |
-
}
|
430 |
-
|
431 |
-
h3:hover{
|
432 |
-
cursor: pointer;
|
433 |
-
color: blue;
|
434 |
-
transform: scale(1.3);
|
435 |
-
}
|
436 |
-
.note{
|
437 |
-
text-align: center;
|
438 |
-
font-size: 16px;
|
439 |
-
}
|
440 |
-
p{
|
441 |
-
font-size: 13px;
|
442 |
-
text-align: center;
|
443 |
-
}
|
444 |
-
|
445 |
-
</style>
|
446 |
-
<h3><center><b>Tomato Bacterial spot</b></center></h3>
|
447 |
-
<h4>PESTICIDES TO BE USED:</h4>
|
448 |
-
<ul>
|
449 |
-
<li>1. Copper oxychloride</li>
|
450 |
-
<li>2. Streptomycin</li>
|
451 |
-
<li>3. tetracycline</li>
|
452 |
-
<li>4. Oxytetracline(Terramycin)</li>
|
453 |
<li>5. Insecticidal soap</li>
|
454 |
<li>6. Horticultural oil</li>
|
455 |
</ul>
|
@@ -458,13 +363,9 @@ def predict_disease(image_file, model, all_labels):
|
|
458 |
|
459 |
|
460 |
"""
|
461 |
-
|
462 |
-
elif predicted_label=='Tomato Healthy':
|
463 |
-
|
464 |
-
predicted_label = """<h3 align="center">Tomato Healthy</h3><br><br>
|
465 |
-
<center>No need use Pesticides</center>"""
|
466 |
else:
|
467 |
-
|
|
|
468 |
|
469 |
return predicted_label
|
470 |
|
@@ -475,16 +376,14 @@ def predict_disease(image_file, model, all_labels):
|
|
475 |
|
476 |
# List of class labels
|
477 |
all_labels = [
|
478 |
-
'
|
479 |
-
'
|
480 |
-
'
|
481 |
-
'
|
482 |
-
'
|
483 |
-
'
|
484 |
-
'
|
485 |
-
'
|
486 |
-
'Tomato Early blight',
|
487 |
-
'Tomato Bacterial spot'
|
488 |
]
|
489 |
|
490 |
# Define the Gradio interface
|
@@ -496,10 +395,9 @@ gr_interface = gr.Interface(
|
|
496 |
fn=gradio_predict, # Function to call for predictions
|
497 |
inputs=gr.Image(type="filepath"), # Upload image as file path
|
498 |
outputs="html", # Output will be the class label as text
|
499 |
-
title="
|
500 |
description="Upload an image of a plant to predict the disease.",
|
501 |
)
|
502 |
|
503 |
# Launch the Gradio app
|
504 |
-
|
505 |
gr_interface.launch(share=True)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# Import tensorflow here
|
|
|
8 |
import numpy as np
|
9 |
|
10 |
# Load the pre-trained model from the local path
|
11 |
+
model_path = 'Mango.h5'
|
12 |
|
13 |
# Define custom objects to handle potential incompatibilities
|
14 |
custom_objects = {'DepthwiseConv2D': tf.keras.layers.DepthwiseConv2D}
|
15 |
|
16 |
# Load the model with custom_objects
|
17 |
+
model = load_model(model_path, custom_objects=custom_objects) # Load the model here
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def predict_disease(image_file, model, all_labels):
|
20 |
+
|
21 |
try:
|
22 |
# Load and preprocess the image
|
23 |
img = load_img(image_file, target_size=(224, 224)) # Use load_img from tensorflow.keras.utils
|
|
|
33 |
predicted_label = all_labels[predicted_class]
|
34 |
|
35 |
# Print the predicted label to the console
|
36 |
+
|
37 |
+
if predicted_label=='Mango Anthracrose':
|
38 |
predicted_label = """<style>
|
39 |
li{
|
40 |
font-size: 15px;
|
|
|
65 |
}
|
66 |
|
67 |
</style>
|
68 |
+
<h3><center><b>Mango Anthracrose</b></center></h3>
|
69 |
<h4>PESTICIDES TO BE USED:</h4>
|
70 |
<ul>
|
71 |
+
<li>1. Mancozeb</li>
|
72 |
+
<li>2. Azoxystrobin</li>
|
73 |
+
<li>3. carbendazim</li>
|
74 |
+
<li>4. Propiconazole</li>
|
75 |
+
<li>5. Thiophanate-methyl</li>
|
76 |
+
<li>6. Copper Sulfate</li>
|
77 |
</ul><br>
|
78 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
79 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
80 |
|
81 |
"""
|
82 |
+
elif predicted_label=='Mango Bacterial Canker':
|
83 |
predicted_label = """
|
84 |
<style>
|
85 |
li{
|
|
|
111 |
}
|
112 |
|
113 |
</style>
|
114 |
+
<h3><center><b>Mango Bacterial Canker</b></center></h3>
|
115 |
<h4>PESTICIDES TO BE USED:</h4>
|
116 |
<ul>
|
117 |
+
<li>1. Copper Hydroxide</li>
|
118 |
+
<li>2. Copper Oxychloride</li>
|
119 |
+
<li>3. Streptomycin</li>
|
120 |
+
<li>4. oxytetracycline</li>
|
121 |
+
<li>5. Neem oil</li>
|
122 |
+
<li>6. Garlic oil</li>
|
123 |
</ul>
|
124 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
125 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
126 |
|
127 |
|
128 |
"""
|
129 |
+
elif predicted_label=='Mango Cutting Weevil':
|
130 |
predicted_label = """
|
131 |
<style>
|
132 |
li{
|
|
|
158 |
}
|
159 |
|
160 |
</style>
|
161 |
+
<h3><center><b>Mango Cutting Weevil</b></center></h3>
|
162 |
<h4>PESTICIDES TO BE USED:</h4>
|
163 |
<ul>
|
164 |
+
<li>1. Imidacloprid</li>
|
165 |
+
<li>2. Thiamethoxam</li>
|
166 |
+
<li>3. Chlorpyrifos</li>
|
167 |
+
<li>4. Lambda-cyhalothrin</li>
|
168 |
+
<li>5. Fipronil</li>
|
169 |
+
<li>6. Neem oil</li>
|
170 |
</ul>
|
171 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
172 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
|
|
174 |
|
175 |
"""
|
176 |
|
177 |
+
elif predicted_label=='Mango Die Back':
|
178 |
predicted_label = """
|
179 |
<style>
|
180 |
li{
|
|
|
206 |
}
|
207 |
|
208 |
</style>
|
209 |
+
<h3><center><b>Mango Die Back</b></center></h3>
|
210 |
<h4>PESTICIDES TO BE USED:</h4>
|
211 |
<ul>
|
212 |
+
<li>1. Carbendazim</li>
|
213 |
+
<li>2. Mancozeb</li>
|
214 |
+
<li>3. Azoxystrobin</li>
|
215 |
+
<li>4. Triazole</li>
|
216 |
+
<li>5. Potassium bicarbonate</li>
|
217 |
+
<li>6. Sodium bicarbonate</li>
|
218 |
</ul>
|
219 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
220 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
221 |
|
222 |
|
223 |
"""
|
224 |
+
elif predicted_label=='Mango Gall Midge':
|
225 |
predicted_label = """
|
226 |
<style>
|
227 |
li{
|
|
|
253 |
}
|
254 |
|
255 |
</style>
|
256 |
+
<h3><center><b>Mango Gall Midge</b></center></h3>
|
257 |
<h4>PESTICIDES TO BE USED:</h4>
|
258 |
<ul>
|
259 |
<li>1. Imidacloprid</li>
|
260 |
<li>2. Thiamethoxam</li>
|
261 |
+
<li>3. Chlorpyrifos</li>
|
262 |
+
<li>4. Lambda-cyhalothrin</li>
|
263 |
+
<li>5. Spinosad</li>
|
264 |
+
<li>6. Pyrethrin</li>
|
265 |
</ul>
|
266 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
267 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
268 |
|
269 |
|
270 |
"""
|
271 |
+
elif predicted_label=='Mango Powdery Mildew':
|
272 |
predicted_label = """
|
273 |
<style>
|
274 |
li{
|
|
|
300 |
}
|
301 |
|
302 |
</style>
|
303 |
+
<h3><center><b>Mango Powdery Mildew</b></center></h3>
|
304 |
<h4>PESTICIDES TO BE USED:</h4>
|
305 |
<ul>
|
306 |
+
<li>1. Sulfur</li>
|
307 |
+
<li>2. Bicarbonates</li>
|
308 |
+
<li>3. Myclobutanil</li>
|
309 |
+
<li>4. Triadimefon</li>
|
310 |
<li>5. Propiconazole</li>
|
311 |
+
<li>6. Azoxystrobin</li>
|
312 |
</ul>
|
313 |
<p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
|
314 |
<p>Be sure to follow local regulations and guidelines for application</p>
|
|
|
316 |
|
317 |
"""
|
318 |
|
319 |
+
elif predicted_label=='Mango Sooty Mould':
|
320 |
predicted_label = """
|
321 |
<style>
|
322 |
li{
|
|
|
348 |
}
|
349 |
|
350 |
</style>
|
351 |
+
<h3><center><b>Mango Sooty Mould</b></center></h3>
|
352 |
<h4>PESTICIDES TO BE USED:</h4>
|
353 |
<ul>
|
354 |
+
<li>1. Imidacloprid (Neonicotinoid)</li>
|
355 |
+
<li>2. Thiamethoxam (Neonicotinoid)</li>
|
356 |
+
<li>3. Bifenthrin (Pyrethroid)</li>
|
357 |
+
<li>4. Lambda-cyhalothrin (Pyrethroid)</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
<li>5. Insecticidal soap</li>
|
359 |
<li>6. Horticultural oil</li>
|
360 |
</ul>
|
|
|
363 |
|
364 |
|
365 |
"""
|
|
|
|
|
|
|
|
|
|
|
366 |
else:
|
367 |
+
predicted_label = """<h3 align="center">Mango Healthy</h3><br><br>
|
368 |
+
<center>No need use Pesticides</center>"""
|
369 |
|
370 |
return predicted_label
|
371 |
|
|
|
376 |
|
377 |
# List of class labels
|
378 |
all_labels = [
|
379 |
+
'Mango Anthracrose',
|
380 |
+
'Mango Bacterial Canker',
|
381 |
+
'Mango Cutting Weevil',
|
382 |
+
'Mango Die Back',
|
383 |
+
'Mango Gall Midge',
|
384 |
+
'Mango Healthy',
|
385 |
+
'Mango Powdery Mildew',
|
386 |
+
'Mango Sooty Mould'
|
|
|
|
|
387 |
]
|
388 |
|
389 |
# Define the Gradio interface
|
|
|
395 |
fn=gradio_predict, # Function to call for predictions
|
396 |
inputs=gr.Image(type="filepath"), # Upload image as file path
|
397 |
outputs="html", # Output will be the class label as text
|
398 |
+
title="Plant Disease Predictor",
|
399 |
description="Upload an image of a plant to predict the disease.",
|
400 |
)
|
401 |
|
402 |
# Launch the Gradio app
|
|
|
403 |
gr_interface.launch(share=True)
|