Update app.py
Browse files
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 |
-
#
|
| 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 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|