File size: 805 Bytes
0363a0f
81c1b0b
0363a0f
 
81c1b0b
 
0363a0f
81c1b0b
 
0363a0f
81c1b0b
 
0363a0f
 
81c1b0b
0363a0f
81c1b0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import gradio as gr
from PIL import Image

# Your public RTSP camera URL
RTSP_URL = "rtsp://Nani@471:Nani@471@49.43.217.124:554/stream1"

def get_snapshot():
    cap = cv2.VideoCapture(RTSP_URL)

    if not cap.isOpened():
        return "❌ Could not connect to RTSP stream."

    ret, frame = cap.read()
    cap.release()

    if not ret:
        return "⚠️ Failed to retrieve frame."

    # Convert BGR to RGB and return as PIL Image
    frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    return Image.fromarray(frame_rgb)

# Gradio UI
app = gr.Interface(
    fn=get_snapshot,
    inputs=[],
    outputs=gr.Image(type="pil"),
    live=False,
    title="📸 RTSP Camera Snapshot Viewer",
    description="Click below to fetch the latest frame from the RTSP camera."
)

app.launch()