Maruf
share=true
2e6f8b0
raw
history blame contribute delete
548 Bytes
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)