Sanjayraju30's picture
Update app.py
a070fb2 verified
raw
history blame
1.46 kB
import gradio as gr
import cv2
import os
import sys
# Add services path
sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
from video_service import get_video_frame
from detection_service import detect_objects
from thermal_service import detect_thermal_anomalies
from shadow_detection import detect_shadow_coverage
from salesforce_dispatcher import send_to_salesforce
# Initialize video reader from sample video
frame_generator = get_video_frame("data/sample_pole_video.mp4")
def detect_faults():
try:
frame = next(frame_generator)
if frame is None:
return None # Gradio will skip frame
# Save temporary frame
temp_path = "temp.jpg"
cv2.imwrite(temp_path, frame)
# Fault detection
intrusion = detect_objects(temp_path)
thermal = detect_thermal_anomalies(temp_path)
shadow = detect_shadow_coverage(temp_path)
# Print for debugging
print("Intrusion:", intrusion)
print("Thermal:", thermal)
print("Shadow:", shadow)
# Send to Salesforce mock
send_to_salesforce({
"detections": intrusion,
"thermal": thermal,
"shadow_issue": shadow
})
return frame
except StopIteration:
return None
gr.Interface(
fn=detect_faults,
inputs=[],
outputs="image",
title="VIEP Live Fault Detection (Simulated)",
live=True
).launch()