File size: 704 Bytes
e7a0427
a0292e2
8cfa67f
 
 
 
 
 
a0292e2
da960f9
a0292e2
 
 
 
 
8cfa67f
a0292e2
8cfa67f
a0292e2
8cfa67f
 
a0292e2
8cfa67f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from ultralytics import YOLO
import gradio as gr

# Optional: Download weights if not present
if not os.path.exists("weights/yolov8n.pt"):
    from huggingface_hub import hf_hub_download
    hf_hub_download(repo_id="ultralytics/yolov8", filename="yolov8n.pt", local_dir="weights")

model = YOLO("weights/yolov8n.pt")

def detect_objects(image):
    results = model(image)
    return results[0].plot()

interface = gr.Interface(
    fn=detect_objects,
    inputs=gr.Image(sources=["upload", "webcam"], type="numpy", label="Input Image"),
    outputs=gr.Image(type="numpy", label="Detection Output"),
    live=False  # Set to False for upload, True for webcam (browser only)
)

interface.launch()