Spaces:
Runtime error
Runtime error
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() | |