Spaces:
Runtime error
Runtime error
Commit History
-
feat(scan): right-click scan-mode alerting + per-camera pose
Scan mode runs parallel low-fps inference sessions per CCTV with no HLS overhead, triggered via right-click on the FE map. Each session owns a RuleEngine that fires on sustained_count rules and persists alerts (JPEG snapshot + H.264 MP4 clip from a ring buffer) into the shared `alerts` table with source='cctv-scan'. Backbone: - ScanSessionWorker: capture -> infer -> rules -> ring buffer - RuleEngine: sustained_count with cold-start guard + per-rule cooldown + progress_snapshot() for the FE probability bar - FrameRingBuffer: deque + JPEG snapshot + H.264 MP4 encode via ffmpeg subprocess (cv2 mp4v fallback when ffmpeg absent) - AlertsDAO: INSERT/UPDATE/query against the Prisma-owned `alerts` table - ScanEventBus: thread-safe pub/sub bridging worker threads to async WS - Registry: second worker pool (MAX_SCAN_STREAMS) sharing the detector Pose pipeline: coverage polygon + per-detection geo projection now use heading_deg / fov_deg from cctv_streams when present (falls back to GEO_* e…d6b1333
-
fix(deploy): align INFERENCE_SIZE with the baked ONNX graph
The VPS deploy crashed inside lifespan with RuntimeError: Got invalid dimensions for input: images index: 2 Got: 960 Expected: 640 because the .env.vps overlay declared INFERENCE_SIZE=768 while the Dockerfile bakes the ONNX graph at YOLO_EXPORT_IMGSZ=640. ONNX exports write a STATIC input shape into the .onnx file, so the runtime imgsz must equal the baked shape verbatim — onnxruntime cannot rescale at inference. Two changes so this can not happen silently again: 1. .env.vps sets INFERENCE_SIZE=640 and explains the constraint in a comment. To raise inference resolution, the image has to be rebuilt with --build-arg YOLO_EXPORT_IMGSZ=<N> AND the profile value updated to N. The two are now visibly coupled. 2. Detector now introspects the ONNX session's input shape at construction and raises a self-explanatory RuntimeError before warmup if the runtime imgsz disagrees with the baked one. Dynamic shapes (symbolic dims) are skipped — they tolerate any …9756463 -
fix(config): UI / shell env now beats profile overlay
Snapshot os.environ before any .env file load and skip those keys in both passes — so values set in Hugging Face Space "Variables & Secrets" UI, in docker -e flags, or in the parent shell always win over the profile file. Previously the profile overlay used a hard override and clobbered the operator's UI overrides, which made MODEL_PATH and TARGET_INFER_FPS untunable on a deployed Space. Precedence is now (highest wins): 1. shell / docker -e / HF UI 2. .env.<profile> (profile overlay) 3. .env (base config + secrets) 4. hard-coded defaults in app/config.py Also ship .env.vps as a reference profile for self-managed VPS deploys (4-8 vCPU AMD/Intel without GPU): inference=768, fps_target=8, max_streams=4, .onnx backend by default.48df398 -
feat(deploy): HF Spaces / CPU production stack
Stack the changes required to ship cakra to a CPU-only host (HF Spaces basic, generic VPS without GPU) cleanly: • app/config.py — profile loader. CAKRA_PROFILE=<name> (set in shell *or* in .env itself) loads `.env.<name>` after the base .env and overrides matching keys. The HF Spaces overlay is auto-applied when the runtime is detected via SPACE_ID, so a Space deploy needs no extra config beyond the secret list. • .env.hfspace — committed overlay tuning HF basic's shared 2 vCPU: INFERENCE_SIZE=640, TARGET_INFER_FPS=3, FRAME_SKIP=2, output 854x480, MAX_STREAMS=1, MODEL_PATH=./models/yolo-world-id.onnx. No secrets in the file — DATABASE_URL stays in .env or the Space Secrets UI. • app/main.py — boot log surfaces the active profile + the resource knobs so HF and local-simulation runs are auditable in one log line. • app/services/detector.py — dispatch backend by MODEL_PATH suffix (.pt → pytorch, .onnx → onnx, .xml → openvino, .engine…ed450db
-
feat(config): bump default coverage range to 90m
GEO_MAX_DISTANCE_M default raised from 50m to 90m. The previous value was too short — most traffic CCTVs can clearly see 80-150m down the road, so 50m undershot the visual reach on the map polygon and clamped per-detection projection at the near-horizon limit too aggressively.2d06ca6
-
fix(config): align Python defaults with local .env
14411d0 -
fix(hls): snapshot read playlist/segment to avoid Content-Length race
FileResponse stat'd then streamed the file while ffmpeg was rolling playlist.m3u8 / .ts segments concurrently, so the response body grew past the precomputed Content-Length and uvicorn raised "Response content longer than Content-Length". Read whole bytes into memory and return Response so Content-Length matches what we send.399ad59
-
perf(stream): drift-free pacer + reader pacing for true 25 fps smoothness
Three fixes layered to eliminate the "smooth → freeze → burst" cycle caused by upstream HLS segment-burst delivery: 1. Drift-free pacer scheduler The pacer now anchors every tick at an absolute monotonic target (start + N*period) with a ~2 ms busy-wait tail. time.sleep() on macOS overshoots by ~3-5 ms because the kernel timer tick is coarse, which was silently drifting the pacer to ~22.7 fps even when work was only 4 ms. Effective pacer rate is now 25.0 fps measured. 2. Reader pacing at HLS_FPS stream_reader.cap.read() was draining ffmpeg's HLS demuxer as fast as it could decode, dumping a full ~50-frame segment into the ring in ~100 ms. The ring's drop-oldest semantics then threw away ~47 % of every burst, producing temporal discontinuities visible downstream as fast-forward bursts followed by frozen frames. Pacing cap.read() at HLS_FPS lets TCP / ffmpeg backpressure smooth the source delivery; the ring now stays at length 1-2 and source fra…abc7cb8 -
feat: real-time CCTV YOLO analytics with bbox-baked HLS
Per-camera worker decoupled into four stages: - capture (StreamReader): decodes upstream HLS, tags frames with capture timestamp, pushes to a bounded ring (drop-oldest) - pace: monotonic-clock thread ticks at HLS_FPS, pops the next frame from the ring, annotates with the detection that was current at that capture time (bbox stays glued to the visible frame even with ring delay) - encode: ffmpeg in true CFR (-r N -fps_mode cfr), libx264 or videotoolbox; segments split on exact second boundaries - inference: YOLO + ByteTrack on its own thread at TARGET_INFER_FPS; never blocks the capture / pace / encode chain Detection coords scaled from source space (e.g. 1920x1080) to output space (e.g. 1280x720) before annotation. Persistent state in a single cctv_session_metrics row per camera (UPSERT each tick, started_at frozen across reconnects). Realtime WS pushes analytics + geo-tagged detections with per-camera coverage polygon. Embed-ready: any client drops <video src=playlist.m3u…40e0b51