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()