File size: 716 Bytes
9819126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import cv2
from ultralytics import YOLO
import numpy as np

# Load Advanced YOLOv8 Model (medium version)
model = YOLO('yolov8m.pt')  # You can switch to yolov8l.pt or yolov8x.pt for even more accuracy

def detect_objects(image):
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    results = model(image)
    annotated = results[0].plot()
    annotated = cv2.cvtColor(annotated, cv2.COLOR_BGR2RGB)
    return annotated

gr.Interface(
    fn=detect_objects,
    inputs=gr.Image(type="numpy", label="Upload an Image"),
    outputs="image",
    title="Advanced Object Detection with YOLOv8m",
    description="Upload an image to detect objects using YOLOv8 Medium Model (YOLOv8m.pt)."
).launch()