Spaces:
Running
Running
File size: 1,445 Bytes
4a0cd82 7f97dd6 3b7e08f d804613 2dd2d70 7c5f722 d804613 e3e70fd d804613 3b7e08f d804613 e1976f4 7f97dd6 3b7e08f d804613 7f97dd6 d804613 7f97dd6 d804613 7f97dd6 d804613 7f97dd6 d804613 4a0cd82 d804613 7c5f722 d804613 7c5f722 d804613 7c5f722 4a0cd82 7c5f722 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
from ultralyticsplus import YOLO, render_result
import cv2
import torch
import ultralytics
import ultralyticsplus
# Check versions
print(f"Torch version: {torch.__version__}")
print(f"Ultralytics version: {ultralytics.__version__}")
print(f"UltralyticsPlus version: {ultralyticsplus.__version__}")
# Load model
model = YOLO('foduucom/plant-leaf-detection-and-classification')
# Model configuration
model.overrides['conf'] = 0.25 # Confidence threshold
model.overrides['iou'] = 0.45 # IoU threshold
model.overrides['agnostic_nms'] = False
model.overrides['max_det'] = 1000
def detect_leaves(image):
# Convert image format
img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Perform prediction
results = model.predict(img)
# Get results
num_leaves = len(results[0].boxes)
rendered_img = render_result(model=model, image=img, result=results[0])
# Convert back to RGB for Gradio
return cv2.cvtColor(rendered_img, cv2.COLOR_BGR2RGB), num_leaves
# Create Gradio interface
interface = gr.Interface(
fn=detect_leaves,
inputs=gr.Image(label="Upload Plant Image"),
outputs=[
gr.Image(label="Detected Leaves"),
gr.Number(label="Number of Leaves Found")
],
title="π Plant Leaf Detection & Counting",
description="Upload an image of a plant to detect and count its leaves"
)
if __name__ == "__main__":
interface.launch(server_port=7860) |