Abs6187 commited on
Commit
dac832d
·
verified ·
1 Parent(s): 8905778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -40
app.py CHANGED
@@ -1,7 +1,6 @@
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")
@@ -12,42 +11,57 @@ def predict_suspicious_activity(image):
12
  results_img = results[0].plot()
13
  return Image.fromarray(results_img)
14
 
15
- # Create Gradio interface with reliable example images
16
- interface = gr.Interface(
17
- fn=predict_suspicious_activity,
18
- inputs=gr.Image(type="pil", label="Security Camera Feed", height=380),
19
- outputs=gr.Image(type="pil", label="Threat Analysis", height=380),
20
- title="🛡️ AI-Powered Suspicious Activity Detection System",
21
- description="""
22
- **Advanced security monitoring using YOLOv8 technology**
23
- Our system detects critical security threats including:
24
- - Unauthorized loitering in restricted zones
25
- - Trespassing incidents captured in surveillance footage
26
- - Vandalism and property damage activities
27
- - Suspicious package handling
28
- - Physical confrontations
29
-
30
- Upload your security footage or test with the examples below:
31
- """,
32
- examples=[
33
- ["https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/assets/bus.jpg"],
34
- ["https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/assets/zidane.jpg"],
35
- ["https://ultralytics.com/images/bus.jpg"]
36
- ],
37
- cache_examples=False,
38
- theme=gr.themes.Soft(
39
- primary_hue="amber",
40
- font=[gr.themes.GoogleFont('IBM Plex Sans'), 'system-ui']
41
- ),
42
- css=".footer {margin-top: 20px; padding: 15px; border-top: 1px solid #eee; text-align: center; color: #666;} footer {visibility: hidden}"
43
- )
44
-
45
- # Correct way to enable queue in newer Gradio versions
46
- # Call .queue() before .launch()
47
- interface.queue().launch(
48
- share=True,
49
- server_port=7860,
50
- show_api=False,
51
- favicon_path="https://raw.githubusercontent.com/ultralytics/assets/main/logo-Ultralytics.svg",
52
- analytics_enabled=False
53
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
 
11
  results_img = results[0].plot()
12
  return Image.fromarray(results_img)
13
 
14
+ # Custom CSS for beauty
15
+ custom_css = """
16
+ #main-card {
17
+ background: rgba(255, 255, 255, 0.08);
18
+ backdrop-filter: blur(12px);
19
+ border-radius: 20px;
20
+ box-shadow: 0 8px 25px rgba(0,0,0,0.2);
21
+ padding: 30px;
22
+ }
23
+ h1 {
24
+ font-size: 2.5rem !important;
25
+ background: linear-gradient(90deg, #ff4b1f, #1fddff);
26
+ -webkit-background-clip: text;
27
+ -webkit-text-fill-color: transparent;
28
+ text-align: center;
29
+ margin-bottom: 10px;
30
+ }
31
+ .description {
32
+ text-align: center;
33
+ font-size: 1.1rem;
34
+ margin-bottom: 25px;
35
+ color: #ddd;
36
+ }
37
+ .gr-button {
38
+ border-radius: 12px !important;
39
+ padding: 10px 20px !important;
40
+ font-weight: bold !important;
41
+ transition: all 0.3s ease-in-out;
42
+ }
43
+ .gr-button:hover {
44
+ transform: scale(1.05);
45
+ box-shadow: 0 4px 15px rgba(0,0,0,0.3);
46
+ }
47
+ """
48
+
49
+ # Build modern UI
50
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
51
+ with gr.Column(elem_id="main-card"):
52
+ gr.Markdown("<h1>🚨 Suspicious Activity Detection</h1>")
53
+ gr.Markdown("<p class='description'>Upload an image and let YOLO detect suspicious activities instantly ⚡</p>")
54
+
55
+ with gr.Row():
56
+ input_image = gr.Image(type="pil", label="Upload Image", height=350)
57
+ output_image = gr.Image(type="pil", label="Detection Result", height=350)
58
+
59
+ with gr.Row():
60
+ detect_btn = gr.Button("🔍 Detect", variant="primary")
61
+ clear_btn = gr.Button("🗑️ Clear", variant="secondary")
62
+
63
+ detect_btn.click(fn=predict_suspicious_activity, inputs=input_image, outputs=output_image)
64
+ clear_btn.click(fn=lambda: (None, None), inputs=None, outputs=[input_image, output_image])
65
+
66
+ # Launch
67
+ demo.launch(share=True)