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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.utils import img_to_array,load_img
|
3 |
+
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 = '/content/Mango.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
|
15 |
+
img_array = img_to_array(img)
|
16 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
17 |
+
img_array = img_array / 255.0 # Normalize the image
|
18 |
+
|
19 |
+
# Predict the class
|
20 |
+
predictions = model.predict(img_array) # Use the loaded model here
|
21 |
+
predicted_class = np.argmax(predictions[0])
|
22 |
+
|
23 |
+
# Get the predicted class label
|
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 |
+
elif predicted_label=='Mango Bacterial Canker':
|
74 |
+
predicted_label = """
|
75 |
+
<style>
|
76 |
+
li{
|
77 |
+
font-size: 15px;
|
78 |
+
margin-left: 90px;
|
79 |
+
margin-top: 15px;
|
80 |
+
margin-bottom: 15px;
|
81 |
+
}
|
82 |
+
h4{
|
83 |
+
font-size: 17px;
|
84 |
+
margin-top: 15px;
|
85 |
+
}
|
86 |
+
h4:hover{
|
87 |
+
cursor: pointer;
|
88 |
+
}
|
89 |
+
|
90 |
+
h3:hover{
|
91 |
+
cursor: pointer;
|
92 |
+
color: blue;
|
93 |
+
transform: scale(1.3);
|
94 |
+
}
|
95 |
+
.note{
|
96 |
+
text-align: center;
|
97 |
+
font-size: 16px;
|
98 |
+
}
|
99 |
+
p{
|
100 |
+
font-size: 13px;
|
101 |
+
text-align: center;
|
102 |
+
}
|
103 |
+
|
104 |
+
</style>
|
105 |
+
<h3><center><b>Mango Bacterial Canker</b></center></h3>
|
106 |
+
<h4>PESTICIDES TO BE USED:</h4>
|
107 |
+
<ul>
|
108 |
+
<li>1. Copper Hydroxide</li>
|
109 |
+
<li>2. Copper Oxychloride</li>
|
110 |
+
<li>3. Streptomycin</li>
|
111 |
+
<li>4. oxytetracycline</li>
|
112 |
+
<li>5. Neem oil</li>
|
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{
|
172 |
+
font-size: 15px;
|
173 |
+
margin-left: 90px;
|
174 |
+
margin-top: 15px;
|
175 |
+
margin-bottom: 15px;
|
176 |
+
}
|
177 |
+
h4{
|
178 |
+
font-size: 17px;
|
179 |
+
margin-top: 15px;
|
180 |
+
}
|
181 |
+
h4:hover{
|
182 |
+
cursor: pointer;
|
183 |
+
}
|
184 |
+
|
185 |
+
h3:hover{
|
186 |
+
cursor: pointer;
|
187 |
+
color: blue;
|
188 |
+
transform: scale(1.3);
|
189 |
+
}
|
190 |
+
.note{
|
191 |
+
text-align: center;
|
192 |
+
font-size: 16px;
|
193 |
+
}
|
194 |
+
p{
|
195 |
+
font-size: 13px;
|
196 |
+
text-align: center;
|
197 |
+
}
|
198 |
+
|
199 |
+
</style>
|
200 |
+
<h3><center><b>Mango Die Back</b></center></h3>
|
201 |
+
<h4>PESTICIDES TO BE USED:</h4>
|
202 |
+
<ul>
|
203 |
+
<li>1. Carbendazim</li>
|
204 |
+
<li>2. Mancozeb</li>
|
205 |
+
<li>3. Azoxystrobin</li>
|
206 |
+
<li>4. Triazole</li>
|
207 |
+
<li>5. Potassium bicarbonate</li>
|
208 |
+
<li>6. Sodium bicarbonate</li>
|
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=='Mango Gall Midge':
|
216 |
+
predicted_label = """
|
217 |
+
<style>
|
218 |
+
li{
|
219 |
+
font-size: 15px;
|
220 |
+
margin-left: 90px;
|
221 |
+
margin-top: 15px;
|
222 |
+
margin-bottom: 15px;
|
223 |
+
}
|
224 |
+
h4{
|
225 |
+
font-size: 17px;
|
226 |
+
margin-top: 15px;
|
227 |
+
}
|
228 |
+
h4:hover{
|
229 |
+
cursor: pointer;
|
230 |
+
}
|
231 |
+
|
232 |
+
h3:hover{
|
233 |
+
cursor: pointer;
|
234 |
+
color: blue;
|
235 |
+
transform: scale(1.3);
|
236 |
+
}
|
237 |
+
.note{
|
238 |
+
text-align: center;
|
239 |
+
font-size: 16px;
|
240 |
+
}
|
241 |
+
p{
|
242 |
+
font-size: 13px;
|
243 |
+
text-align: center;
|
244 |
+
}
|
245 |
+
|
246 |
+
</style>
|
247 |
+
<h3><center><b>Mango Gall Midge</b></center></h3>
|
248 |
+
<h4>PESTICIDES TO BE USED:</h4>
|
249 |
+
<ul>
|
250 |
+
<li>1. Imidacloprid</li>
|
251 |
+
<li>2. Thiamethoxam</li>
|
252 |
+
<li>3. Chlorpyrifos</li>
|
253 |
+
<li>4. Lambda-cyhalothrin</li>
|
254 |
+
<li>5. Spinosad</li>
|
255 |
+
<li>6. Pyrethrin</li>
|
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=='Mango Powdery Mildew':
|
263 |
+
predicted_label = """
|
264 |
+
<style>
|
265 |
+
li{
|
266 |
+
font-size: 15px;
|
267 |
+
margin-left: 90px;
|
268 |
+
margin-top: 15px;
|
269 |
+
margin-bottom: 15px;
|
270 |
+
}
|
271 |
+
h4{
|
272 |
+
font-size: 17px;
|
273 |
+
margin-top: 15px;
|
274 |
+
}
|
275 |
+
h4:hover{
|
276 |
+
cursor: pointer;
|
277 |
+
}
|
278 |
+
|
279 |
+
h3:hover{
|
280 |
+
cursor: pointer;
|
281 |
+
color: blue;
|
282 |
+
transform: scale(1.3);
|
283 |
+
}
|
284 |
+
.note{
|
285 |
+
text-align: center;
|
286 |
+
font-size: 16px;
|
287 |
+
}
|
288 |
+
p{
|
289 |
+
font-size: 13px;
|
290 |
+
text-align: center;
|
291 |
+
}
|
292 |
+
|
293 |
+
</style>
|
294 |
+
<h3><center><b>Mango Powdery Mildew</b></center></h3>
|
295 |
+
<h4>PESTICIDES TO BE USED:</h4>
|
296 |
+
<ul>
|
297 |
+
<li>1. Sulfur</li>
|
298 |
+
<li>2. Bicarbonates</li>
|
299 |
+
<li>3. Myclobutanil</li>
|
300 |
+
<li>4. Triadimefon</li>
|
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">Mango Healthy</h3><br><br>
|
359 |
+
<center>No need use Pesticides</center>"""
|
360 |
+
|
361 |
+
return predicted_label
|
362 |
+
|
363 |
+
|
364 |
+
except Exception as e:
|
365 |
+
print(f"Error: {e}")
|
366 |
+
return None
|
367 |
+
|
368 |
+
# List of class labels
|
369 |
+
all_labels = [
|
370 |
+
'Mango Anthracrose',
|
371 |
+
'Mango Bacterial Canker',
|
372 |
+
'Mango Cutting Weevil',
|
373 |
+
'Mango Die Back',
|
374 |
+
'Mango Gall Midge',
|
375 |
+
'Mango Healthy',
|
376 |
+
'Mango Powdery Mildew',
|
377 |
+
'Mango Sooty Mould'
|
378 |
+
]
|
379 |
+
|
380 |
+
# Define the Gradio interface
|
381 |
+
def gradio_predict(image_file):
|
382 |
+
return predict_disease(image_file, model, all_labels) # Pass the model to the function
|
383 |
+
|
384 |
+
# Create a Gradio interface
|
385 |
+
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="Plant Disease Predictor",
|
390 |
+
description="Upload an image of a plant to predict the disease.",
|
391 |
+
)
|
392 |
+
|
393 |
+
# Launch the Gradio app
|
394 |
+
gr_interface.launch(share=True)
|