Kennethdotse commited on
Commit
d21529f
·
1 Parent(s): aeb5053
Files changed (2) hide show
  1. app.py +38 -5
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  import cv2
@@ -15,36 +21,63 @@ def detect(image):
15
  if image is None:
16
  return None
17
 
 
 
18
  results = model(
19
  image,
20
  verbose=False
21
  )
22
 
 
 
23
  annotated = results[0].plot()
24
 
 
 
25
  annotated = cv2.cvtColor(
26
  annotated,
27
  cv2.COLOR_BGR2RGB
28
  )
29
 
 
30
  return annotated
31
 
32
 
 
33
  demo = gr.Interface(
 
34
  fn=detect,
 
35
  inputs=gr.Image(
36
  sources=["webcam"],
37
- type="numpy"
 
38
  ),
 
39
  outputs=gr.Image(
40
- type="numpy"
 
41
  ),
42
- title="YOLO Webcam Demo"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
 
45
 
46
- print("Launching Gradio...")
47
 
48
  demo.launch(
49
- server_name="0.0.0.0",
50
  )
 
1
+ import os
2
+
3
+ # Fix Ultralytics permission warning
4
+ os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics"
5
+
6
+
7
  import gradio as gr
8
  from ultralytics import YOLO
9
  import cv2
 
21
  if image is None:
22
  return None
23
 
24
+
25
+ # Run YOLO inference
26
  results = model(
27
  image,
28
  verbose=False
29
  )
30
 
31
+
32
+ # Draw detections
33
  annotated = results[0].plot()
34
 
35
+
36
+ # Convert BGR -> RGB
37
  annotated = cv2.cvtColor(
38
  annotated,
39
  cv2.COLOR_BGR2RGB
40
  )
41
 
42
+
43
  return annotated
44
 
45
 
46
+
47
  demo = gr.Interface(
48
+
49
  fn=detect,
50
+
51
  inputs=gr.Image(
52
  sources=["webcam"],
53
+ type="numpy",
54
+ label="Mobile Camera"
55
  ),
56
+
57
  outputs=gr.Image(
58
+ type="numpy",
59
+ label="AI Detection"
60
  ),
61
+
62
+ title="AI Shop Security Demo",
63
+
64
+ description="""
65
+ Real-time shop monitoring prototype.
66
+
67
+ Model:
68
+ - YOLOv8 Nano
69
+
70
+ Detects:
71
+ - People
72
+ - Bags
73
+ - Objects
74
+
75
+ Demo only: detections should be reviewed by humans.
76
+ """
77
  )
78
 
79
 
 
80
 
81
  demo.launch(
82
+ server_name="0.0.0.0"
83
  )
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  ultralytics
2
  opencv-python-headless
3
  numpy
 
 
1
  ultralytics
2
  opencv-python-headless
3
  numpy
4
+ spaces