# ════════════════════════════════════════════════════════════════════════ # cakra-intelegence-yolo — environment configuration # ════════════════════════════════════════════════════════════════════════ # # Copy to .env and edit. Anything not set here uses the hard-coded # defaults in app/config.py (always safe baseline). # # Profile overlays: # Set CAKRA_PROFILE= to load .env. on top of .env. # Profile values OVERRIDE .env (DATABASE_URL etc. stay in .env only). # Built-in profiles: # - .env.hfspace : Hugging Face Spaces free CPU tier # The profile is auto-applied when SPACE_ID env is detected (HF sets # that automatically), so a Space deploy needs zero extra config. # # Backend hint: # MODEL_PATH extension picks the runtime: .pt → PyTorch, .onnx → ONNX # Runtime, .xml → OpenVINO. Use scripts/export_onnx.py to convert # .pt → .onnx for ~3-5× CPU throughput on production deploys. # ════════════════════════════════════════════════════════════════════════ # ──── Profile (optional) ──────────────────────────────────────────────── # Leave empty for local M2 / GPU dev. Set to "hfspace" to simulate HF # Spaces' CPU constraints on your laptop, or before deploying. # CAKRA_PROFILE=hfspace # ──── Server ──────────────────────────────────────────────────────────── HOST=0.0.0.0 PORT=8000 LOG_LEVEL=INFO # ──── Camera catalog ──────────────────────────────────────────────────── # Source camera rows from Postgres `cctv_streams`. STREAMS_STATUS_FILTER # restricts to rows with this status ("online" by default). MAX_STREAMS # caps the in-process worker pool — set per deploy tier. STREAMS_STATUS_FILTER=online MAX_STREAMS=50 RECONNECT_DELAY=5.0 # ──── Database ────────────────────────────────────────────────────────── # Reads cctv_streams (catalog). UPSERTs cctv_session_metrics (one row # per camera, lifetime aggregates). NEVER put DATABASE_URL in a profile # overlay — keep secrets in .env (or the deploy platform's secret UI). DATABASE_URL=postgresql://user:pass@host:5432/dbname # ──── YOLO model ──────────────────────────────────────────────────────── # Regenerate the .pt with scripts/setup_yolo_world.py to change class # list. Default ships YOLO-World medium with 17 Indonesian-traffic # classes baked in. MODEL_PATH=./models/yolo-world-id.pt CONF_THRESHOLD=0.05 IOU_THRESHOLD=0.5 # 960 = best far-recall on GPU. 640 = ~2× throughput on CPU with # minimal close-range accuracy loss. Drop further (480) for very slow # CPUs at the cost of far-vehicle miss. INFERENCE_SIZE=960 USE_HALF=true FRAME_SKIP=1 # Cap inference rate. Lower than capture fps because YOLO can not keep # up at full source rate on CPU/MPS. Tune to your deploy tier. TARGET_INFER_FPS=8 # ──── ONNX backend (CPU production) ───────────────────────────────────── # To use ONNX Runtime instead of PyTorch: # 1. Generate the .onnx file: # .venv/bin/python -m scripts.export_onnx --imgsz 640 --half # 2. Point MODEL_PATH at the new file: # MODEL_PATH=./models/yolo-world-id.onnx # 3. Restart cakra. The Detector log line shows "backend=onnx". # Typical speedup vs PyTorch CPU: 3-5× (single-camera 9-15 fps on HF # basic). Re-export the .onnx whenever you change class list or imgsz. # ──── HUD mask (CCTV banner / timestamp strips) ───────────────────────── # Top + bottom percentages of the source frame are blanked before # inference so YOLO doesn't pick up burned-in agency overlays. HUD_MASK_TOP_PCT=0.06 HUD_MASK_BOTTOM_PCT=0.05 STALE_FRAME_SECONDS=2.0 # ──── Video output (HLS) ──────────────────────────────────────────────── # Encoded HLS resolution. 1280×720 = clear surveillance quality. # 854×480 if scaling to many cameras on a small box. OUTPUT_WIDTH=1280 OUTPUT_HEIGHT=720 # Match upstream native rate. Semarang livepantau is 25/1. HLS_FPS=25 HLS_SEGMENT_SECONDS=2.0 HLS_PLAYLIST_SIZE=6 # CRF: 20 = sharp surveillance, 23 = ffmpeg default, 18 = ~lossless. HLS_CRF=22 HLS_PRESET=veryfast # libx264 (universal CPU) | videotoolbox (macOS hw) | nvenc (NVIDIA). # Auto-fallback to libx264 if requested encoder isn't in this ffmpeg. HLS_ENCODER=libx264 HLS_OUTPUT_DIR=/tmp/cakra-hls # ──── WebSocket push cadence ──────────────────────────────────────────── METRICS_WS_INTERVAL=0.1 # ──── Geo projection (per-detection lat/lng for map overlay) ──────────── # cctv_streams only carries lat/lng. Defaults below are applied to # every camera; extend the catalog table to override per-camera. # Tune for your CCTV fleet: # - Urban highway pole (Sudirman style): height=6, tilt=22, fov=80 # - Standard street CCTV mast (default): height=4, tilt=15, fov=70 # - Residential alley pole: height=3, tilt=10, fov=90 GEO_DEFAULT_HEADING_DEG=0 GEO_FOV_DEG=70 GEO_V_FOV_DEG=40 GEO_MAX_DISTANCE_M=90 GEO_CAMERA_HEIGHT_M=4 GEO_CAMERA_TILT_DEG=15 # ──── Scan mode (alerting) ────────────────────────────────────────────── # Triggered from the FE map by right-clicking a CCTV marker. Each scan # session runs in parallel with preview, but at much lower fps and with # no HLS encoding — the cost is dominated by inference, which is # serialised on the shared Detector. Sessions can be set to fire on: # - Kemacetan : sustained vehicle count above threshold # - Keramaian : sustained person count above threshold # Each fire writes a JPEG snapshot + MP4 clip (from ring buffer) under # ALERTS_DIR and pushes an event to WS /scan/events. MAX_SCAN_STREAMS=12 SCAN_TARGET_FPS=1.0 SCAN_RING_BUFFER_SECONDS=30 SCAN_OUTPUT_WIDTH=640 SCAN_OUTPUT_HEIGHT=360 ALERTS_DIR=./data/alerts # ──── Scan rule presets ───────────────────────────────────────────────── # Threshold + window + cooldown for the two production rules. Applied to # every session that starts with an empty body (the default FE flow via # right-click "Mulai scan"). Tunables: # - Threshold: minimum object count before "congested/crowded" triggers # - Sustained: seconds the threshold must hold before firing. Filters # momentary spikes (one busy frame won't fire unless it # holds for the sustained window). # - Cooldown: pause between fires in ONE session. Caps noise from a # single session; does NOT throttle parallel sessions. # Multi-session throttling lives in the FE (5 min per # [camera, rule]). # # Note: preset keys remain Indonesian ("kemacetan"/"keramaian") because # they're user-facing slugs the FE references; env knobs are English # (TRAFFIC_JAM = kemacetan = vehicle count; CROWD = keramaian = person). # Traffic jam — vehicle sustained count. Default 50 vehicles held for 60 # seconds, 5-minute pause between fires per session. Tuned for arterial # roads / large intersections where light traffic is already 10-20 # vehicles per frame — 50 picks up genuine congestion, not normal flow. # Drop to 25-30 for narrow streets where 50 will rarely trigger. SCAN_TRAFFIC_JAM_THRESHOLD=50 SCAN_TRAFFIC_JAM_SUSTAINED_SECONDS=60 SCAN_TRAFFIC_JAM_COOLDOWN_SECONDS=300 # Crowd — person sustained count. Default 50 people held for 30 seconds, # 2-minute pause. Tuned for event-level density (rally, concert overflow, # major tourist hotspots). Lower to 20-30 for typical pedestrian streets # or 10-15 for residential CCTV where 50 indicates a major incident. SCAN_CROWD_THRESHOLD=50 SCAN_CROWD_SUSTAINED_SECONDS=30 SCAN_CROWD_COOLDOWN_SECONDS=120