# heisumesh2006/traffic_light_detection architecture

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

- Interactive diagram: https://gitdiagram.com/heisumesh2006/traffic_light_detection
- Repository: https://github.com/heisumesh2006/traffic_light_detection

## Overview

This is a traffic-light detection assistant: camera frames are analyzed by a YOLO model, stabilized detection and distance feed an advisory response, and Flask exposes video and current status to a browser. Gemini-generated guidance is also spoken aloud. A separate utility converts traffic-light annotations to YOLO labels. Source excerpts show the principal calls; the camera endpoint and browser interactions are explicit in configuration/routes, while training and dataset consumption beyond the converter are not shown.

Main entry points: [`app.py`](https://github.com/heisumesh2006/traffic_light_detection/blob/main/app.py) (Flask application), [`realtime_detect.py`](https://github.com/heisumesh2006/traffic_light_detection/blob/main/realtime_detect.py) (Detection and distance), [`main.py`](https://github.com/heisumesh2006/traffic_light_detection/blob/main/main.py) (Detection stabilization), [`gemini_assistant.py`](https://github.com/heisumesh2006/traffic_light_detection/blob/main/gemini_assistant.py) (Gemini response)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Vision pipeline"]
  node_yolo_model["YOLO weights<br/>[best.pt]"]
  node_capture["Frame capture<br/>[realtime_detect.py]"]
  node_inference["Detection and distance<br/>[realtime_detect.py]"]
end

subgraph group_guidance["Guidance and speech"]
  node_analysis["Detection stabilization<br/>[main.py]"]
  node_gemini["Gemini response"]
  node_speech["Spoken guidance"]
end

subgraph group_web["Web interface"]
  node_flask["Flask application<br/>[app.py]"]
  node_page["Web page<br/>[index.html]"]
end

subgraph group_data["Dataset preparation"]
  node_converter["YOLO label converter"]
  node_annotations["Training annotations<br/>[train.json]"]
  node_label_config["YOLO data configuration<br/>[data.yaml]"]
end

node_user(("Browser user"))
node_camera["IP camera"]
node_audio["Audio output"]

node_user -->|"requests page and feeds"| node_flask
node_flask -->|"renders"| node_page
node_flask -->|"starts capture"| node_capture
node_flask -->|"starts detection"| node_inference
node_camera -->|"sends frames"| node_capture
node_capture -->|"shares frames"| node_inference
node_inference -->|"loads weights"| node_yolo_model
node_flask -->|"requests frame data"| node_inference
node_flask -->|"requests guidance"| node_analysis
node_analysis -->|"gets detection"| node_inference
node_analysis -->|"requests advice"| node_gemini
node_gemini -->|"speaks reply"| node_speech
node_speech -->|"outputs speech"| node_audio
node_gemini -->|"queries Gemini"| node_user
node_flask -->|"streams video and status"| node_user
node_converter -->|"reads annotations"| node_annotations
node_converter -.->|"maps light classes"| node_label_config

click node_yolo_model "https://github.com/heisumesh2006/traffic_light_detection/blob/main/best.pt"
click node_capture "https://github.com/heisumesh2006/traffic_light_detection/blob/main/realtime_detect.py"
click node_inference "https://github.com/heisumesh2006/traffic_light_detection/blob/main/realtime_detect.py"
click node_analysis "https://github.com/heisumesh2006/traffic_light_detection/blob/main/main.py"
click node_gemini "https://github.com/heisumesh2006/traffic_light_detection/blob/main/gemini_assistant.py"
click node_speech "https://github.com/heisumesh2006/traffic_light_detection/blob/main/gemini_assistant.py"
click node_flask "https://github.com/heisumesh2006/traffic_light_detection/blob/main/app.py"
click node_page "https://github.com/heisumesh2006/traffic_light_detection/blob/main/templates/index.html"
click node_converter "https://github.com/heisumesh2006/traffic_light_detection/blob/main/convert_json_to_yolo.py"
click node_annotations "https://github.com/heisumesh2006/traffic_light_detection/blob/main/train.json"
click node_label_config "https://github.com/heisumesh2006/traffic_light_detection/blob/main/data.yaml"

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_yolo_model,node_capture,node_inference,node_user toneBlue
class node_analysis,node_gemini,node_speech toneAmber
class node_flask,node_page toneMint
class node_converter,node_annotations,node_label_config toneRose
class node_camera,node_audio toneIndigo
```

## Components

### Vision pipeline

- [YOLO weights](https://github.com/heisumesh2006/traffic_light_detection/blob/main/best.pt): `best.pt`
- [Frame capture](https://github.com/heisumesh2006/traffic_light_detection/blob/main/realtime_detect.py): `realtime_detect.py`
- [Detection and distance](https://github.com/heisumesh2006/traffic_light_detection/blob/main/realtime_detect.py): `realtime_detect.py`

### Guidance and speech

- [Detection stabilization](https://github.com/heisumesh2006/traffic_light_detection/blob/main/main.py): `main.py`
- [Gemini response](https://github.com/heisumesh2006/traffic_light_detection/blob/main/gemini_assistant.py): `gemini_assistant.py`
- [Spoken guidance](https://github.com/heisumesh2006/traffic_light_detection/blob/main/gemini_assistant.py): `gemini_assistant.py`

### Web interface

- [Flask application](https://github.com/heisumesh2006/traffic_light_detection/blob/main/app.py): `app.py`
- [Web page](https://github.com/heisumesh2006/traffic_light_detection/blob/main/templates/index.html): `templates/index.html`

### Dataset preparation

- [YOLO label converter](https://github.com/heisumesh2006/traffic_light_detection/blob/main/convert_json_to_yolo.py): `convert_json_to_yolo.py`
- [Training annotations](https://github.com/heisumesh2006/traffic_light_detection/blob/main/train.json): `train.json`
- [YOLO data configuration](https://github.com/heisumesh2006/traffic_light_detection/blob/main/data.yaml): `data.yaml`

### Other components

- **Browser user**
- **IP camera**
- **Audio output**

## Connections

- Browser user → Flask application: requests page and feeds (evidence: `app.py`)
- Flask application → Web page: renders (evidence: `app.py`)
- Flask application → Frame capture: starts capture (evidence: `app.py`)
- Flask application → Detection and distance: starts detection (evidence: `app.py`)
- IP camera → Frame capture: sends frames (evidence: `realtime_detect.py`)
- Frame capture → Detection and distance: shares frames (evidence: `realtime_detect.py`)
- Detection and distance → YOLO weights: loads weights (evidence: `realtime_detect.py`)
- Flask application → Detection and distance: requests frame data (evidence: `app.py`)
- Flask application → Detection stabilization: requests guidance (evidence: `app.py`)
- Detection stabilization → Detection and distance: gets detection (evidence: `main.py`)
- Detection stabilization → Gemini response: requests advice (evidence: `main.py`)
- Gemini response → Spoken guidance: speaks reply (evidence: `gemini_assistant.py`)
- Spoken guidance → Audio output: outputs speech (evidence: `gemini_assistant.py`)
- Gemini response → Browser user: queries Gemini (evidence: `gemini_assistant.py`)
- Flask application → Browser user: streams video and status (evidence: `app.py`)
- YOLO label converter → Training annotations: reads annotations (evidence: `convert_json_to_yolo.py`)
- YOLO label converter → YOLO data configuration: maps light classes
