Abs6187 commited on
Commit
2d5c39f
·
verified ·
1 Parent(s): 64e27b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
 
4
 
5
  # Load YOLO model
6
  model = YOLO("Suspicious_Activities_nano.pt")
@@ -8,42 +9,48 @@ model = YOLO("Suspicious_Activities_nano.pt")
8
  # Define the prediction function
9
  def predict_suspicious_activity(image):
10
  results = model.predict(source=image, show=False, conf=0.6)
11
- results_img = results[0].plot() # Get the image with bounding boxes/annotations
12
  return Image.fromarray(results_img)
13
 
14
- # Create Gradio interface with enhanced UI
 
 
 
15
  interface = gr.Interface(
16
  fn=predict_suspicious_activity,
17
- inputs=gr.Image(type="pil", label="Upload Security Footage", height=350),
18
- outputs=gr.Image(type="pil", label="Detection Results", height=350),
19
- title="🚨 Advanced Suspicious Activity Detection System",
20
  description="""
21
- **Real-time threat identification using YOLOv8 technology**
22
- Our system detects multiple suspicious behaviors including:
23
- - Loitering and unauthorized presence [[7]]
24
- - Physical altercations and fighting
25
- - Trespassing in restricted areas [[7]]
26
- - Vandalism and property damage
27
  - Suspicious package handling
 
28
 
29
- Upload your image or try our pre-loaded security footage examples below!
30
  """,
31
  examples=[
32
- ["https://cdn.pixabay.com/photo/2016/08/11/23/36/car-1587281_1280.jpg"], # Car break-in attempt
33
- ["https://cdn.pixabay.com/photo/2017/08/06/12/18/man-2595256_1280.jpg"], # Suspicious loitering
34
- ["https://cdn.pixabay.com/photo/2016/08/11/23/35/security-1587280_1280.jpg"] # Security monitoring
35
  ],
36
  cache_examples=False,
37
- theme=gr.themes.Soft(primary_hue="indigo", font=[gr.themes.GoogleFont('Inconsolata'), 'monospace']),
38
- css=".footer {position: fixed; bottom: 0; text-align: center; width: 100%; padding: 10px; background: #f0f0f0;}"
 
 
 
39
  )
40
 
41
- # Launch the interface with professional configuration
42
  interface.launch(
43
  share=True,
44
- debug=False,
45
  server_port=7860,
46
  show_api=False,
47
  enable_queue=True,
48
- favicon_path="https://raw.githubusercontent.com/ultralytics/assets/main/logo-Ultralytics.svg"
 
49
  )
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
  from PIL import Image
4
+ import os
5
 
6
  # Load YOLO model
7
  model = YOLO("Suspicious_Activities_nano.pt")
 
9
  # Define the prediction function
10
  def predict_suspicious_activity(image):
11
  results = model.predict(source=image, show=False, conf=0.6)
12
+ results_img = results[0].plot()
13
  return Image.fromarray(results_img)
14
 
15
+ # Create a temporary directory for examples if needed
16
+ os.makedirs("examples", exist_ok=True)
17
+
18
+ # Create Gradio interface with reliable example images
19
  interface = gr.Interface(
20
  fn=predict_suspicious_activity,
21
+ inputs=gr.Image(type="pil", label="Security Camera Feed", height=380),
22
+ outputs=gr.Image(type="pil", label="Threat Analysis", height=380),
23
+ title="🛡️ AI-Powered Suspicious Activity Detection System",
24
  description="""
25
+ **Advanced security monitoring using YOLOv8 technology**
26
+ Our system detects critical security threats including:
27
+ - Unauthorized loitering in restricted zones
28
+ - Trespassing incidents captured in surveillance footage
29
+ - Vandalism and property damage activities
 
30
  - Suspicious package handling
31
+ - Physical confrontations
32
 
33
+ Upload your security footage or test with the examples below:
34
  """,
35
  examples=[
36
+ ["https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/assets/bus.jpg"],
37
+ ["https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/assets/zidane.jpg"],
38
+ ["https://ultralytics.com/images/bus.jpg"]
39
  ],
40
  cache_examples=False,
41
+ theme=gr.themes.Soft(
42
+ primary_hue="amber",
43
+ font=[gr.themes.GoogleFont('IBM Plex Sans'), 'system-ui']
44
+ ),
45
+ css=".footer {margin-top: 20px; padding: 15px; border-top: 1px solid #eee; text-align: center; color: #666;} footer {visibility: hidden}"
46
  )
47
 
48
+ # Launch with professional configuration
49
  interface.launch(
50
  share=True,
 
51
  server_port=7860,
52
  show_api=False,
53
  enable_queue=True,
54
+ favicon_path="https://raw.githubusercontent.com/ultralytics/assets/main/logo-Ultralytics.svg",
55
+ analytics_enabled=False
56
  )