bhanusAI commited on
Commit
01462ec
·
verified ·
1 Parent(s): f8cfbac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -4,6 +4,7 @@ import tensorflow as tf # version 2.13.0
4
  from keras.models import load_model
5
  import cv2
6
  import json
 
7
 
8
  def analyse(img, plant_type):
9
  # Load label_disease.json
@@ -66,6 +67,21 @@ def analyse(img, plant_type):
66
 
67
  return result
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Gradio interface
70
  demo = gr.Interface(
71
  fn=analyse,
@@ -74,7 +90,13 @@ demo = gr.Interface(
74
  gr.Radio(["Apple", "Blueberry", "Cherry", "Corn", "Grape", "Orange", "Peach",
75
  "Pepper", "Potato", "Raspberry", "Soybean", "Squash", "Strawberry", "Tomato"])
76
  ],
77
- outputs=gr.JSON()
 
 
 
 
78
  )
79
 
80
- demo.launch(share=True, show_error=True)
 
 
 
4
  from keras.models import load_model
5
  import cv2
6
  import json
7
+ import os
8
 
9
  def analyse(img, plant_type):
10
  # Load label_disease.json
 
67
 
68
  return result
69
 
70
+ def get_example_images():
71
+ examples = []
72
+ example_dir = "examples"
73
+
74
+ # Load all images from examples directory
75
+ if os.path.exists(example_dir):
76
+ image_files = [f for f in os.listdir(example_dir) if f.endswith(('.jpg', ,'JPG','.jpeg', '.png'))]
77
+ for img_file in image_files:
78
+ # Extract plant type from filename (assumes filename format: planttype_condition.jpg)
79
+ plant_type = img_file.split('_')[0].capitalize()
80
+ img_path = os.path.join(example_dir, img_file)
81
+ examples.append([img_path, plant_type])
82
+
83
+ return examples
84
+
85
  # Gradio interface
86
  demo = gr.Interface(
87
  fn=analyse,
 
90
  gr.Radio(["Apple", "Blueberry", "Cherry", "Corn", "Grape", "Orange", "Peach",
91
  "Pepper", "Potato", "Raspberry", "Soybean", "Squash", "Strawberry", "Tomato"])
92
  ],
93
+ outputs=gr.JSON(),
94
+ examples=get_example_images(),
95
+ title="Plant Disease Detection",
96
+ description="""Upload an image of a plant leaf or use one of the example images below.
97
+ Select the type of plant and the model will analyze it for diseases."""
98
  )
99
 
100
+ # Launch the interface
101
+ if __name__ == "__main__":
102
+ demo.launch(share=True, show_error=True)