Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
-
import
|
| 4 |
-
import
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 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(
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 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=
|
| 51 |
inputs=[],
|
| 52 |
outputs="image",
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
)
|
|
|
|
|
|
| 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()
|