Spaces:
Running
Running
File size: 1,308 Bytes
4a0cd82 7f97dd6 4557350 2dd2d70 169781f f305096 e3e70fd 169781f f305096 169781f f305096 e1976f4 7f97dd6 4557350 f305096 d804613 7f97dd6 169781f 7f97dd6 4557350 7f97dd6 d804613 7f97dd6 169781f d804613 4a0cd82 169781f 7c5f722 f305096 7c5f722 f305096 7c5f722 f305096 169781f 7c5f722 4a0cd82 4557350 169781f 4557350 |
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 50 |
import gradio as gr
from ultralyticsplus import YOLO, render_result
import cv2
import time
# Load model
model = YOLO('foduucom/plant-leaf-detection-and-classification')
# Model configuration
model.overrides.update({
'conf': 0.25,
'iou': 0.45,
'imgsz': 640,
'device': '0' if next(model.model.parameters()).is_cuda else 'cpu'
})
def detect_leaves(image):
start_time = time.time()
# Convert image format
img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Predict
results = model.predict(img, verbose=False)
# Process results
num_leaves = len(results[0].boxes)
rendered_img = render_result(model=model, image=img, result=results[0])
print(f"Processing time: {time.time() - start_time:.2f}s")
return cv2.cvtColor(rendered_img, cv2.COLOR_BGR2RGB), num_leaves
# Create interface with queue support
interface = gr.Interface(
fn=detect_leaves,
inputs=gr.Image(label="Plant Image"),
outputs=[
gr.Image(label="Detection Result", width=600),
gr.Number(label="Leaves Count")
],
title="π Leaf Detection",
flagging_mode="never" # Updated from allow_flagging
)
if __name__ == "__main__":
interface.launch(
server_port=7860,
share=False,
# Removed enable_queue parameter
) |