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