project21 commited on
Commit
b91b489
·
verified ·
1 Parent(s): 3d9179a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +161 -396
app.py CHANGED
@@ -1,463 +1,205 @@
 
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 = 'tomato.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=='Tomato Yellow Leaf Curl Virus':
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>Tomato Yellow Leaf Curl Virus</b></center></h3>
60
- <h4>PESTICIDES TO BE USED:</h4>
61
- <ul>
62
  <li>1. imidacloprid</li>
63
  <li>2. thiamethoxam</li>
64
  <li>3. Spinosad</li>
65
  <li>4. Acetamiprid</li>
66
-
67
  </ul><br>
68
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
69
- <p>Be sure to follow local regulations and guidelines for application</p>
70
-
71
  """
72
- elif predicted_label=='Tomato Target Spot':
73
- predicted_label = """
74
- <style>
75
- li{
76
- font-size: 15px;
77
- margin-left: 90px;
78
- margin-top: 15px;
79
- margin-bottom: 15px;
80
- }
81
- h4{
82
- font-size: 17px;
83
- margin-top: 15px;
84
- }
85
- h4:hover{
86
- cursor: pointer;
87
- }
88
-
89
- h3:hover{
90
- cursor: pointer;
91
- color: blue;
92
- transform: scale(1.3);
93
- }
94
- .note{
95
- text-align: center;
96
- font-size: 16px;
97
- }
98
- p{
99
- font-size: 13px;
100
- text-align: center;
101
- }
102
-
103
- </style>
104
- <h3><center><b>Tomato Target Spot</b></center></h3>
105
- <h4>PESTICIDES TO BE USED:</h4>
106
- <ul>
107
  <li>1. Azoxystrobin</li>
108
  <li>2. Boscalid</li>
109
  <li>3. Mancozeb</li>
110
  <li>4. Chlorothalonil</li>
111
  <li>5. Propiconazole</li>
112
-
113
- </ul>
114
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
115
- <p>Be sure to follow local regulations and guidelines for application</p>
116
-
117
-
118
  """
119
- elif predicted_label=='Tomato Spider mites':
120
- predicted_label = """
121
- <style>
122
- li{
123
- font-size: 15px;
124
- margin-left: 90px;
125
- margin-top: 15px;
126
- margin-bottom: 15px;
127
- }
128
- h4{
129
- font-size: 17px;
130
- margin-top: 15px;
131
- }
132
- h4:hover{
133
- cursor: pointer;
134
- }
135
-
136
- h3:hover{
137
- cursor: pointer;
138
- color: blue;
139
- transform: scale(1.3);
140
- }
141
- .note{
142
- text-align: center;
143
- font-size: 16px;
144
- }
145
- p{
146
- font-size: 13px;
147
- text-align: center;
148
- }
149
-
150
- </style>
151
- <h3><center><b>Tomato Spider mites</b></center></h3>
152
- <h4>PESTICIDES TO BE USED:</h4>
153
- <ul>
154
  <li>1. Abamectin</li>
155
  <li>2. Spiromesifen</li>
156
  <li>3. Miticides</li>
157
- <li>4. insecticidal soap</li>
158
-
159
  <li>5. Neem oil</li>
160
- </ul>
161
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
162
- <p>Be sure to follow local regulations and guidelines for application</p>
163
-
164
-
165
  """
166
-
167
- elif predicted_label=='Tomato Septoria leaf spot':
168
- predicted_label = """
169
- <style>
170
- li{
171
- font-size: 15px;
172
- margin-left: 90px;
173
- margin-top: 15px;
174
- margin-bottom: 15px;
175
- }
176
- h4{
177
- font-size: 17px;
178
- margin-top: 15px;
179
- }
180
- h4:hover{
181
- cursor: pointer;
182
- }
183
-
184
- h3:hover{
185
- cursor: pointer;
186
- color: blue;
187
- transform: scale(1.3);
188
- }
189
- .note{
190
- text-align: center;
191
- font-size: 16px;
192
- }
193
- p{
194
- font-size: 13px;
195
- text-align: center;
196
- }
197
-
198
- </style>
199
- <h3><center><b>Tomato Septoria leaf spot</b></center></h3>
200
- <h4>PESTICIDES TO BE USED:</h4>
201
- <ul>
202
  <li>1. Azoxystrobin</li>
203
  <li>2. Boscalid</li>
204
  <li>3. Mancozeb</li>
205
  <li>4. Chlorothalonil</li>
206
  <li>5. Propiconazole</li>
207
- </ul>
208
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
209
- <p>Be sure to follow local regulations and guidelines for application</p>
210
-
211
-
212
  """
213
- elif predicted_label=='Tomato Mosaic virus':
214
- predicted_label = """
215
- <style>
216
- li{
217
- font-size: 15px;
218
- margin-left: 90px;
219
- margin-top: 15px;
220
- margin-bottom: 15px;
221
- }
222
- h4{
223
- font-size: 17px;
224
- margin-top: 15px;
225
- }
226
- h4:hover{
227
- cursor: pointer;
228
- }
229
-
230
- h3:hover{
231
- cursor: pointer;
232
- color: blue;
233
- transform: scale(1.3);
234
- }
235
- .note{
236
- text-align: center;
237
- font-size: 16px;
238
- }
239
- p{
240
- font-size: 13px;
241
- text-align: center;
242
- }
243
-
244
- </style>
245
- <h3><center><b>Tomato Mosaic virus</b></center></h3>
246
- <h4>PESTICIDES TO BE USED:</h4>
247
- <ul>
248
  <li>1. Imidacloprid</li>
249
  <li>2. Thiamethoxam</li>
250
  <li>3. Acetamiprid</li>
251
  <li>4. Dinotefuran</li>
252
  <li>5. Pyrethrin</li>
253
-
254
- </ul>
255
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
256
- <p>Be sure to follow local regulations and guidelines for application</p>
257
-
258
-
259
- """
260
- elif predicted_label=='Tomato Leaf Mold':
261
- predicted_label = """
262
- <style>
263
- li{
264
- font-size: 15px;
265
- margin-left: 90px;
266
- margin-top: 15px;
267
- margin-bottom: 15px;
268
- }
269
- h4{
270
- font-size: 17px;
271
- margin-top: 15px;
272
- }
273
- h4:hover{
274
- cursor: pointer;
275
- }
276
-
277
- h3:hover{
278
- cursor: pointer;
279
- color: blue;
280
- transform: scale(1.3);
281
- }
282
- .note{
283
- text-align: center;
284
- font-size: 16px;
285
- }
286
- p{
287
- font-size: 13px;
288
- text-align: center;
289
- }
290
-
291
- </style>
292
- <h3><center><b>Tomato Leaf Mold</b></center></h3>
293
- <h4>PESTICIDES TO BE USED:</h4>
294
- <ul>
295
  <li>1. Azoxystrobin</li>
296
  <li>2. Boscalid</li>
297
  <li>3. Mancozeb</li>
298
  <li>4. Chlorothalonil</li>
299
  <li>5. Propiconazole</li>
300
- </ul>
301
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
302
- <p>Be sure to follow local regulations and guidelines for application</p>
303
-
304
-
305
- """
306
-
307
- elif predicted_label=='Tomato Late blight':
308
- predicted_label = """
309
- <style>
310
- li{
311
- font-size: 15px;
312
- margin-left: 90px;
313
- margin-top: 15px;
314
- margin-bottom: 15px;
315
- }
316
- h4{
317
- font-size: 17px;
318
- margin-top: 15px;
319
- }
320
- h4:hover{
321
- cursor: pointer;
322
- }
323
-
324
- h3:hover{
325
- cursor: pointer;
326
- color: blue;
327
- transform: scale(1.3);
328
- }
329
- .note{
330
- text-align: center;
331
- font-size: 16px;
332
- }
333
- p{
334
- font-size: 13px;
335
- text-align: center;
336
- }
337
-
338
- </style>
339
- <h3><center><b>Tomato blight</b></center></h3>
340
- <h4>PESTICIDES TO BE USED:</h4>
341
- <ul>
342
  <li>1. metalaxl</li>
343
  <li>2. Chlorothalonil</li>
344
  <li>3. Mancozeb</li>
345
  <li>4. Copper oxychloride</li>
346
  <li>5. Azoxystrobin</li>
347
-
348
- </ul>
349
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
350
- <p>Be sure to follow local regulations and guidelines for application</p>
351
-
352
-
353
- """
354
- elif predicted_label=='Tomato Early blight':
355
- predicted_label = """
356
- <style>
357
- li{
358
- font-size: 15px;
359
- margin-left: 90px;
360
- margin-top: 15px;
361
- margin-bottom: 15px;
362
- }
363
- h4{
364
- font-size: 17px;
365
- margin-top: 15px;
366
- }
367
- h4:hover{
368
- cursor: pointer;
369
- }
370
-
371
- h3:hover{
372
- cursor: pointer;
373
- color: blue;
374
- transform: scale(1.3);
375
- }
376
- .note{
377
- text-align: center;
378
- font-size: 16px;
379
- }
380
- p{
381
- font-size: 13px;
382
- text-align: center;
383
- }
384
-
385
- </style>
386
- <h3><center><b>Tomato blight</b></center></h3>
387
- <h4>PESTICIDES TO BE USED:</h4>
388
- <ul>
389
  <li>1. Azoxystrobin</li>
390
  <li>2. Boscalid</li>
391
  <li>3. Mancozeb</li>
392
  <li>4. Chlorothalonil</li>
393
  <li>5. Propiconazole</li>
394
- </ul>
395
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
396
- <p>Be sure to follow local regulations and guidelines for application</p>
397
-
398
-
399
  """
400
- elif predicted_label=='Tomato Bacterial spot':
401
- predicted_label = """
402
- <style>
403
- li{
404
- font-size: 15px;
405
- margin-left: 90px;
406
- margin-top: 15px;
407
- margin-bottom: 15px;
408
- }
409
- h4{
410
- font-size: 17px;
411
- margin-top: 15px;
412
- }
413
- h4:hover{
414
- cursor: pointer;
415
- }
416
-
417
- h3:hover{
418
- cursor: pointer;
419
- color: blue;
420
- transform: scale(1.3);
421
- }
422
- .note{
423
- text-align: center;
424
- font-size: 16px;
425
- }
426
- p{
427
- font-size: 13px;
428
- text-align: center;
429
- }
430
-
431
- </style>
432
- <h3><center><b>Tomato Bacterial spot</b></center></h3>
433
- <h4>PESTICIDES TO BE USED:</h4>
434
- <ul>
435
  <li>1. Copper oxychloride</li>
436
  <li>2. Streptomycin</li>
437
  <li>3. tetracycline</li>
438
  <li>4. Oxytetracline(Terramycin)</li>
439
  <li>5. Insecticidal soap</li>
440
  <li>6. Horticultural oil</li>
441
- </ul>
442
- <p class="note"><b>* * * IMPORTANT NOTE * * *</b></p>
443
- <p>Be sure to follow local regulations and guidelines for application</p>
444
-
445
-
446
- """
447
-
448
- elif predicted_label=='Tomato Healthy':
449
-
450
- predicted_label = """<h3 align="center">Tomato Healthy</h3><br><br>
451
- <center>No need use Pesticides</center>"""
452
  else:
453
- predict_label="choose correct image"
454
 
455
- return predicted_label
456
 
 
 
 
 
 
 
 
 
 
 
457
 
458
  except Exception as e:
459
- print(f"Error: {e}")
460
- return None
461
 
462
  # List of class labels
463
  all_labels = [
@@ -473,19 +215,42 @@ all_labels = [
473
  'Tomato Bacterial spot'
474
  ]
475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
  # Define the Gradio interface
477
- def gradio_predict(image_file):
478
- return predict_disease(image_file, model, all_labels) # Pass the model to the function
 
 
479
 
480
- # Create a Gradio interface
481
  gr_interface = gr.Interface(
482
- fn=gradio_predict, # Function to call for predictions
483
- inputs=gr.Image(type="filepath"), # Upload image as file path
484
- outputs="html", # Output will be the class label as text
 
 
 
485
  title="Tomato Disease Predictor",
486
- description="Upload an image of a plant to predict the disease.",
487
  )
488
 
489
  # Launch the Gradio app
490
-
491
- gr_interface.launch()
 
1
+ import h5py
2
  import gradio as gr
3
+ from tensorflow.keras.utils import img_to_array, load_img
4
  from keras.models import load_model
5
  import numpy as np
6
+ from deep_translator import GoogleTranslator
7
 
8
  # Load the pre-trained model from the local path
9
  model_path = 'tomato.h5'
 
10
 
11
+ # Check if the model is loading correctly
12
+ try:
13
+ with h5py.File(model_path, 'r+') as f:
14
+ if 'groups' in f.attrs['model_config']:
15
+ model_config_string = f.attrs['model_config']
16
+ model_config_string = model_config_string.replace('"groups": 1,', '')
17
+ model_config_string = model_config_string.replace('"groups": 1}', '}')
18
+ f.attrs['model_config'] = model_config_string.encode('utf-8')
19
+
20
+ model = load_model(model_path)
21
+ print("Model loaded successfully.")
22
+ except Exception as e:
23
+ print(f"Error loading model: {e}")
24
+
25
+ def predict_disease(image_file, model, all_labels, target_language):
26
  try:
27
  # Load and preprocess the image
28
+ print(f"Received image file: {image_file}")
29
+ img = load_img(image_file, target_size=(224, 224)) # Ensure image size matches model input
30
  img_array = img_to_array(img)
31
  img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
32
  img_array = img_array / 255.0 # Normalize the image
33
 
34
  # Predict the class
35
+ predictions = model.predict(img_array)
36
  predicted_class = np.argmax(predictions[0])
37
+
38
  # Get the predicted class label
39
  predicted_label = all_labels[predicted_class]
 
 
40
 
41
+ # Translate the predicted label to the selected language
42
+ translated_label = GoogleTranslator(source='en', target=target_language).translate(predicted_label)
43
+
44
+ # Provide pesticide information based on the predicted label
45
+ if predicted_label == 'Tomato Yellow Leaf Curl Virus':
46
+ pesticide_info = """
47
+ <h2><center><b>Tomato Yellow Leaf Curl Virus</b></center></h2>
48
+ <h4>PESTICIDES TO BE USED:</h4><br>
49
+
50
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  <li>1. imidacloprid</li>
52
  <li>2. thiamethoxam</li>
53
  <li>3. Spinosad</li>
54
  <li>4. Acetamiprid</li>
 
55
  </ul><br>
56
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
57
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
 
58
  """
59
+ elif predicted_label == 'Tomato Target Spot':
60
+ pesticide_info = """
61
+ <h2><center><b>Tomato Target Spot</b></center></h2>
62
+ <h4>PESTICIDES TO BE USED:</h4><br>
63
+
64
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  <li>1. Azoxystrobin</li>
66
  <li>2. Boscalid</li>
67
  <li>3. Mancozeb</li>
68
  <li>4. Chlorothalonil</li>
69
  <li>5. Propiconazole</li>
70
+ </ul><br>
71
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
72
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
 
 
 
73
  """
74
+ elif predicted_label == 'Tomato Spider mites':
75
+ pesticide_info = """
76
+ <h2><center><b>Tomato Spider mites</b></center></h2>
77
+ <h4>PESTICIDES TO BE USED:</h4><br>
78
+
79
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  <li>1. Abamectin</li>
81
  <li>2. Spiromesifen</li>
82
  <li>3. Miticides</li>
83
+ <li>4. insecticidal soap</li>
 
84
  <li>5. Neem oil</li>
85
+ </ul><br>
86
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
87
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
 
 
88
  """
89
+ elif predicted_label == 'Tomato Septoria leaf spot':
90
+ pesticide_info = """
91
+ <h2><center><b>Tomato Septoria leaf spot</b></center></h2>
92
+ <h4>PESTICIDES TO BE USED:</h4><br>
93
+
94
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  <li>1. Azoxystrobin</li>
96
  <li>2. Boscalid</li>
97
  <li>3. Mancozeb</li>
98
  <li>4. Chlorothalonil</li>
99
  <li>5. Propiconazole</li>
100
+ </ul><br>
101
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
102
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
 
 
103
  """
104
+ elif predicted_label == 'Tomato Mosaic virus':
105
+ pesticide_info = """
106
+ <h2><center><b>Tomato Mosaic virus</b></center></h2>
107
+ <h4>PESTICIDES TO BE USED:</h4><br>
108
+
109
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  <li>1. Imidacloprid</li>
111
  <li>2. Thiamethoxam</li>
112
  <li>3. Acetamiprid</li>
113
  <li>4. Dinotefuran</li>
114
  <li>5. Pyrethrin</li>
115
+ </ul><br>
116
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
117
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
118
+ """
119
+ elif predicted_label == 'Tomato Leaf Mold':
120
+ pesticide_info = """
121
+ <h2><center><b>Tomato Leaf Mold</b></center></h2>
122
+ <h4>PESTICIDES TO BE USED:</h4><br>
123
+
124
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  <li>1. Azoxystrobin</li>
126
  <li>2. Boscalid</li>
127
  <li>3. Mancozeb</li>
128
  <li>4. Chlorothalonil</li>
129
  <li>5. Propiconazole</li>
130
+ </ul><br>
131
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
132
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
133
+ """
134
+ elif predicted_label == 'Tomato Late blight':
135
+ pesticide_info = """
136
+ <h2><center><b>Tomato Late blight</b></center></h2>
137
+ <h4>PESTICIDES TO BE USED:</h4><br>
138
+
139
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  <li>1. metalaxl</li>
141
  <li>2. Chlorothalonil</li>
142
  <li>3. Mancozeb</li>
143
  <li>4. Copper oxychloride</li>
144
  <li>5. Azoxystrobin</li>
145
+ </ul><br>
146
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
147
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
148
+ """
149
+ elif predicted_label == 'Tomato Early blight':
150
+ pesticide_info = """
151
+ <h2><center><b>Tomato Early blight</b></center></h2>
152
+ <h4>PESTICIDES TO BE USED:</h4><br>
153
+
154
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  <li>1. Azoxystrobin</li>
156
  <li>2. Boscalid</li>
157
  <li>3. Mancozeb</li>
158
  <li>4. Chlorothalonil</li>
159
  <li>5. Propiconazole</li>
160
+ </ul><br>
161
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
162
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
 
 
163
  """
164
+ elif predicted_label == 'Tomato Bacterial spot':
165
+ pesticide_info = """
166
+ <h2><center><b>Tomato Bacterial spot</b></center></h2>
167
+ <h4>PESTICIDES TO BE USED:</h4><br>
168
+
169
+ <ul style="font-size:17px;margin-left:40px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  <li>1. Copper oxychloride</li>
171
  <li>2. Streptomycin</li>
172
  <li>3. tetracycline</li>
173
  <li>4. Oxytetracline(Terramycin)</li>
174
  <li>5. Insecticidal soap</li>
175
  <li>6. Horticultural oil</li>
176
+ </ul><br>
177
+ <center><p class="note" style="font-size:15px;"><b>* * * IMPORTANT NOTE * * *</b></p></center><br>
178
+ <center><p style="font-size:13px;">Be sure to follow local regulations and guidelines for application</p></center>
179
+ """
180
+ elif predicted_label == 'Tomato Healthy':
181
+ pesticide_info = """<h2><center><b>Tomato Healthy</b></center></h2>
182
+ <h5> No pesticides needed"""
183
+
 
 
 
184
  else:
185
+ pesticide_info = 'No pesticide information available.'
186
 
187
+ print(f"Pesticide Info (Before Translation): {pesticide_info}")
188
 
189
+ # Translate the pesticide information to the selected language
190
+ translated_pesticide_info = GoogleTranslator(source='en', target=target_language).translate(pesticide_info)
191
+ print(f"Translated Pesticide Info: {translated_pesticide_info}")
192
+
193
+ # Return translated label and pesticide information with associated styling
194
+ predicted_label_html = f"""
195
+
196
+ {translated_pesticide_info}
197
+ """
198
+ return predicted_label_html
199
 
200
  except Exception as e:
201
+ print(f"Error during prediction: {e}")
202
+ return f"<h3>Error: {e}</h3>"
203
 
204
  # List of class labels
205
  all_labels = [
 
215
  'Tomato Bacterial spot'
216
  ]
217
 
218
+ # Language codes and their full names (display full names in dropdown)
219
+ language_choices = {
220
+ 'hi': 'Hindi',
221
+ 'te': 'Telugu',
222
+ 'en': 'English',
223
+ 'ml': 'Malayalam',
224
+ 'ta': 'Tamil',
225
+ 'bn': 'Bengali',
226
+ 'gu': 'Gujarati',
227
+ 'kn': 'Kannada',
228
+ 'mr': 'Marathi'
229
+ }
230
+
231
+ # Mapping full names back to their corresponding language code
232
+ full_to_code = {value: key for key, value in language_choices.items()}
233
+
234
+ # Create a dropdown of full language names, using the full name in the UI
235
+ languages = list(language_choices.values()) # List of full language names
236
+
237
  # Define the Gradio interface
238
+ def gradio_predict(image_file, target_language):
239
+ # Map full name back to language code for translation
240
+ language_code = full_to_code.get(target_language, 'en')
241
+ return predict_disease(image_file, model, all_labels, language_code)
242
 
243
+ # Create the Gradio interface
244
  gr_interface = gr.Interface(
245
+ fn=gradio_predict,
246
+ inputs=[
247
+ gr.Image(type="filepath"), # Image input for disease prediction
248
+ gr.Dropdown(label="Select language", choices=languages, value='English') # Language selection dropdown with full names
249
+ ],
250
+ outputs="html", # Output will be in HTML (translated text)
251
  title="Tomato Disease Predictor",
252
+ description="Upload an image of a plant to predict the disease and get the translated label and pesticide information in the selected language."
253
  )
254
 
255
  # Launch the Gradio app
256
+ gr_interface.launch()