SuriRaja commited on
Commit
d7c0a63
·
1 Parent(s): d902917

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -31
app.py CHANGED
@@ -1,56 +1,61 @@
1
- # app.py
2
 
3
  import gradio as gr
4
  import cv2
5
  import random
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
- # List of videos to cycle or pick randomly
13
- VIDEO_LIST = [
14
- "data/drone_day.mp4",
15
- "data/thermal_hotspot.mp4",
16
- "data/shadow_dust_issue.mp4",
17
- "data/alert_response.mp4",
18
- ]
19
-
20
- # Pick a random video at app startup
21
- selected_video = random.choice(VIDEO_LIST)
22
- frame_gen = get_video_frame(selected_video)
23
 
24
  def monitor_feed():
25
  try:
26
  frame = next(frame_gen)
27
- if frame is None:
28
- return None
29
  temp_path = "temp.jpg"
30
  cv2.imwrite(temp_path, frame)
31
 
32
  detections = detect_objects(temp_path)
33
  thermal_boxes = detect_thermal_anomalies(temp_path)
34
- shadow_flag = detect_shadow_coverage(temp_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- alert_payload = {
37
- "detections": detections,
38
- "thermal": bool(thermal_boxes),
39
- "shadow_issue": shadow_flag,
40
- }
41
-
42
- send_to_salesforce(alert_payload)
43
  return frame
44
 
45
  except StopIteration:
46
  return None
47
 
48
- iface = gr.Interface(
49
- fn=monitor_feed,
50
- inputs=[],
51
- outputs="image",
52
- live=True,
53
- title="Solar Surveillance Feed Simulation"
54
- )
55
-
56
  iface.launch()
 
1
+ ### Updated app.py
2
 
3
  import gradio as gr
4
  import cv2
5
  import random
6
+ from services.video_service import get_random_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
+ # Initialize frame generator
13
+ frame_gen = get_random_video_frame()
 
 
 
 
 
 
 
 
 
14
 
15
  def monitor_feed():
16
  try:
17
  frame = next(frame_gen)
18
+
 
19
  temp_path = "temp.jpg"
20
  cv2.imwrite(temp_path, frame)
21
 
22
  detections = detect_objects(temp_path)
23
  thermal_boxes = detect_thermal_anomalies(temp_path)
24
+ shadow_issue = detect_shadow_coverage(temp_path)
25
+
26
+ # Draw detections
27
+ for det in detections:
28
+ box = det['box']
29
+ cv2.rectangle(frame, (int(box['xmin']), int(box['ymin'])), (int(box['xmax']), int(box['ymax'])), (0, 255, 0), 2)
30
+
31
+ # Draw thermal anomalies
32
+ for box in thermal_boxes:
33
+ cv2.rectangle(frame, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), (0, 0, 255), 2)
34
+
35
+ # Overlay text based on detections
36
+ overlay_text = []
37
+ if any(d['label'] == 'person' for d in detections):
38
+ overlay_text.append("Intrusion Detected")
39
+ if thermal_boxes:
40
+ overlay_text.append("Thermal Anomaly")
41
+ if shadow_issue:
42
+ overlay_text.append("Shadow Coverage Issue")
43
+
44
+ for idx, text in enumerate(overlay_text):
45
+ cv2.putText(frame, text, (10, 30 + idx * 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
46
+
47
+ # 🚨 Commented out Salesforce integration for now
48
+ # alert_payload = {
49
+ # "detections": detections,
50
+ # "thermal": bool(thermal_boxes),
51
+ # "shadow_issue": shadow_issue,
52
+ # }
53
+ # send_to_salesforce(alert_payload)
54
 
 
 
 
 
 
 
 
55
  return frame
56
 
57
  except StopIteration:
58
  return None
59
 
60
+ iface = gr.Interface(fn=monitor_feed, inputs=[], outputs="image", live=True, title="Solar Surveillance Feed Simulation", cache_examples=False)
 
 
 
 
 
 
 
61
  iface.launch()