Spaces:
Runtime error
Runtime error
| import os | |
| # Fix Ultralytics permission warning | |
| os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics" | |
| import gradio as gr | |
| from ultralytics import YOLO | |
| import cv2 | |
| print("Loading YOLO model...") | |
| model = YOLO("yolov8n.pt") | |
| print("Model loaded!") | |
| def detect(image): | |
| if image is None: | |
| return None | |
| # Run YOLO inference | |
| results = model( | |
| image, | |
| verbose=False | |
| ) | |
| # Draw detections | |
| annotated = results[0].plot() | |
| # Convert BGR -> RGB | |
| annotated = cv2.cvtColor( | |
| annotated, | |
| cv2.COLOR_BGR2RGB | |
| ) | |
| return annotated | |
| demo = gr.Interface( | |
| fn=detect, | |
| inputs=gr.Image( | |
| sources=["webcam"], | |
| type="numpy", | |
| label="Mobile Camera" | |
| ), | |
| outputs=gr.Image( | |
| type="numpy", | |
| label="AI Detection" | |
| ), | |
| title="AI Shop Security Demo", | |
| description=""" | |
| Real-time shop monitoring prototype. | |
| Model: | |
| - YOLOv8 Nano | |
| Detects: | |
| - People | |
| - Bags | |
| - Objects | |
| Demo only: detections should be reviewed by humans. | |
| """ | |
| ) | |
| demo.launch( | |
| server_name="0.0.0.0" | |
| ) |