Spaces:
Running
Running
import gradio as gr | |
from ultralyticsplus import YOLO | |
from PIL import Image | |
# Load YOLOv8 leaf detection model | |
model = YOLO('foduucom/plant-leaf-detection-and-classification') | |
def count_leaves(image): | |
# Convert to PIL Image if needed | |
image = Image.open(image).convert("RGB") | |
# Run inference | |
results = model.predict(image) | |
# Count number of detected leaves | |
num_leaves = len(results[0].boxes) | |
return f"Number of leaves detected: {num_leaves}" | |
# Gradio UI | |
iface = gr.Interface( | |
fn=count_leaves, | |
inputs=gr.Image(type="filepath"), # User uploads an image | |
outputs="text", | |
title="Leaf Counter", | |
description="Upload an image of a plant, and the model will detect and count the number of leaves." | |
) | |
# Launch app | |
if __name__ == "__main__": | |
iface.launch() |