|
from ultralytics import YOLO |
|
import gradio as gr |
|
from PIL import Image |
|
import torch |
|
|
|
|
|
model = YOLO("best.pt") |
|
|
|
|
|
def predict(image): |
|
results = model(image) |
|
boxes = results[0].boxes |
|
names = model.names |
|
output = "" |
|
|
|
if len(boxes) == 0: |
|
output = "β
Healthy: No disease detected!" |
|
else: |
|
for box in boxes: |
|
class_id = int(box.cls[0]) |
|
class_name = names[class_id] |
|
confidence = float(box.conf[0]) |
|
output += f"π¨ Detected: {class_name} ({confidence*100:.2f}%)\n" |
|
|
|
return output |
|
|
|
|
|
gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="pil"), |
|
outputs="text", |
|
title="πΏ AgroScan: Plant Disease Detector", |
|
description="Upload a plant leaf image to detect disease using a YOLOv5 model.", |
|
).launch() |
|
|