Sanjayraju30's picture
Update app.py
6076bdd verified
raw
history blame
1.33 kB
import gradio as gr
import os, sys
import cv2
# Add 'services' folder to Python path
sys.path.append(os.path.join(os.path.dirname(__file__), "services"))
from video_service import get_live_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
# πŸ” Live stream: Use webcam (0) or RTSP stream
cap = cv2.VideoCapture(0) # Replace 0 with RTSP URL if needed
frame_gen = get_live_frame(cap)
def detect_live_faults():
try:
frame = next(frame_gen)
temp_path = "temp.jpg"
cv2.imwrite(temp_path, frame)
objects = detect_objects(temp_path)
thermal = detect_thermal_anomalies(temp_path)
shadow = detect_shadow_coverage(temp_path)
alert = {
"detections": objects,
"thermal": bool(thermal),
"shadow_issue": shadow,
}
send_to_salesforce(alert)
return frame
except StopIteration:
return None
gr.Interface(
fn=detect_live_faults,
inputs=[],
outputs="image",
live=True,
title="πŸ“‘ VIEP Live Smart Pole Fault Detection",
description="Live AI detection of faults like overheating, intrusion, and shadow coverage."
).launch()