| import gradio as gr | |
| from ultralytics import YOLO | |
| def detect_objects(image): | |
| model = YOLO('yolov8m.pt') | |
| results = model(image) | |
| annotated_image = results[0].plot() | |
| return annotated_image | |
| app = gr.Interface( | |
| title="YOLOv8 目标检测 Demo", | |
| fn=detect_objects, | |
| inputs="image", | |
| outputs="image") | |
| app.launch() |