File size: 985 Bytes
95aca65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 torch
import ultralytics
from ultralytics import YOLO
import cv2
import gradio as gr

# ---- FIX for PyTorch 2.6+ ----
torch.serialization.add_safe_globals([ultralytics.nn.tasks.DetectionModel])

# ---- Load trained YOLO model ----
model = YOLO("tea.pt")  # Make sure 'best.pt' is in the same folder

# ---- Prediction function ----
def predict(image):
    # Run inference
    results = model.predict(source=image, conf=0.25)
    # Draw boxes on the image
    result_image = results[0].plot()
    # Convert BGR → RGB for Gradio
    return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)

# ---- Gradio Interface ----
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="filepath", label="Upload Tea Leaf Image"),
    outputs=gr.Image(type="numpy", label="Detection Result"),
    title="Tea Leaf Disease Detection",
    description="Upload a tea leaf image to detect types of tea leaf diseases using YOLOv8."
)

if __name__ == "__main__":
    iface.launch(debug=True)