HazardLens
Enterprise NVR and real-time AI threat detection console pairing dual YOLOv8 models (fire/smoke + crowd surge) with decoupled native MJPEG streaming (12–15 FPS), single-port Nginx reverse proxying, Hindi Edge-TTS neural voice alerts, and Resend email dispatch.
Problem Space
Standard CCTV requires passive human monitoring, while rendering live computer-vision streams inside Streamlit's script-rerun loop causes UI dimming, WebSocket queue stalls, and frozen frames.
Production Architecture
Decouples video capture (CameraWorker), dual YOLOv8 inference (InferenceWorker), and native multipart MJPEG streaming (:8502) from Streamlit (:8503) behind a single-port Nginx reverse proxy (:8501) on Azure Container Apps.
Execution Pipeline
- STAGE 01
Zero-Buffer CameraWorker
Ingests IP webcam or Cloudflare tunnel feeds via FFmpeg nobuffer flags with automatic keep-alive /shot.jpg fallback.
- STAGE 02
Dual YOLOv8 InferenceWorker
Runs custom fire/smoke model (best.pt, conf >= 0.85) and person counter (yolov8n.pt, limit 5) asynchronously at imgsz=320.
- STAGE 03
Native MJPEG + Nginx Proxy
ThreadingHTTPServer streams ~15 FPS JPEG over /stream while Nginx unifies UI WebSockets and video under one HTTPS origin with proxy_buffering off.
- STAGE 04
1Hz Alert FSM & Hindi TTS
1Hz @st.fragment drives Edge-TTS Hindi voice alerts (hi-IN-SwaraNeural) with 3s clear-grace shutoff, 60s PIN-gated silence, and queued Resend email alerts.
Key Engineering Trade-Offs & Decisions
- Moved live video outside Streamlit reruns into a dedicated MJPEG server, achieving steady 12–15 FPS with zero DOM flicker.
- Added SSRF URL validation, operator PIN controls, and SHA-256 model integrity checks in utils/security.py.
- Replaced transitive GUI opencv-python with opencv-python-headless and CPU-only PyTorch wheels under a non-root container user.
- Verified audio loop resets, email cooldown/retries, and security guards across 59 pytest tests.
Tech Stack
Live on Azure Container Apps (2 vCPU / 4 GiB, scale-to-zero, single-port Nginx :8501) via ghcr.io/tusharsingh-sde/hazardlens:v1.
Open-source repo: PRs, issues, and feature collabs are always welcome on GitHub.