leaf-counter / app.py
muskangoyal06's picture
Update app.py
05ea63d verified
raw
history blame
1.04 kB
from ultralytics import YOLO
import gradio as gr
# Load the pretrained model directly using YOLOvv8.from_pretrained
model = YOLO("foduucom/plant-leaf-detection-and-classification")
def predict_leaves(image_path):
"""
Given an image file path, run prediction on it using the YOLOvv8 model.
The model will automatically save the result if configured.
"""
# Run the prediction; you can pass additional kwargs as needed (like save=True)
results = model.predict(source=image_path, save=True)
# Optionally, count the detected leaves using the first result
count = len(results[0].boxes)
return f"Detected leaves: {count}"
# Build a Gradio Interface for the leaf detection app
iface = gr.Interface(
fn=predict_leaves,
inputs=gr.Image(type="filepath"), # Users can upload an image file
outputs="text",
title="Leaf Detection & Classification",
description="Upload an image to detect and count leaves using the YOLOvv8 model."
)
if __name__ == "__main__":
iface.launch()