File size: 1,210 Bytes
6989a37
90d35fd
30f242a
6989a37
90d35fd
 
 
75e60e4
90d35fd
 
 
6989a37
90d35fd
 
1a4514d
90d35fd
 
e3a012f
90d35fd
 
 
 
 
 
 
 
 
 
30f242a
e3a012f
90d35fd
 
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
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()