chimithecat commited on
Commit
7d764e2
·
1 Parent(s): 3e6ffb6

Fix: ensure image is PIL.Image for Hugging Face pipeline

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1,10 +1,20 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
 
4
  model = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")
5
 
6
  def classify(image):
 
 
7
  result = model(image)
8
- return result
9
 
10
- gr.Interface(fn=classify, inputs="image", outputs="label").launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from PIL import Image # ✅ make sure PIL is imported
4
 
5
+ # Load your model
6
  model = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")
7
 
8
  def classify(image):
9
+ if not isinstance(image, Image.Image):
10
+ image = Image.fromarray(image) # fallback, just in case
11
  result = model(image)
12
+ return result[0]['label'] # return top label
13
 
14
+ gr.Interface(
15
+ fn=classify,
16
+ inputs=gr.Image(type="pil"),
17
+ outputs="label",
18
+ title="Tomato Leaf Disease Analyzer",
19
+ description="Upload a tomato leaf image to detect the disease."
20
+ ).launch()