detect / app.py
Samp21's picture
Create app.py
0c3390c verified
raw
history blame contribute delete
705 Bytes
import torch
import gradio as gr
from PIL import Image
# Load pre-trained YOLOv5 model from ultralytics
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
def detect_objects(image):
# Perform inference
results = model(image)
results.render() # updates results.imgs with boxes and labels
detected_image = Image.fromarray(results.imgs[0])
return detected_image
# Define Gradio interface
iface = gr.Interface(
fn=detect_objects,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.outputs.Image(type="pil"),
title="Object Detection with YOLOv5",
description="Upload an image and get the detected objects with their names."
)
# Launch the interface
iface.launch()