File size: 872 Bytes
505b5b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d4e7bb
988f95a
505b5b9
988f95a
 
 
0d4e7bb
505b5b9
 
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
import cv2
from ultralytics import YOLO
from huggingface_hub import hf_hub_download

# Download YOLOv8 weights from Hugging Face
weights_path = hf_hub_download(
    repo_id="foduucom/plant-leaf-detection-and-classification",
    filename="best.pt"
)

# Load YOLOv8 model
model = YOLO(weights_path)

# Prediction function
def predict(image):
    img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)  # convert for YOLO
    results = model(img)
    result_img = results[0].plot()
    result_img = cv2.cvtColor(result_img, cv2.COLOR_BGR2RGB)
    return result_img

# Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="numpy"),  # simple upload
    outputs=gr.Image(type="numpy"),
    title="Plant Leaf Detection & Classification",
    description="Upload a plant leaf image to detect diseases and classify leaves."
)

iface.launch()