SuriRaja commited on
Commit
b5e153c
·
1 Parent(s): 7269934

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -33
app.py CHANGED
@@ -2,67 +2,49 @@
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=[],
 
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=[],