Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| from PIL import Image | |
| # Load the Hugging Face image classification pipeline with EfficientNetB0 | |
| # This model is generic for plant disease, so if you have a specific tobacco disease model, replace it accordingly | |
| classifier = pipeline("image-classification", model="nateraw/efficientnet-b0") | |
| def identify_disease(image): | |
| # Use the classifier to predict the disease | |
| predictions = classifier(image) | |
| # Format the output to include disease name and confidence score | |
| results = [{"Disease": pred["label"], "Confidence": f"{pred['score'] * 100:.2f}%"} for pred in predictions] | |
| # Return the uploaded image along with the results | |
| return image, results | |
| # Define Gradio interface | |
| interface = gr.Interface( | |
| fn=identify_disease, | |
| inputs=gr.inputs.Image(type="pil"), | |
| outputs=[ | |
| gr.outputs.Image(type="pil", label="Uploaded Image"), | |
| gr.outputs.Dataframe(type="pandas", label="Predictions") | |
| ], | |
| title="Tobacco Plant Disease Identifier", | |
| description="Upload an image of a tobacco plant, and this tool will identify the disease along with the confidence score." | |
| ) | |
| # Launch the app | |
| interface.launch() | |