Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,43 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os, sys
|
3 |
+
import cv2
|
4 |
+
|
5 |
+
# Ensure services is importable
|
6 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
|
7 |
+
|
8 |
+
from video_service import get_video_frame
|
9 |
+
from detection_service import detect_objects
|
10 |
+
from thermal_service import detect_thermal_anomalies
|
11 |
+
from shadow_detection import detect_shadow_coverage
|
12 |
+
from salesforce_dispatcher import send_to_salesforce
|
13 |
+
|
14 |
+
frame_generator = get_video_frame("data/sample_pole_video.mp4")
|
15 |
+
|
16 |
+
def detect_frame():
|
17 |
+
try:
|
18 |
+
frame = next(frame_generator)
|
19 |
+
temp_path = "temp.jpg"
|
20 |
+
cv2.imwrite(temp_path, frame)
|
21 |
+
|
22 |
+
objects = detect_objects(temp_path)
|
23 |
+
thermal = detect_thermal_anomalies(temp_path)
|
24 |
+
shadow = detect_shadow_coverage(temp_path)
|
25 |
+
|
26 |
+
alert = {
|
27 |
+
"detections": objects,
|
28 |
+
"thermal": bool(thermal),
|
29 |
+
"shadow_issue": shadow,
|
30 |
+
}
|
31 |
+
|
32 |
+
send_to_salesforce(alert)
|
33 |
+
return frame
|
34 |
+
except StopIteration:
|
35 |
+
return None
|
36 |
+
|
37 |
+
gr.Interface(
|
38 |
+
fn=detect_frame,
|
39 |
+
inputs=[],
|
40 |
+
outputs="image",
|
41 |
+
live=True,
|
42 |
+
title="VIEP Smart Pole Live Fault Detection"
|
43 |
+
).launch()
|