SuriRaja commited on
Commit
2483ba3
·
1 Parent(s): c2dcaee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -33
app.py CHANGED
@@ -5,11 +5,10 @@ import cv2
5
  import os
6
  from services.video_service import get_video_frame
7
  from services.detection_service import detect_objects
8
- from services.thermal_service import detect_thermal_anomalies
9
  from services.shadow_detection import detect_shadow_coverage
10
  from services.salesforce_dispatcher import send_to_salesforce
11
 
12
- # Global frame generator
13
  frame_gen = get_video_frame("data/drone_day.mp4")
14
 
15
  def monitor_feed():
@@ -19,46 +18,24 @@ def monitor_feed():
19
  cv2.imwrite(temp_path, frame)
20
 
21
  detections = detect_objects(temp_path)
22
- thermal_flags = detect_thermal_anomalies(temp_path)
23
  shadow_flag = detect_shadow_coverage(temp_path)
24
 
25
- # Prepare alert payload
26
  alert_payload = {
27
  "detections": detections,
28
- "thermal": bool(thermal_flags),
29
  "shadow_issue": shadow_flag,
30
  }
31
  send_to_salesforce(alert_payload)
32
 
33
- # Create human-readable alert
34
- detected_classes = [d['label'] for d in detections]
35
- confidence_scores = [round(d['score'] * 100, 2) for d in detections]
36
- confidence_max = max(confidence_scores) if confidence_scores else 0
37
 
38
- alert_message = f"""
39
- 🚨 Detection Summary 🚨
40
- Detected Objects: {', '.join(detected_classes) if detected_classes else 'None'}
41
- Thermal Issue: {'Yes' if alert_payload['thermal'] else 'No'}
42
- Shadow Issue: {'Yes' if alert_payload['shadow_issue'] else 'No'}
43
- Highest Confidence: {confidence_max}%
44
- """
45
-
46
- # Return the frame and the alert
47
- return frame, alert_message.strip()
48
 
49
  except StopIteration:
50
- return None, "End of Video Feed."
51
-
52
- # 🎯 Create better Gradio Interface
53
- with gr.Blocks(title="Solar Surveillance Feed Simulation") as app:
54
- gr.Markdown("# ☀️ Solar Site Live Surveillance")
55
- gr.Markdown("### Live Drone Feed with AI Intrusion + Thermal + Shadow Monitoring")
56
-
57
- video_output = gr.Image(label="Drone Camera View", shape=(512, 512))
58
- alert_output = gr.Textbox(label="AI Generated Alerts", lines=5)
59
-
60
- live_button = gr.Button("Start Live Surveillance 🚀")
61
-
62
- live_button.click(fn=monitor_feed, outputs=[video_output, alert_output])
63
 
64
- app.queue().launch()
 
 
5
  import os
6
  from services.video_service import get_video_frame
7
  from services.detection_service import detect_objects
8
+ from services.thermal_service import detect_thermal_anomalies, overlay_thermal_boxes
9
  from services.shadow_detection import detect_shadow_coverage
10
  from services.salesforce_dispatcher import send_to_salesforce
11
 
 
12
  frame_gen = get_video_frame("data/drone_day.mp4")
13
 
14
  def monitor_feed():
 
18
  cv2.imwrite(temp_path, frame)
19
 
20
  detections = detect_objects(temp_path)
21
+ thermal_boxes = detect_thermal_anomalies(temp_path)
22
  shadow_flag = detect_shadow_coverage(temp_path)
23
 
 
24
  alert_payload = {
25
  "detections": detections,
26
+ "thermal": bool(thermal_boxes),
27
  "shadow_issue": shadow_flag,
28
  }
29
  send_to_salesforce(alert_payload)
30
 
31
+ # Overlay thermal boxes
32
+ if thermal_boxes:
33
+ frame = overlay_thermal_boxes(temp_path, thermal_boxes)
 
34
 
35
+ return frame
 
 
 
 
 
 
 
 
 
36
 
37
  except StopIteration:
38
+ return None
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ iface = gr.Interface(fn=monitor_feed, inputs=[], outputs="image", live=True, title="Solar Surveillance Feed Simulation")
41
+ iface.launch()