Spaces:
Sleeping
Sleeping
File size: 548 Bytes
ab14be8 ef46d86 ab14be8 ef46d86 ab14be8 ef46d86 2e6f8b0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import gradio as gr
import torch
from PIL import Image
# Load a pretrained model (YOLOv5 for example)
model = torch.hub.load("ultralytics/yolov5", "yolov5s", pretrained=True)
def detect_objects(image):
results = model(image)
detections = results.pandas().xyxy[0].to_dict(orient="records")
return detections # JSON-friendly list of dicts
# Gradio interface
iface = gr.Interface(
fn=detect_objects,
inputs=gr.Image(type="pil"),
outputs=gr.JSON(),
examples=[]
)
if __name__ == "__main__":
iface.launch(share=True)
|