Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os, sys
|
3 |
import cv2
|
|
|
|
|
4 |
|
5 |
-
# Add
|
6 |
sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
|
7 |
|
8 |
-
from video_service import
|
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 |
-
#
|
15 |
-
|
16 |
-
frame_gen = get_live_frame(cap)
|
17 |
|
18 |
-
def
|
19 |
try:
|
20 |
-
frame = next(
|
|
|
|
|
|
|
|
|
21 |
temp_path = "temp.jpg"
|
22 |
cv2.imwrite(temp_path, frame)
|
23 |
|
24 |
-
|
|
|
25 |
thermal = detect_thermal_anomalies(temp_path)
|
26 |
shadow = detect_shadow_coverage(temp_path)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
send_to_salesforce(alert)
|
35 |
return frame
|
36 |
except StopIteration:
|
37 |
return None
|
38 |
|
39 |
gr.Interface(
|
40 |
-
fn=
|
41 |
inputs=[],
|
42 |
outputs="image",
|
43 |
-
|
44 |
-
|
45 |
-
description="Live AI detection of faults like overheating, intrusion, and shadow coverage."
|
46 |
).launch()
|
47 |
-
|
|
|
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()
|
|