Spaces:
Build error
Build error
| 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() |