Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,36 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
pipe = pipeline("image-classification", model=
|
| 8 |
|
| 9 |
-
def
|
|
|
|
| 10 |
predictions = pipe(image)
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
for pred in predictions:
|
| 13 |
-
label
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return result
|
| 17 |
|
|
|
|
| 18 |
iface = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
-
inputs=gr.Image(type="pil"),
|
| 21 |
-
outputs="text",
|
| 22 |
-
title="Plant Disease
|
| 23 |
-
description="Upload an image
|
| 24 |
)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
| 1 |
+
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
+
from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# Load the pre-trained model and image processor
|
| 8 |
+
model_name = "Diginsa/Plant-Disease-Detection-Project"
|
| 9 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 11 |
|
| 12 |
+
# Create the prediction pipeline
|
| 13 |
+
pipe = pipeline("image-classification", model=model, image_processor=processor)
|
| 14 |
|
| 15 |
+
def predict_disease(image):
|
| 16 |
+
"""Predicts the plant disease based on the input image."""
|
| 17 |
predictions = pipe(image)
|
| 18 |
+
|
| 19 |
+
# Format the predictions for display
|
| 20 |
+
results = []
|
| 21 |
for pred in predictions:
|
| 22 |
+
results.append(f"{pred['label']}: {pred['score']:.4f}")
|
| 23 |
+
|
| 24 |
+
return "\n".join(results) # Return predictions as a single string
|
|
|
|
| 25 |
|
| 26 |
+
# Create the Gradio interface
|
| 27 |
iface = gr.Interface(
|
| 28 |
+
fn=predict_disease,
|
| 29 |
+
inputs=gr.Image(type="pil"), # Input is a PIL Image
|
| 30 |
+
outputs="text", # Output is a text string with predictions
|
| 31 |
+
title="Plant Disease Detection",
|
| 32 |
+
description="Upload an image of a plant to detect potential diseases.",
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# Launch the Gradio interface
|
| 36 |
+
iface.launch()
|