SuriRaja commited on
Commit
2ec4d04
·
1 Parent(s): 682cff4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -28
app.py CHANGED
@@ -1,30 +1,24 @@
1
- import gradio as gr
2
- import cv2
3
-
4
- # ✅ Import all services before calling anything
5
- from services.video_service import get_video_frame
6
- from services.detection_service import detect_objects
7
- from services.thermal_service import detect_thermal_anomalies
8
- from services.shadow_detection import detect_shadow_coverage
9
- from services.salesforce_dispatcher import send_to_salesforce
10
-
11
- # ✅ Initialize frame generator only after imports
12
- frame_gen = get_video_frame("data/drone_day.mp4")
13
 
14
  def monitor_feed():
15
  global frame_gen
16
  try:
17
  frame = next(frame_gen)
18
  except StopIteration:
19
- # Auto-reload video when it ends
20
  frame_gen = get_video_frame("data/drone_day.mp4")
21
  frame = next(frame_gen)
22
 
23
- cv2.imwrite("temp.jpg", frame)
 
24
 
25
- detections = detect_objects("temp.jpg")
26
- thermal = detect_thermal_anomalies("temp.jpg")
27
- shadow_flag = detect_shadow_coverage("temp.jpg")
 
 
 
 
28
 
29
  alert_payload = {
30
  "detections": detections,
@@ -32,15 +26,5 @@ def monitor_feed():
32
  "shadow_issue": shadow_flag,
33
  }
34
  send_to_salesforce(alert_payload)
35
- return frame
36
-
37
- # ✅ Setup Gradio interface
38
- iface = gr.Interface(
39
- fn=monitor_feed,
40
- inputs=[],
41
- outputs="image",
42
- live=True,
43
- title="Solar Surveillance Feed Simulation"
44
- )
45
 
46
- iface.launch()
 
1
+ import os
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def monitor_feed():
4
  global frame_gen
5
  try:
6
  frame = next(frame_gen)
7
  except StopIteration:
8
+ # Auto-restart video when finished
9
  frame_gen = get_video_frame("data/drone_day.mp4")
10
  frame = next(frame_gen)
11
 
12
+ temp_path = "temp.jpg"
13
+ cv2.imwrite(temp_path, frame)
14
 
15
+ if not os.path.exists(temp_path):
16
+ raise FileNotFoundError("Temp image not created!")
17
+
18
+ # 🛠️ Correct: pass temp_path (string) to detector
19
+ detections = detect_objects(temp_path)
20
+ thermal = detect_thermal_anomalies(temp_path)
21
+ shadow_flag = detect_shadow_coverage(temp_path)
22
 
23
  alert_payload = {
24
  "detections": detections,
 
26
  "shadow_issue": shadow_flag,
27
  }
28
  send_to_salesforce(alert_payload)
 
 
 
 
 
 
 
 
 
 
29
 
30
+ return frame # OpenCV frame still returned for Gradio