File size: 1,110 Bytes
d21529f
 
 
 
 
 
8442657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d21529f
 
8442657
 
 
 
 
d21529f
 
8442657
 
d21529f
 
8442657
 
 
 
 
d21529f
8442657
 
 
d21529f
8442657
d21529f
8442657
d21529f
8442657
 
d21529f
 
8442657
d21529f
8442657
d21529f
 
8442657
d21529f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8442657
 
 
 
 
d21529f
8442657
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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"
)