|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
from ultralytics import YOLO |
|
|
|
|
|
model = YOLO('yolov5s') |
|
|
|
|
|
def run_inference(image): |
|
|
|
image = np.array(image) |
|
|
|
|
|
results = model.predict(source=image, save=False, conf=0.25, stream=False) |
|
|
|
|
|
annotated_image = results[0].plot() |
|
|
|
return annotated_image |
|
|
|
|
|
interface = gr.Interface( |
|
fn=run_inference, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Image(type="numpy"), |
|
title="YOLOv5 Object Detection", |
|
description="Upload an image to run YOLOv5 object detection and see the results." |
|
) |
|
|
|
|
|
interface.launch() |
|
|