Sanjayraju30 commited on
Commit
4ca8f20
·
verified ·
1 Parent(s): 826d892

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -44
app.py CHANGED
@@ -1,55 +1,34 @@
1
  import gradio as gr
2
  import cv2
3
- import os
4
- import sys
 
 
5
 
6
- # Add services path
7
- sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
8
 
9
- from video_service import get_video_frame
10
- from detection_service import detect_objects
11
- from thermal_service import detect_thermal_anomalies
12
- from shadow_detection import detect_shadow_coverage
13
- from salesforce_dispatcher import send_to_salesforce
14
-
15
- # Initialize video reader from sample video
16
- frame_generator = get_video_frame("data/sample_pole_video.mp4")
17
-
18
- def detect_faults():
19
  try:
20
- frame = next(frame_generator)
21
- if frame is None:
22
- return None # Gradio will skip frame
23
-
24
- # Save temporary frame
25
- temp_path = "temp.jpg"
26
- cv2.imwrite(temp_path, frame)
27
-
28
- # Fault detection
29
- intrusion = detect_objects(temp_path)
30
- thermal = detect_thermal_anomalies(temp_path)
31
- shadow = detect_shadow_coverage(temp_path)
32
-
33
- # Print for debugging
34
- print("Intrusion:", intrusion)
35
- print("Thermal:", thermal)
36
- print("Shadow:", shadow)
37
-
38
- # Send to Salesforce mock
39
- send_to_salesforce({
40
- "detections": intrusion,
41
- "thermal": thermal,
42
- "shadow_issue": shadow
43
- })
44
-
45
  return frame
46
  except StopIteration:
47
  return None
48
 
49
- gr.Interface(
50
- fn=detect_faults,
51
  inputs=[],
52
  outputs="image",
53
- title="VIEP Live Fault Detection (Simulated)",
54
- live=True
55
- ).launch()
 
 
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.fault_service import detect_pole_faults
6
+ from services.salesforce_dispatcher import send_to_salesforce
7
 
8
+ # Initialize video feed
9
+ frame_gen = get_video_frame("data/pole_feed.mp4")
10
 
11
+ def monitor_feed():
 
 
 
 
 
 
 
 
 
12
  try:
13
+ frame = next(frame_gen)
14
+ cv2.imwrite("temp.jpg", frame)
15
+ detections = detect_objects("temp.jpg")
16
+ faults = detect_pole_faults("temp.jpg")
17
+ alert_payload = {
18
+ "detections": detections,
19
+ "faults": bool(faults),
20
+ "fault_details": faults
21
+ }
22
+ send_to_salesforce(alert_payload)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  return frame
24
  except StopIteration:
25
  return None
26
 
27
+ iface = gr.Interface(
28
+ fn=monitor_feed,
29
  inputs=[],
30
  outputs="image",
31
+ live=True,
32
+ title="Pole Fault Detection Feed Simulation"
33
+ )
34
+ iface.launch()