HaramGuard / backend /config.py
adeem6's picture
Update backend/config.py
61fc9df verified
raw
history blame
4.26 kB
"""
HaramGuard β€” Central Configuration
=====================================
Edit this file to tune thresholds without touching agent code.
"""
import os
# ── API Keys ─────────────────────────────────────────────────────────
GROQ_API_KEY = os.getenv('GROQ_API_KEY', 'Secret')
ANTHROPIC_KEY = os.getenv('ANTHROPIC_KEY', 'YOUR_ANTHROPIC_KEY_HERE')
# ── Paths ─────────────────────────────────────────────────────────────
VIDEO_PATH = 'hajj_real_video.mp4'
DB_PATH = 'outputs/hajjflow_rt.db'
MODEL_PATH = 'yolo11l.pt' # swap to 'yolov8x.pt' for better detection
# ── PerceptionAgent ───────────────────────────────────────────────────
PERCEPTION_MAX_PERSONS = 500
PERCEPTION_MAX_DENSITY = 50.0
PERCEPTION_CONF = 0.12
PERCEPTION_IOU = 0.5
PERCEPTION_IMGSZ = 1024
# ── RiskAgent ─────────────────────────────────────────────────────────
# Single-camera partial-view calibration:
# Camera sees near crowd first, far crowd later β†’ peak across window is
# more representative than instantaneous count.
# Metric: EMA of per-frame peak (sliding-peak + exponential smoothing).
#
# Observed range from 17-frame demo: ~7–70 persons
# Thresholds chosen so the demo naturally traverses LOW→MEDIUM→HIGH:
# LOW : peak_ema < 20 (sparse, camera sees near edge only)
# MEDIUM : 20–49 (moderate, mid-crowd visible)
# HIGH : β‰₯ 50 (dense, full crowd fills frame)
RISK_WINDOW_SIZE = 17 # match demo frame count β€” window = one full demo loop
RISK_HIGH_THRESHOLD = 0.65 # score >= 0.65 β†’ HIGH (β‰ˆ peak_ema β‰₯ 50 persons)
RISK_MED_THRESHOLD = 0.35 # score >= 0.35 β†’ MEDIUM (β‰ˆ peak_ema β‰₯ 20 persons)
RISK_HIGH_DENSITY = 1.0 # kept for compression calc
RISK_HIGH_COUNT = 50 # normalizer: peak_ema / HIGH_COUNT β†’ score 0–1
RISK_EMA_ALPHA = 0.6 # raised from 0.4 β€” faster reaction to crowd changes
# Fruin LoS-calibrated weights (Fruin 1971 + UQU Haram research)
# W_DENSITY raised 0.50β†’0.60: fixes structural ceiling bug where HIGH was unreachable
# Old weights (0.65/0.15/0.10/0.07/0.03) used by RiskAgent directly β€” now agent owns them
RISK_W_DENSITY = 0.60 # Fruin count-based primary (c_score=1.0 β†’ 0.60 > HIGH_THRESHOLD)
RISK_W_SPACING = 0.10 # physical spacing between persons
RISK_W_TREND = 0.10 # rising/stable/falling (ROC handled inside agent)
RISK_W_COMPRESSION = 0.10 # crowd compression
RISK_W_FLOW = 0.00 # flow velocity (disabled β€” noisy without optical flow)
RISK_W_DISTRIBUTION = 0.00 # spatial distribution (replaced by grid-based Path 4)
RISK_SPACING_REF = 120.0 # px β€” comfortable spacing
# ── ReflectionAgent ───────────────────────────────────────────────────
REFLECTION_BIAS_WINDOW = 10 # reduced: 17-frame loop, catch bias faster
REFLECTION_CROWD_LOW_THRESH = 15 # chronic LOW suspicious above 15 persons
REFLECTION_HIGH_CROWD_THRESH = 50 # 50+ persons but LOW β†’ upgrade to MEDIUM
REFLECTION_OVER_EST_THRESH = 15 # HIGH risk but <15 persons β†’ downgrade
# ── OperationsAgent ───────────────────────────────────────────────────
OPS_RATE_LIMIT_SEC = 60 # reduced: 1 min cooldown (pipeline is slow, 5min was too long)
OPS_P0_SCORE = 0.65 # aligned with RISK_HIGH_THRESHOLD
OPS_P1_SCORE = 0.35 # aligned with RISK_MED_THRESHOLD
# ── API Server ─────────────────────────────────────────────────────────
API_PORT = 8000