|
import gradio as gr |
|
from ultralytics import YOLO |
|
|
|
|
|
|
|
model = YOLO("best (1).pt") |
|
|
|
def detect(image): |
|
""" |
|
Runs object detection on the input image. |
|
|
|
Args: |
|
image: A numpy array representing the input image. |
|
|
|
Returns: |
|
Annotated image as a numpy array. |
|
""" |
|
|
|
results = model(image) |
|
|
|
|
|
annotated_image = results[0].plot() |
|
return annotated_image |
|
|
|
|
|
iface = gr.Interface( |
|
fn=detect, |
|
inputs=gr.Image(type="numpy", label="Input Image"), |
|
outputs=gr.Image(type="numpy", label="Detection Output"), |
|
title="YOLOv8n Object Detection", |
|
description="Upload an image and the model will detect objects using YOLOv8n." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|