Skip to content

Repository files navigation

Namma AI

Namma AI

Smarter Roads. Safer Journeys.

Traffic Intelligence Platform for Bengaluru

Python FastAPI Next.js PostgreSQL CatBoost License

Namma Traffic Platform

Overview

Namma AI helps Bengaluru Traffic Police shift from reactive patrol to proactive, data-driven enforcement. It predicts incident severity and road-closure probability using a CatBoost ML model, recommends officer and barricade deployment, generates diversion routes, surfaces hotspots on a live heatmap, and lets citizens report incidents directly to authorities.

Next.js 14 · FastAPI · PostgreSQL · CatBoost

Key Metrics

Metric Value
ML inference latency < 5 ms per prediction
Diversion route computation < 3 s
Incident telemetry Real-time via WebSocket
Authentication JWT-based
Access control Role-based (Citizen / Personnel / Authority)
API REST, with auto-generated Swagger documentation

Tech Stack

Layer Technology
Frontend Next.js 14, TypeScript, Tailwind CSS, Leaflet (OpenStreetMap), Recharts
Backend FastAPI, Pydantic v2, SQLAlchemy
Database PostgreSQL
ML CatBoost (closure probability + priority ranking), DBSCAN (hotspot clustering)
Routing OSRM public server + custom diversion engine
Maps & weather OpenStreetMap tiles, Open-Meteo API (both free, no key needed)

Why Do We Need Namma Traffic

Folder Structure

namma-traffic/
├── backend/          # FastAPI app, models, routers, ML inference
│   ├── models/       # CatBoost + DBSCAN model artifacts
│   ├── routers/      # API route handlers
│   └── main.py
├── frontend/         # Next.js 14 app (citizen + authority views)
│   ├── app/
│   └── components/
├── docs/             # Screenshots, logo, hero images
└── README.md

Run Locally

Prerequisites

1 — Database

createdb traffic_db

2 — Backend

Open a terminal in the project root:

# Windows (PowerShell)
cd backend
py -3.12 -m venv venv
venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn main:app --reload
# Mac / Linux
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload

If PowerShell blocks script execution, run once: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

Backend: http://localhost:8000 · Swagger docs: http://localhost:8000/docs

The schema (all tables and columns) is created automatically on first start.

3 — Environment variables

Create backend/.env:

DATABASE_URL=postgresql://user:pass@localhost:5432/traffic_db
JWT_SECRET_KEY=any-random-string-here

# Optional — only needed for Gemini advisory and Cloudinary photo upload
GEMINI_API_KEY=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=

4 — Frontend

Open a second terminal:

cd frontend          # or: cd namma-traffic/frontend
npm install
npm run dev

Open http://localhost:3000


Demo Flow

  1. Open http://localhost:3000
  2. Seed data — click "I'm an Authority" → log in (admin / admin123) → Dashboard → expand Admin Tools → click Generate demo data
  3. Citizen view — go back to home → click "I'm a Citizen" → try Safe Route Finder and Live Heatmap
  4. Report an incident — Citizen → Report Incident → fill form → submit → copy tracking ID
  5. Verify it — Authority → Verify Reports → approve the report → watch it appear on the dashboard live
  6. Resource planning — Authority → Deployment → see per-incident officer and barricade recommendations
  7. Diversion — Authority → Diversion Plans → click "Diversion plan" on any incident

Roles & Logins

Role How to access Credentials
Citizen Home → "I'm a Citizen" No login needed
Traffic Personnel Home → "I'm Traffic Personnel" Register or use demo login
Authority Home → "I'm an Authority" → Login admin / admin123

Page Routes

Route Who Description
/ Public Landing + role selection
/citizen/report Citizen Submit incident report
/citizen/heatmap Citizen Live incident map + hotspots
/citizen/route Citizen Incident-aware safe route planner
/authority/login Authority JWT login
/authority/dashboard Authority Live KPIs + priority incidents
/authority/predict Authority ML closure probability + priority ranking
/authority/analytics Authority Incident trends (charts from live DB)
/authority/resources Authority Per-incident deployment recommendations
/authority/diversion Authority Auto-generated diversion routes
/authority/verify Authority Approve / reject citizen reports

API Example

POST /api/predict — returns road-closure probability and priority ranking for an incident.

Request:

{
  "incident_type": "accident",
  "location": {
    "lat": 12.9716,
    "lng": 77.5946
  },
  "severity": "moderate",
  "weather": "rain",
  "time_of_day": "peak_hour",
  "road_type": "arterial"
}

Response:

{
  "closure_probability": 0.72,
  "priority_score": 8.4,
  "recommended_officers": 3,
  "recommended_barricades": 2,
  "estimated_clearance_minutes": 35
}

Full interactive docs for all endpoints are available at /docs (Swagger UI) once the backend is running.

Deploy

  • Backend → Render: New Web Service · root backend · start command uvicorn main:app --host 0.0.0.0 --port $PORT · set env vars in Render dashboard
  • Frontend → Vercel: Import repo · root frontend · set NEXT_PUBLIC_API_URL to your Render backend URL

Namma Traffic · Smarter Roads. Safer Journeys.
BIT Mesra

About

AI traffic intelligence platform for Bengaluru — predicts incident severity & road-closure probability with CatBoost, recommends officer/barricade deployment, auto-generates diversion routes, and surfaces hotspots on a live heatmap. Next.js 14 + FastAPI + PostgreSQL.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages