bhanusAI commited on
Commit
5a960f6
·
verified ·
1 Parent(s): 969f366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -67,34 +67,28 @@ def analyse(img, plant_type):
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,
88
- inputs=[
89
- gr.Image(type="numpy"),
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
 
67
 
68
  return result
69
 
70
+ # Create Gradio interface
71
+ input_image = gr.Image(type="numpy")
72
+ plant_type = gr.Radio(["Apple", "Blueberry", "Cherry", "Corn", "Grape", "Orange", "Peach",
73
+ "Pepper", "Potato", "Raspberry", "Soybean", "Squash", "Strawberry", "Tomato"])
74
+
 
 
 
 
 
 
 
 
 
 
 
75
  demo = gr.Interface(
76
  fn=analyse,
77
+ inputs=[input_image, plant_type],
 
 
 
 
78
  outputs=gr.JSON(),
 
79
  title="Plant Disease Detection",
80
+ description="Upload an image of a plant leaf or use one of the example images below. Select the type of plant and the model will analyze it for diseases."
81
+ )
82
+
83
+ # Add examples component
84
+ examples = gr.Examples(
85
+ examples=[
86
+ os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
87
+ ],
88
+ inputs=[input_image],
89
+ label="Examples",
90
+ cache_examples=False,
91
+ examples_per_page=16
92
  )
93
 
94
  # Launch the interface