Spaces:
Sleeping
Sleeping
File size: 1,035 Bytes
5a596d2 4a0cd82 2dd2d70 0770f2c 05ea63d e1976f4 0770f2c 4e9dcdb 0770f2c 4e9dcdb 0770f2c 4a0cd82 0770f2c 4a0cd82 0770f2c 4a0cd82 0770f2c 4a0cd82 a835c9c |
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 |
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()
|