Spaces:
Sleeping
Sleeping
File size: 941 Bytes
cfbecf8 69ae6ea c80404c cfbecf8 69ae6ea cfbecf8 69ae6ea c80404c 69ae6ea c80404c cfbecf8 c80404c 69ae6ea cfbecf8 | 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 | import gradio as gr
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
import numpy as np
model_path = hf_hub_download(repo_id="newtechdevng/detect", filename="best.pt")
model = YOLO(model_path)
def predict(image):
results = model(image)
result = results[0]
# Get annotated image with boxes drawn
annotated = result.plot()
labels = []
for box in result.boxes:
confidence = float(box.conf)
if confidence < 0.5:
continue
label = result.names[int(box.cls)]
labels.append(f"{label}: {confidence:.2f}")
return annotated, "\n".join(labels) if labels else "No objects detected"
gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=[
gr.Image(label="Detected Objects"), # image with boxes
gr.Text(label="Labels") # text results
],
title="Car / Bike / Mountain / Road Detector"
).launch() |