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
-
chore(deploy): only install CLIP when building yolo-world
CLIP is dead weight for the default yolov8 build path — the COCO classes are baked into the YOLOv8 checkpoint at training time, no text-encoder branch involved. Move the dep out of requirements.txt and only resolve it inside the Dockerfile's yoloworld bake case, so the production yolov8 image ships ~50 MB lighter and skips a CDN git clone at build time.d6d0769 -
feat(model): default to standard YOLOv8 backbone for CPU production
Local benchmark on M2 + ONNX Runtime CoreML, single-frame inference: YOLO-World M (worldv2, 180M params, vision + text branch) → 13.7 fps, 73 ms / frame YOLOv8 M (standard, 26M params, vision-only) → 56.6 fps, 18 ms / frame ───────── 4.1× speedup on the same hardware, same imgsz → projection on EPYC 4 cores: ~15-20 fps (was 0.6 fps with YOLO-World M, fundamentally too heavy) YOLO-World shines for zero-shot detection of arbitrary text-prompted classes, but the dual-branch vision-language fusion is a CPU non-starter: even with static-class export the text encoder branch keeps contributing residual compute every frame. Standard YOLOv8 with its fixed 80 COCO classes covers everything traffic monitoring needs (car / truck / bus / motorcycle / bicycle / person), so unless the fleet specifically demands the YOLO-World classes (becak / bemo / bajaj / angkot / ojek as distinct labels), the speed is the better trade.…5b1b3f2 -
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(deploy): ship .env.vps and .env.hfspace inside the image
The deploy log showed `profile=vps | inference=960px max_streams=50` even though .env.vps sets 768 / 4 — the Dockerfile only copied app/, scripts/, docs/, and run.sh, so the profile overlay files were absent inside the container. The loader fell through to hard-coded defaults silently, with no warning at the surface. Copy both committed profile overlays at the same layer as the rest of the source. Container can now flip behaviour through CAKRA_PROFILE alone, no env-file gymnastics required.29909d6 -
ci(deploy): build + ship cakra-yolo to the cakra-network VM
Mirrors the location-propability pipeline: build the image, push to GHCR, SSH into the production VM, replace the running container via straight `docker run`. No compose file — the box only needs one container per service so the extra layer earns nothing here. Pipeline: 1. `docker/build-push-action` builds with cache scoped to gha, bakes YOLO-World M weights + ONNX export at build time (via the Dockerfile's YOLO_BUILD_SIZE and YOLO_EXPORT_IMGSZ ARGs). 2. `appleboy/ssh-action` pulls the image on the VM, writes the YOLO_ENV_FILE secret to /opt/cakra/yolo/.env, then replaces the container. 3. Container joins the external `cakra-network` overlay shared with the platform's NestJS api and React web, so the API reaches this service at http://cakra-yolo:7860 with no public port exposed. 4. `--cpus 4` caps inference at 4 cores on an 8-core EPYC, leaving headroom for the API + ffmpeg encoders sharing the box. 5. Healthcheck via `docker exec` (no host…725b40f -
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 -
fix(deploy): unblock Dockerfile build + slim image for HF CPU spaces
- Add `git` to apt deps so pip can install `clip` from its git URL. YOLO-World's `model.set_classes(...)` lazy-imports CLIP at runtime and Ultralytics' auto-installer relies on git+pip; without git in the image the build crashed inside `scripts.setup_yolo_world` with ModuleNotFoundError: No module named 'clip'. - Pin clip in requirements.txt so the dependency is explicit + the resolver doesn't try the auto-install path at runtime. - Install CPU-only torch/torchvision wheels from https://download.pytorch.org/whl/cpu before the rest of pip requirements. The default PyPI torch bundles CUDA (~700 MB) which a CPU Hugging Face space can't use; this cuts ~700 MB off the final image. Subsequent `pip install -r requirements.txt` sees torch>=2.2 already satisfied and skips reinstall. - Drop unused deps: aiortc (WebRTC was removed), ffmpeg-python (we spawn ffmpeg via subprocess), pandas (never imported), httpx (removed with the HLS proxy).f1803be -
fix(conflict): readme conflict
8653aff
-
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
-
initial commit
Verified signatureaaf1d0c