SkyGuardAI commited on
Commit
78de67a
·
verified ·
1 Parent(s): 5354aa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -102
app.py CHANGED
@@ -10,12 +10,9 @@ from huggingface_hub import hf_hub_download
10
  import warnings
11
  warnings.filterwarnings('ignore')
12
 
13
- # ============================================
14
- # 1. LOAD MODELS
15
- # ============================================
16
- print("Loading YOLOv11 model from Hugging Face Hub...")
17
  model_path = hf_hub_download(
18
- repo_id="SkyGuardAI/drone-detection-yolov11",
19
  filename="best.pt"
20
  )
21
  model = YOLO(model_path)
@@ -30,9 +27,6 @@ blip_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image
30
  blip_model.eval()
31
  print("BLIP model loaded successfully.")
32
 
33
- # ============================================
34
- # 2. HEATMAP FUNCTIONS
35
- # ============================================
36
  layer_outputs = {}
37
 
38
  def hook_fn(module, input, output):
@@ -90,9 +84,6 @@ def generate_heatmap(model, image):
90
  print(f"Heatmap error: {e}")
91
  return None
92
 
93
- # ============================================
94
- # 3. DYNAMIC CAPTION (BLIP)
95
- # ============================================
96
  def generate_dynamic_caption(image):
97
  try:
98
  if isinstance(image, np.ndarray):
@@ -118,7 +109,6 @@ def generate_dynamic_caption(image):
118
  # 4. XAI REPORT (ENGLISH)
119
  # ============================================
120
  def build_xai_report(is_drone, confidence, drone_count, processing_time, image_caption):
121
- confidence_percent = confidence * 100
122
  if is_drone:
123
  drone_text = "a drone" if drone_count == 1 else f"{drone_count} drones"
124
  if confidence >= 0.8:
@@ -259,94 +249,19 @@ def drone_detection_pipeline(input_image):
259
  return blank, blank, error_msg
260
 
261
  # ============================================
262
- # 6. SKYGUARD PROFESSIONAL INTERFACE
263
- # Dark blue theme | White & Yellow text | No emojis
264
  # ============================================
265
-
266
- custom_css = """
267
- /* Main background - dark blue gradient */
268
- .gradio-container {
269
- background: linear-gradient(135deg, #0a1928 0%, #0d2a3e 100%) !important;
270
- font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
271
- }
272
- /* Headings and text */
273
- h1, h2, h3, .gr-markdown h1, .gr-markdown h2, .gr-markdown h3 {
274
- color: #ffffff !important;
275
- font-weight: 500 !important;
276
- }
277
- p, label, .gr-form, .gr-box, .gr-markdown p {
278
- color: #f0f0f0 !important;
279
- }
280
- /* Accent text (yellow) */
281
- .accent-text, .gr-markdown strong {
282
- color: #ffd966 !important;
283
- }
284
- /* Buttons - primary */
285
- .gr-button-primary {
286
- background: linear-gradient(90deg, #1e5a8a, #2c7ab1) !important;
287
- border: none !important;
288
- color: white !important;
289
- font-weight: 600 !important;
290
- border-radius: 8px !important;
291
- padding: 12px 28px !important;
292
- font-size: 1rem !important;
293
- transition: all 0.2s ease !important;
294
- box-shadow: 0 2px 5px rgba(0,0,0,0.2);
295
- }
296
- .gr-button-primary:hover {
297
- transform: translateY(-2px);
298
- background: linear-gradient(90deg, #2c7ab1, #3a8fc5) !important;
299
- box-shadow: 0 5px 15px rgba(0, 120, 200, 0.3);
300
- }
301
- /* Tabs styling */
302
- .gr-tabs .tab-nav button {
303
- background-color: #0f2b3a !important;
304
- color: #c0d0e0 !important;
305
- border-radius: 8px 8px 0 0 !important;
306
- font-weight: 500 !important;
307
- padding: 10px 20px !important;
308
- margin-right: 4px !important;
309
- }
310
- .gr-tabs .tab-nav button.selected {
311
- background-color: #1e5a8a !important;
312
- color: #ffd966 !important;
313
- border-bottom: 2px solid #ffd966 !important;
314
- }
315
- /* Input and output areas */
316
- .gr-box, .gr-form, .gr-input, .gr-panel {
317
- background-color: #0f2b3a !important;
318
- border: 1px solid #2c7ab1 !important;
319
- border-radius: 12px !important;
320
- }
321
- /* Image containers */
322
- .gr-image {
323
- background-color: #0a1928 !important;
324
- border-radius: 8px;
325
- }
326
- /* Footer */
327
- .footer {
328
- text-align: center;
329
- margin-top: 25px;
330
- font-size: 12px;
331
- color: #8aaec0 !important;
332
- border-top: 1px solid #2c7ab1;
333
- padding-top: 15px;
334
- }
335
- """
336
-
337
- with gr.Blocks(title="SkyGuard - Drone Detection System", theme=gr.themes.Soft(), css=custom_css) as demo:
338
- gr.Markdown(
339
- """
340
- <div style="text-align: center; padding: 1rem 0 0.5rem 0;">
341
- <h1 style="font-weight: 700; letter-spacing: -0.5px; margin-bottom: 0.2rem; color: #ffffff;">SKYGUARD</h1>
342
- <p style="font-size: 1.1rem; color: #ffd966;">Advanced Drone Detection with Explainable AI</p>
343
- <p style="font-size: 0.9rem; color: #c0d0e0;">YOLOv11 | XAI Heatmap | BLIP Captioning</p>
344
  </div>
345
- """
346
- )
347
 
348
- with gr.Row(equal_height=False):
349
- with gr.Column(scale=1, min_width=320):
350
  input_image = gr.Image(label="Upload Image", type="pil")
351
  analyze_btn = gr.Button("Analyze", variant="primary")
352
  with gr.Column(scale=2):
@@ -364,13 +279,11 @@ with gr.Blocks(title="SkyGuard - Drone Detection System", theme=gr.themes.Soft()
364
  outputs=[output_image, heatmap_image, report_text]
365
  )
366
 
367
- gr.Markdown(
368
- """
369
- <div class="footer">
370
  SkyGuard System | Powered by YOLOv11, Gradio, Hugging Face Spaces
371
  </div>
372
- """
373
- )
374
 
375
  # ============================================
376
  # 7. RUN APP
 
10
  import warnings
11
  warnings.filterwarnings('ignore')
12
 
13
+ print("Loading YOLOv11 model from Hugging Face Hub...")ا
 
 
 
14
  model_path = hf_hub_download(
15
+ repo_id="SkyGuardAI/drone-detection-yolov11",
16
  filename="best.pt"
17
  )
18
  model = YOLO(model_path)
 
27
  blip_model.eval()
28
  print("BLIP model loaded successfully.")
29
 
 
 
 
30
  layer_outputs = {}
31
 
32
  def hook_fn(module, input, output):
 
84
  print(f"Heatmap error: {e}")
85
  return None
86
 
 
 
 
87
  def generate_dynamic_caption(image):
88
  try:
89
  if isinstance(image, np.ndarray):
 
109
  # 4. XAI REPORT (ENGLISH)
110
  # ============================================
111
  def build_xai_report(is_drone, confidence, drone_count, processing_time, image_caption):
 
112
  if is_drone:
113
  drone_text = "a drone" if drone_count == 1 else f"{drone_count} drones"
114
  if confidence >= 0.8:
 
249
  return blank, blank, error_msg
250
 
251
  # ============================================
252
+ # 6. INTERFACE - MODIFIED: centering title and ensuring tabs visibility
 
253
  # ============================================
254
+ with gr.Blocks(title="SkyGuard - Drone Detection System", theme=gr.themes.Soft()) as demo:
255
+ gr.HTML("""
256
+ <div style="text-align: center; margin-bottom: 20px;">
257
+ <h1 style="color: #1e3a8a; font-weight: 700;">SKYGUARD</h1>
258
+ <p style="color: #facc15; font-size: 1.2rem;">Advanced Drone Detection with Explainable AI</p>
259
+ <p style="color: #4b5563;">YOLOv11 | XAI Heatmap | BLIP Captioning</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  </div>
261
+ """)
 
262
 
263
+ with gr.Row():
264
+ with gr.Column(scale=1):
265
  input_image = gr.Image(label="Upload Image", type="pil")
266
  analyze_btn = gr.Button("Analyze", variant="primary")
267
  with gr.Column(scale=2):
 
279
  outputs=[output_image, heatmap_image, report_text]
280
  )
281
 
282
+ gr.HTML("""
283
+ <div style="text-align: center; margin-top: 30px; font-size: 12px; color: #6c757d; border-top: 1px solid #dee2e6; padding-top: 15px;">
 
284
  SkyGuard System | Powered by YOLOv11, Gradio, Hugging Face Spaces
285
  </div>
286
+ """)
 
287
 
288
  # ============================================
289
  # 7. RUN APP