| import cv2 |
| import gradio as gr |
| from PIL import Image |
|
|
| |
| 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." |
|
|
| |
| frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
| return Image.fromarray(frame_rgb) |
|
|
| |
| 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() |
|
|