File size: 3,217 Bytes
f492127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6dde3f
f492127
 
d6dde3f
f492127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6dde3f
f492127
 
 
 
 
 
d6dde3f
f492127
d6dde3f
f492127
 
 
 
 
 
 
 
 
 
 
d6dde3f
 
 
 
f492127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6dde3f
f492127
 
 
d6dde3f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# HaramGuard β€” Agentic AI Crowd Management System

## πŸ“ Folder Structure

```
HaramGuard/
β”‚
β”œβ”€β”€ config.py                  ← All thresholds & API keys (edit here only)
β”œβ”€β”€ pipeline.py                ← RealTimePipeline β€” orchestrates all agents
β”œβ”€β”€ dashboard.py               ← Streamlit dashboard entry point
β”œβ”€β”€ requirements.txt
β”‚
β”œβ”€β”€ core/                      ← Shared infrastructure (no agent logic here)
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ models.py              ← FrameResult, RiskResult, Decision dataclasses
β”‚   └── database.py            ← HajjFlowDB β€” SQLite (4 tables)
β”‚
β”œβ”€β”€ agents/                    ← One file per agent
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ perception_agent.py    ← YOLO tracking + Guardrails GR1/GR2
β”‚   β”œβ”€β”€ risk_agent.py          ← Clip segmentation + sliding K-window density scoring
β”‚   β”œβ”€β”€ reflection_agent.py    ← Self-critique design pattern (Bias detection)
β”‚   β”œβ”€β”€ operations_agent.py    ← Event-driven playbook + rate-limit guardrail
β”‚   └── coordinator_agent.py   ← openai/gpt-oss-120b + output validation guardrails GR-C1..5
β”‚
└── outputs/                   ← Auto-created at runtime
    β”œβ”€β”€ hajjflow_rt.db         ← Main SQLite database
    └── plots/                 ← Saved charts
```

## πŸ€– Agent Pipeline

```
Frame
  β”‚
  β–Ό
PerceptionAgent   β†’  FrameResult   (YOLO detect + track)
  β”‚
  β–Ό
RiskAgent         β†’  RiskResult    (clip segmentation + K-window density score)
  β”‚
  β–Ό
ReflectionAgent   β†’  reflection{}  (bias check + correction)
  β”‚
  β–Ό
OperationsAgent   β†’  Decision      (event-driven, P0/P1/P2)
  β”‚
  β–Ό
CoordinatorAgent  β†’  plan{}        (openai/gpt-oss-120b action plan, all priorities)
  β”‚
  β–Ό
pipeline.state    β†’  Dashboard
```

## πŸ›‘οΈ Guardrails

| ID | Agent | Description |
|----|-------|-------------|
| GR1 | PerceptionAgent | Person count capped at 500 |
| GR2 | PerceptionAgent | Density score capped at 50 |
| GR3 | RiskAgent | Risk score clamped to [0, 1] (density_pct / 100) |
| GR3b | RiskAgent | level_changed suppressed during K-window warmup (first 17 frames per clip) |
| GR4 | OperationsAgent | P0 rate-limited (1 per 5 min per zone); resets on pipeline restart |
| GR-C1..5 | CoordinatorAgent | LLM output validation (fields, threat_level, confidence, score-level consistency, Arabic fallback) |
| RF1..3 | ReflectionAgent | Chronic LOW bias, rising trend ignored, count-risk mismatch |

## πŸ“Š Run Evaluation

```bash
python evaluation.py
```

Outputs:
- `outputs/plots/eval_perception.png` β€” PerceptionAgent charts
- `outputs/plots/eval_risk.png`       β€” RiskAgent score trajectories
- `outputs/plots/eval_e2e.png`        β€” End-to-end accuracy + throughput
- `outputs/eval/summary.json`         β€” Final metrics summary

Rubric coverage:
- βœ… End-to-end performance metrics   (Section 5)
- βœ… Component-level evaluation       (Sections 1–4)
- βœ… Error analysis methodology       (Section 6)
- βœ… Evidence of iterative improvement (Section 7)

## πŸš€ Run Backend API

```bash
pip install -r requirements.txt
python api.py
```