File size: 1,157 Bytes
6989a37
ba2ce75
30f242a
6989a37
ba2ce75
 
 
75e60e4
90d35fd
ba2ce75
 
6989a37
ba2ce75
 
1a4514d
ba2ce75
 
e3a012f
90d35fd
 
ba2ce75
90d35fd
 
ba2ce75
 
90d35fd
ba2ce75
 
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 a general-purpose model for plant disease classification
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="Plant Disease Identifier",
    description="Upload an image of a plant leaf, and this tool will identify the disease along with the confidence score."
)

# Launch the app
interface.launch()