A pothole detection and road repair optimization system for Cotonou, Benin
# RoadAI — Cotonou, Benin
Pothole detection and road repair optimization system for the city of Cotonou.
## Features
- **Citizen reporting** (`/`) — upload a road photo, run YOLOv8 pothole detection, click the map for GPS, save a report
- **Mayor dashboard** (`/dashboard`) — reports ranked by danger score, zone heatmap, optimized repair route
- **Danger score** per report and zone: `number of potholes × average bounding-box area (px²)`
- **Repair route** — greedy priority algorithm (high danger ÷ distance to next stop)
## Stack
| Layer | Technology |
|----------|-------------------------------------------|
| Frontend | React 18, Vite, React Router, Leaflet |
| Backend | Python 3, FastAPI, Uvicorn |
| AI | Ultralytics YOLOv8 + Hugging Face Hub |
| Model | `keremberke/yolov8n-pothole-segmentation` |
| Database | SQLite (`backend/roadai.db`) |
## Project structure
```
RoadAI/
├── backend/
│ ├── main.py # FastAPI app, HF model load, /api/detect
│ ├── detection.py # Box parsing, red annotations, danger score
│ ├── database.py # SQLite reports
│ ├── optimization.py # Greedy repair route
│ ├── zones.py # Cotonou 5×5 zone grid
│ ├── uploads/ # Original images (gitignored)
│ ├── annotated/ # Annotated images (gitignored)
│ └── models/ # Optional local weights (see models/README.md)
├── frontend/
│ └── src/
│ ├── pages/ # ReportPage, DashboardPage
│ ├── components/ # CotonouMap, Layout
│ └── api.ts # API client (port 8001)
├── start-backend.ps1
├── start-frontend.ps1
└── README.md
```
## AI model and detection
At startup, `main.py` downloads and loads the pothole model from Hugging Face:
```python
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
model_path = hf_hub_download(
repo_id="keremberke/yolov8n-pothole-segmentation",
filename="best.pt",
)
model = …