SuriRaja commited on
Commit
aa7c278
Β·
1 Parent(s): 36be4c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -1,39 +1,68 @@
 
 
1
  import gradio as gr
2
  import cv2
 
3
  from services.video_service import get_video_frame
4
  from services.detection_service import detect_objects
5
  from services.thermal_service import detect_thermal_anomalies
6
  from services.shadow_detection import detect_shadow_coverage
7
  from services.salesforce_dispatcher import send_to_salesforce
8
- from services.thermal_service import overlay_thermal_boxes
9
 
 
10
  frame_gen = get_video_frame("data/drone_day.mp4")
11
 
 
 
 
12
  def monitor_feed():
13
  try:
14
  frame = next(frame_gen)
15
- temp_path = "temp.jpg"
 
 
16
  cv2.imwrite(temp_path, frame)
17
 
 
18
  detections = detect_objects(temp_path)
 
 
19
  thermal_boxes = detect_thermal_anomalies(temp_path)
 
 
20
  shadow_flag = detect_shadow_coverage(temp_path)
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  alert_payload = {
23
  "detections": detections,
24
  "thermal": bool(thermal_boxes),
25
  "shadow_issue": shadow_flag,
26
  }
27
 
28
- # 🚨🚨🚨 ATTENTION! 🚨🚨🚨
29
- # πŸ”₯ THE BELOW LINE SHOULD BE RE-ENABLED AFTER CONFIGURING SALESFORCE URL PROPERLY πŸ”₯
30
  # send_to_salesforce(alert_payload)
 
31
 
32
- frame = overlay_thermal_boxes(temp_path, thermal_boxes)
33
  return frame
 
34
  except StopIteration:
35
  return None
36
 
 
37
  iface = gr.Interface(
38
  fn=monitor_feed,
39
  inputs=[],
@@ -41,4 +70,5 @@ iface = gr.Interface(
41
  live=True,
42
  title="Solar Surveillance Feed Simulation"
43
  )
 
44
  iface.launch()
 
1
+ # app.py
2
+
3
  import gradio as gr
4
  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
+ # Load video generator
13
  frame_gen = get_video_frame("data/drone_day.mp4")
14
 
15
+ # Ensure temp directory exists
16
+ os.makedirs("temp", exist_ok=True)
17
+
18
  def monitor_feed():
19
  try:
20
  frame = next(frame_gen)
21
+
22
+ # Save frame as temporary image
23
+ temp_path = "temp/temp_frame.jpg"
24
  cv2.imwrite(temp_path, frame)
25
 
26
+ # Object Detection
27
  detections = detect_objects(temp_path)
28
+
29
+ # Thermal Detection
30
  thermal_boxes = detect_thermal_anomalies(temp_path)
31
+
32
+ # Shadow Detection
33
  shadow_flag = detect_shadow_coverage(temp_path)
34
 
35
+ # Draw bounding boxes for visualization
36
+ for d in detections:
37
+ box = d['box']
38
+ label = d['label']
39
+ score = d['score']
40
+ x0, y0, x1, y1 = int(box['xmin']), int(box['ymin']), int(box['xmax']), int(box['ymax'])
41
+ cv2.rectangle(frame, (x0, y0), (x1, y1), (0, 255, 0), 2)
42
+ cv2.putText(frame, f"{label} {score:.2f}", (x0, y0-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
43
+
44
+ for box in thermal_boxes:
45
+ x0, y0, x1, y1 = int(box['xmin']), int(box['ymin']), int(box['xmax']), int(box['ymax'])
46
+ cv2.rectangle(frame, (x0, y0), (x1, y1), (0, 0, 255), 2)
47
+ cv2.putText(frame, "Thermal", (x0, y1+20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
48
+
49
+ # Prepare payload to send
50
  alert_payload = {
51
  "detections": detections,
52
  "thermal": bool(thermal_boxes),
53
  "shadow_issue": shadow_flag,
54
  }
55
 
56
+ # πŸ”₯ IMPORTANT: SALESFORCE API IS DISABLED FOR NOW
 
57
  # send_to_salesforce(alert_payload)
58
+ # ⚠️ TODO: Update SALESFORCE_WEBHOOK_URL in salesforce_dispatcher.py
59
 
 
60
  return frame
61
+
62
  except StopIteration:
63
  return None
64
 
65
+ # Build Gradio UI
66
  iface = gr.Interface(
67
  fn=monitor_feed,
68
  inputs=[],
 
70
  live=True,
71
  title="Solar Surveillance Feed Simulation"
72
  )
73
+
74
  iface.launch()