File size: 815 Bytes
941c7e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from ultralytics import YOLO
from PIL import Image
import numpy as np
import gradio as gr

# Load a YOLOv8 model (YOLOv8n is the smallest and fastest version)
model = YOLO('yolov8n.pt')

def detect_objects(image):
    results = model(image)
    rendered_image = results[0].plot()  # This returns a numpy array with the bounding boxes drawn
    return Image.fromarray(rendered_image)  # Convert the numpy array back to an image

# Define the Gradio interface
interface = gr.Interface(
    fn=detect_objects,  # Function to process the input
    inputs=gr.Image(type="pil"),  # Input is an image
    outputs=gr.Image(type="pil"),  # Output is an image
    title="YOLOv8 Object Detection",
    description="Upload an image to detect objects using YOLOv8."
)

# Launch the Gradio interface
interface.launch(share=True)