Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +32 -0
- requirements.txt +5 -0
- tea.pt +3 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import ultralytics
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import cv2
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# ---- FIX for PyTorch 2.6+ ----
|
| 8 |
+
torch.serialization.add_safe_globals([ultralytics.nn.tasks.DetectionModel])
|
| 9 |
+
|
| 10 |
+
# ---- Load trained YOLO model ----
|
| 11 |
+
model = YOLO("best.pt") # Make sure 'best.pt' is in the same folder
|
| 12 |
+
|
| 13 |
+
# ---- Prediction function ----
|
| 14 |
+
def predict(image):
|
| 15 |
+
# Run inference
|
| 16 |
+
results = model.predict(source=image, conf=0.25)
|
| 17 |
+
# Draw boxes on the image
|
| 18 |
+
result_image = results[0].plot()
|
| 19 |
+
# Convert BGR → RGB for Gradio
|
| 20 |
+
return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)
|
| 21 |
+
|
| 22 |
+
# ---- Gradio Interface ----
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs=gr.Image(type="filepath", label="Upload Tea Leaf Image"),
|
| 26 |
+
outputs=gr.Image(type="numpy", label="Detection Result"),
|
| 27 |
+
title="Tea Leaf Disease Detection",
|
| 28 |
+
description="Upload a tea leaf image to detect types of tea leaf diseases using YOLOv8."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
iface.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ultralytics
|
| 2 |
+
opencv-python
|
| 3 |
+
numpy
|
| 4 |
+
gradio
|
| 5 |
+
torch
|
tea.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b20a9df806ff832661d694de8933bb9eaa1fa121202a3a7e8333a2d0ca8ad4e4
|
| 3 |
+
size 6249123
|