agroscan / app.py
isana25's picture
Update app.py
2ee4dd1 verified
raw
history blame contribute delete
889 Bytes
from ultralytics import YOLO
import gradio as gr
from PIL import Image
import torch
# Load YOLOv5 model
model = YOLO("best.pt") # assumes model is in the same directory
# Prediction function
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
# Gradio UI
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()