# ailab-uniss/agora architecture

> Architecture diagram of the GitHub repository ailab-uniss/agora, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ailab-uniss/agora
- Repository: https://github.com/ailab-uniss/agora

## Overview

AGORA turns public-space images into per-person posture, activity, social-configuration, age, and sex annotations. Its primary workflow detects people, pads and clusters boxes, crops each cluster, generates visual descriptions, merges them into structured records, and can combine model outputs by voting. A separate GPT zero-shot mode analyzes full images directly. Post-processing utilities create and clean CSVs and evaluate predictions. The graph follows documented and excerpted calls; some unsampled pipeline and utility details are represented only where the README documents them.

Main entry points: [`pipeline.py`](https://github.com/ailab-uniss/agora/blob/main/pipeline.py) (Detection pipeline), [`models/gpt.py`](https://github.com/ailab-uniss/agora/blob/main/models/gpt.py) (GPT analysis), [`models/gemini_api.py`](https://github.com/ailab-uniss/agora/blob/main/models/gemini_api.py) (Gemini extraction), [`gpt_full.py`](https://github.com/ailab-uniss/agora/blob/main/gpt_full.py) (GPT zero-shot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Image workflows"]
  node_pipeline["Detection pipeline<br/>[pipeline.py]"]
  node_zeroshot["GPT zero-shot<br/>[gpt_full.py]"]
end

subgraph group_models["Vision models"]
  node_detector["Faster R-CNN<br/>[fastrcnn.py]"]
  node_llava["LLaVA descriptions<br/>[llava.py]"]
  node_gpt["GPT analysis<br/>[gpt.py]"]
  node_gemini["Gemini extraction<br/>[gemini_api.py]"]
  node_ensemble["Majority voting<br/>[ensemble.py]"]
  node_backend["Backend parsing<br/>[base.py]"]
end

subgraph group_processing["Detection and data"]
  node_boxes["Box padding<br/>[bounding_box.py]"]
  node_clustering["IoU clustering<br/>[clustering.py]"]
  node_imageutils["Crop and annotate<br/>[image_utils.py]"]
  node_schemas["Validated schemas<br/>[schemas.py]"]
end

subgraph group_outputs["Results and evaluation"]
  node_resultio["Result serialization<br/>[utils.py]"]
  node_csvcreate["Prediction CSV<br/>[csv_creator.py]"]
  node_csvclean["CSV cleaning<br/>[csv_cleaner.py]"]
  node_evaluation["Metrics evaluation<br/>[evaluate.py]"]
  node_resultfiles["JSON and CSV results"]
end

subgraph group_support["Shared support"]
  node_config["Settings and prompts<br/>[config.py]"]
  node_retry["API retry<br/>[retry.py]"]
  node_logging["Logging<br/>[logging_config.py]"]
end

node_user(("Image analyst"))
node_groundtruth["Ground-truth CSV"]
node_detectron{{"Detectron2"}}
node_openai{{"OpenAI API"}}
node_google{{"Gemini API"}}
node_input["Input images"]

node_user -->|"runs workflow"| node_pipeline
node_user -->|"runs direct analysis"| node_zeroshot
node_input -->|"provides images"| node_pipeline
node_input -->|"provides full image"| node_zeroshot
node_pipeline -->|"detects people"| node_detector
node_detector -->|"runs detection"| node_detectron
node_pipeline -->|"pads boxes"| node_boxes
node_pipeline -->|"clusters boxes"| node_clustering
node_pipeline -->|"crops clusters"| node_imageutils
node_pipeline -->|"requests descriptions"| node_llava
node_pipeline -->|"selects describer or merger"| node_gpt
node_pipeline -->|"selects merger"| node_gemini
node_pipeline -->|"parses extraction"| node_backend
node_pipeline -->|"votes model results"| node_ensemble
node_pipeline -.->|"saves analysis"| node_resultio
node_zeroshot -->|"requests analysis"| node_openai
node_zeroshot -->|"creates result"| node_schemas
node_zeroshot -->|"saves JSON"| node_resultio
node_llava -->|"inherits interface"| node_backend
node_gpt -->|"inherits interface"| node_backend
node_gemini -->|"inherits interface"| node_backend
node_gpt -->|"sends requests"| node_openai
node_gemini -->|"sends requests"| node_google
node_backend -->|"parses records"| node_schemas
node_ensemble -->|"votes annotations"| node_schemas
node_detector -->|"returns boxes"| node_schemas
node_pipeline -->|"reads settings"| node_config
node_gpt -->|"reads model settings"| node_config
node_gemini -->|"reads model settings"| node_config
node_llava -->|"reads model settings"| node_config
node_gpt -->|"retries API calls"| node_retry
node_gemini -->|"retries API calls"| node_retry
node_pipeline -.->|"produces results"| node_resultfiles
node_resultio -->|"writes JSON"| node_resultfiles
node_resultfiles -->|"supplies predictions"| node_csvcreate
node_csvcreate -->|"writes prediction CSV"| node_resultfiles
node_groundtruth -->|"supplies source CSV"| node_csvclean
node_resultfiles -->|"supplies prediction CSV"| node_csvclean
node_csvclean -->|"writes cleaned CSV"| node_resultfiles
node_resultfiles -->|"supplies predictions"| node_evaluation
node_groundtruth -->|"supplies comparison data"| node_evaluation
node_evaluation -.->|"writes metrics"| node_resultfiles

click node_pipeline "https://github.com/ailab-uniss/agora/blob/main/pipeline.py"
click node_zeroshot "https://github.com/ailab-uniss/agora/blob/main/gpt_full.py"
click node_detector "https://github.com/ailab-uniss/agora/blob/main/models/fastrcnn.py"
click node_llava "https://github.com/ailab-uniss/agora/blob/main/models/llava.py"
click node_gpt "https://github.com/ailab-uniss/agora/blob/main/models/gpt.py"
click node_gemini "https://github.com/ailab-uniss/agora/blob/main/models/gemini_api.py"
click node_ensemble "https://github.com/ailab-uniss/agora/blob/main/models/ensemble.py"
click node_backend "https://github.com/ailab-uniss/agora/blob/main/models/base.py"
click node_boxes "https://github.com/ailab-uniss/agora/blob/main/utils/bounding_box.py"
click node_clustering "https://github.com/ailab-uniss/agora/blob/main/utils/clustering.py"
click node_imageutils "https://github.com/ailab-uniss/agora/blob/main/utils/image_utils.py"
click node_schemas "https://github.com/ailab-uniss/agora/blob/main/utils/schemas.py"
click node_config "https://github.com/ailab-uniss/agora/blob/main/config/config.py"
click node_retry "https://github.com/ailab-uniss/agora/blob/main/utils/retry.py"
click node_logging "https://github.com/ailab-uniss/agora/blob/main/utils/logging_config.py"
click node_resultio "https://github.com/ailab-uniss/agora/blob/main/utils/utils.py"
click node_csvcreate "https://github.com/ailab-uniss/agora/blob/main/utils/csv_creator.py"
click node_csvclean "https://github.com/ailab-uniss/agora/blob/main/utils/csv_cleaner.py"
click node_evaluation "https://github.com/ailab-uniss/agora/blob/main/utils/evaluate.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pipeline,node_zeroshot toneBlue
class node_detector,node_llava,node_gpt,node_gemini,node_ensemble,node_backend toneAmber
class node_boxes,node_clustering,node_imageutils,node_schemas,node_openai,node_google toneMint
class node_resultio,node_csvcreate,node_csvclean,node_evaluation,node_resultfiles toneRose
class node_config,node_retry,node_logging,node_user,node_groundtruth,node_detectron,node_input toneIndigo
```

## Components

### Image workflows

- [Detection pipeline](https://github.com/ailab-uniss/agora/blob/main/pipeline.py): `pipeline.py`
- [GPT zero-shot](https://github.com/ailab-uniss/agora/blob/main/gpt_full.py): `gpt_full.py`

### Vision models

- [Faster R-CNN](https://github.com/ailab-uniss/agora/blob/main/models/fastrcnn.py): `models/fastrcnn.py`
- [LLaVA descriptions](https://github.com/ailab-uniss/agora/blob/main/models/llava.py): `models/llava.py`
- [GPT analysis](https://github.com/ailab-uniss/agora/blob/main/models/gpt.py): `models/gpt.py`
- [Gemini extraction](https://github.com/ailab-uniss/agora/blob/main/models/gemini_api.py): `models/gemini_api.py`
- [Majority voting](https://github.com/ailab-uniss/agora/blob/main/models/ensemble.py): `models/ensemble.py`
- [Backend parsing](https://github.com/ailab-uniss/agora/blob/main/models/base.py): `models/base.py`

### Detection and data

- [Box padding](https://github.com/ailab-uniss/agora/blob/main/utils/bounding_box.py): `utils/bounding_box.py`
- [IoU clustering](https://github.com/ailab-uniss/agora/blob/main/utils/clustering.py): `utils/clustering.py`
- [Crop and annotate](https://github.com/ailab-uniss/agora/blob/main/utils/image_utils.py): `utils/image_utils.py`
- [Validated schemas](https://github.com/ailab-uniss/agora/blob/main/utils/schemas.py): `utils/schemas.py`

### Results and evaluation

- [Result serialization](https://github.com/ailab-uniss/agora/blob/main/utils/utils.py): `utils/utils.py`
- [Prediction CSV](https://github.com/ailab-uniss/agora/blob/main/utils/csv_creator.py): `utils/csv_creator.py`
- [CSV cleaning](https://github.com/ailab-uniss/agora/blob/main/utils/csv_cleaner.py): `utils/csv_cleaner.py`
- [Metrics evaluation](https://github.com/ailab-uniss/agora/blob/main/utils/evaluate.py): `utils/evaluate.py`
- **JSON and CSV results**

### Shared support

- [Settings and prompts](https://github.com/ailab-uniss/agora/blob/main/config/config.py): `config/config.py`
- [API retry](https://github.com/ailab-uniss/agora/blob/main/utils/retry.py): `utils/retry.py`
- [Logging](https://github.com/ailab-uniss/agora/blob/main/utils/logging_config.py): `utils/logging_config.py`

### Other components

- **Image analyst**
- **Ground-truth CSV**
- **Detectron2**
- **OpenAI API**
- **Gemini API**
- **Input images**

## Connections

- Image analyst → Detection pipeline: runs workflow (evidence: `README.md`)
- Image analyst → GPT zero-shot: runs direct analysis (evidence: `README.md`)
- Input images → Detection pipeline: provides images (evidence: `README.md`)
- Input images → GPT zero-shot: provides full image (evidence: `gpt_full.py`)
- Detection pipeline → Faster R-CNN: detects people (evidence: `pipeline.py`)
- Faster R-CNN → Detectron2: runs detection (evidence: `models/fastrcnn.py`)
- Detection pipeline → Box padding: pads boxes (evidence: `pipeline.py`)
- Detection pipeline → IoU clustering: clusters boxes (evidence: `pipeline.py`)
- Detection pipeline → Crop and annotate: crops clusters (evidence: `pipeline.py`)
- Detection pipeline → LLaVA descriptions: requests descriptions (evidence: `pipeline.py`)
- Detection pipeline → GPT analysis: selects describer or merger (evidence: `pipeline.py`)
- Detection pipeline → Gemini extraction: selects merger (evidence: `pipeline.py`)
- Detection pipeline → Backend parsing: parses extraction (evidence: `pipeline.py`)
- Detection pipeline → Majority voting: votes model results (evidence: `README.md`)
- Detection pipeline → Result serialization: saves analysis (evidence: `pipeline.py`)
- GPT zero-shot → OpenAI API: requests analysis (evidence: `gpt_full.py`)
- GPT zero-shot → Validated schemas: creates result (evidence: `gpt_full.py`)
- GPT zero-shot → Result serialization: saves JSON (evidence: `gpt_full.py`)
- LLaVA descriptions → Backend parsing: inherits interface (evidence: `models/llava.py`)
- GPT analysis → Backend parsing: inherits interface (evidence: `models/gpt.py`)
- Gemini extraction → Backend parsing: inherits interface (evidence: `models/gemini_api.py`)
- GPT analysis → OpenAI API: sends requests (evidence: `models/gpt.py`)
- Gemini extraction → Gemini API: sends requests (evidence: `models/gemini_api.py`)
- Backend parsing → Validated schemas: parses records (evidence: `models/base.py`)
- Majority voting → Validated schemas: votes annotations (evidence: `models/ensemble.py`)
- Faster R-CNN → Validated schemas: returns boxes (evidence: `models/fastrcnn.py`)
- Detection pipeline → Settings and prompts: reads settings (evidence: `pipeline.py`)
- GPT analysis → Settings and prompts: reads model settings (evidence: `models/gpt.py`)
- Gemini extraction → Settings and prompts: reads model settings (evidence: `models/gemini_api.py`)
- LLaVA descriptions → Settings and prompts: reads model settings (evidence: `models/llava.py`)
- GPT analysis → API retry: retries API calls (evidence: `models/gpt.py`)
- Gemini extraction → API retry: retries API calls (evidence: `models/gemini_api.py`)
- Detection pipeline → JSON and CSV results: produces results
- Result serialization → JSON and CSV results: writes JSON (evidence: `utils/utils.py`)
- JSON and CSV results → Prediction CSV: supplies predictions (evidence: `README.md`)
- Prediction CSV → JSON and CSV results: writes prediction CSV (evidence: `README.md`)
- Ground-truth CSV → CSV cleaning: supplies source CSV (evidence: `README.md`)
- JSON and CSV results → CSV cleaning: supplies prediction CSV (evidence: `README.md`)
- CSV cleaning → JSON and CSV results: writes cleaned CSV (evidence: `README.md`)
- JSON and CSV results → Metrics evaluation: supplies predictions (evidence: `README.md`)
- Ground-truth CSV → Metrics evaluation: supplies comparison data (evidence: `README.md`)
- Metrics evaluation → JSON and CSV results: writes metrics
