Spaces:
Runtime error
Runtime error
File size: 671 Bytes
b567593 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt') # Ensure this file is in the same directory
def detect_objects(image):
results = model(image) # Run inference
boxes = results[0].boxes # Get bounding boxes
detected_classes = [model.names[int(box.cls)] for box in boxes] # Get class names
return detected_classes
# Create a Gradio interface
interface = gr.Interface(
fn=detect_objects,
inputs=gr.Image(type="pil"),
outputs="label",
title="Object Detection Bot",
description="Upload an image to detect objects."
)
# Launch the interface
interface.launch()
|