File size: 1,329 Bytes
1ef0f8e
 
 
 
6076bdd
1ef0f8e
 
6076bdd
1ef0f8e
 
 
 
 
6076bdd
 
 
1ef0f8e
6076bdd
1ef0f8e
6076bdd
1ef0f8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6076bdd
1ef0f8e
 
 
6076bdd
 
1ef0f8e
6076bdd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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()