Hackathon Submission | IIT Delhi ร TigerGraph
A real-time, graph-powered urban-safety platform for Chandigarh that combines AI inference, live CCTV crowd analysis, incident NLP, and multi-role dashboards.
SmartCity is an end-to-end intelligent safety system that empowers citizens, patrol officers, and supervisors with actionable, AI-generated insights about city-safety in real time. It integrates a TigerGraph knowledge graph (UrbanSafetyGraph) of the Chandigarh road network with three independent AI pipelines โ LSTM time-series danger prediction, computer-vision crowd analysis, and NLP incident classification โ all served through a FastAPI backend and a React/Vite frontend.
| Feature | Description |
|---|---|
| ๐บ๏ธ Live Danger Heatmap | Per-intersection danger scores overlaid on the Chandigarh map, fetched from TigerGraph |
| ๐ค๏ธ Safe Route Planner | Dijkstra-based safest-path computation over the graph with live risk weights |
| ๐ก CCTV Crowd Analysis | MobileNetV2 + YOLOv8 inference on uploaded frames to estimate crowd density & detect anomalies |
| ๐ฎ LSTM Danger Predictor | Temporal LSTM model (lstm_INT007.keras) predicts danger scores per zone (MC-Dropout uncertainty bounds) |
| ๐ NLP Incident Reports | Transformer-based sentiment/emotion/severity pipeline; fast keyword path returns enriched results in < 5 ms |
| ๐จ SOS Dispatch | Citizens can trigger SOS; supervisors see live alerts with AI-generated classification |
| ๐ฎ Role-Based Access (RBAC) | Three roles: Citizen, Patrol Officer, Supervisor โ each with a custom portal |
| ๐ Supervisor Dashboard | Real-time incident feed, analytics, cluster overview, officer tracking |
| ๐๏ธ Cluster Info | Zone-level statistical summary pulled from the graph |
| ๐ Graph Explorer | Interactive node/edge explorer for the UrbanSafetyGraph |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ React / Vite Frontend โ
โ (Leaflet maps ยท Recharts analytics ยท Role portals) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP /api/v1/*
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Backend (backend_python/) โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ LSTM Router โ โ CV Router โ โ NLP / Reports Router โ โ
โ โ (danger.py) โ โ (cctv.py) โ โ (reports.py) โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโโโโโฌโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ โ
โ โ AI Model Layer (ai/) โ โ
โ โ lstm/lstm_INT007.keras ยท cv/mobilenetv2_crowd.pth โ โ
โ โ cv/yolov8n.pt ยท nlp/inference.py โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Graph / Data Routers โ โ
โ โ safe_route ยท intersections ยท incidents ยท cluster_info โ โ
โ โ graph (heatmap) ยท danger_score ยท portal_routes โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ custom_db/tigergraph_client.py โ โ
โ โ pyTigerGraph โ TigerGraph Cloud โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TigerGraph Cloud โ UrbanSafetyGraph โ
โ Intersection vertices ยท Road-segment edges ยท Safety attributes โ
โ (Chandigarh road network โ 400 vertices, 2 300+ edges) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Graph name: UrbanSafetyGraph
Host: TigerGraph Cloud (accessed via JWT Bearer token; DNS-patch applied for institutional network)
| Type | Key attributes |
|---|---|
Intersection |
intersection_id, intersection_name, latitude, longitude |
| Type | Description |
|---|---|
RoadSegment (directed) |
Connects intersections; carries distance_km, risk_score, lighting_score |
- Source: Custom-scraped Chandigarh road-network JSON (
data/chandigarh_vertices.json,data/chandigarh_edges.json) - Loader:
data/load_to_tg.pyโ batched REST++ upsert with retry logic and DNS bypass - Batch sizes: 200 vertices / 300 edges per request
SmartCity/
โโโ ai/ # AI model files & inference code
โ โโโ lstm/
โ โ โโโ lstm_INT007.keras # Trained LSTM danger-score model
โ โ โโโ scaler_INT007.pkl # Feature scaler for LSTM
โ โ โโโ inference.py
โ โโโ cv/
โ โ โโโ mobilenetv2_crowd.pth # MobileNetV2 crowd density classifier
โ โ โโโ inference.py # YOLOv8 + MobileNetV2 pipeline
โ โ โโโ app.py
โ โโโ nlp/
โ โโโ inference.py # Transformer NLP pipeline (>50 KB)
โ โโโ app.py
โ
โโโ backend_python/ # FastAPI application
โ โโโ main.py # App entry point, router registration, lifespan
โ โโโ config.py # All env-vars & feature-flags in one place
โ โโโ requirements.txt
โ โโโ routers/ # One file per API feature
โ โ โโโ danger.py # POST /api/v1/danger/score (LSTM+CV+anomaly)
โ โ โโโ cctv.py # POST /api/v1/cctv/analyze
โ โ โโโ reports.py # GET/POST /api/v1/reports + NLP analysis
โ โ โโโ safe_route.py # GET /api/v1/safe-route
โ โ โโโ intersections.py # GET /api/v1/intersections
โ โ โโโ incidents.py # GET /api/v1/incidents
โ โ โโโ graph.py # GET /api/v1/graph/{heatmap,intersections,status}
โ โ โโโ auth.py # POST /api/v1/auth/signup & /login
โ โ โโโ citizen.py # Citizen-role endpoints
โ โ โโโ supervisor.py # Supervisor-role endpoints
โ โ โโโ officer.py # Patrol-officer endpoints
โ โ โโโ portal_routes.py # Dual-route, SOS, admin stats
โ โ โโโ ...
โ โโโ custom_db/
โ โ โโโ tigergraph_client.py # Singleton TigerGraph connection wrapper
โ โ โโโ mock_db.py # In-memory fallback when TG is unavailable
โ โโโ services/ # Business-logic layer (NLP, danger aggregation)
โ โโโ middleware/
โ
โโโ src/ # React / Vite frontend
โ โโโ pages/
โ โ โโโ Login.jsx & Signup.jsx
โ โ โโโ SupervisorDashboard.jsx # Live incident feed + analytics
โ โ โโโ CitizenDashboard.jsx
โ โ โโโ OfficerDashboard.jsx
โ โ โโโ PublicCitizenPortal.jsx # Map, safe-route, SOS, report form
โ โโโ components/
โ โ โโโ Dashboard.jsx # Main map + heatmap overlay
โ โ โโโ SafeRoutePanel.jsx
โ โ โโโ DangerPanel.jsx
โ โ โโโ CCTVPanel.jsx
โ โ โโโ IncidentsPanel.jsx
โ โ โโโ AnomalyScanner.jsx
โ โ โโโ ClusterPanel.jsx
โ โ โโโ Explorer.jsx # Graph explorer
โ โ โโโ ReportForm.jsx
โ โ โโโ AdminPortal.jsx
โ โ โโโ ...
โ โโโ api/ # Axios wrappers for backend calls
โ
โโโ data/ # Graph seed data & loaders
โ โโโ chandigarh_vertices.json # ~400 intersection vertices
โ โโโ chandigarh_edges.json # ~2 300 road-segment edges
โ โโโ chandigarh_graph_data.json
โ โโโ load_to_tg.py # Bulk loader (REST++ upsert, DNS patch)
โ
โโโ start_backend.py # One-command backend launcher
โโโ index.html
โโโ vite.config.js
โโโ package.json
- Model: Custom LSTM trained on intersection-level temporal features (
lstm_INT007.keras) - Input: 24-step time-series of [hour, day, crimes, incidents, crowd_density, lighting]
- Output:
danger_scoreโ [0,1] with MC-Dropout uncertainty bounds - Aggregation weights: LSTM 45% ยท CV 30% ยท Anomaly 15% ยท Graph 10%
- MobileNetV2 โ crowd density classification (Low / Medium / High)
- YOLOv8n โ person count + anomaly detection (weapons, suspicious objects)
- Accepts JPEG/PNG uploads or Base-64 encoded frames
- Fast path (< 5 ms): Keyword-based emergency detection โ instant response
- Full ML path (background): Transformer-based sentiment, emotion (7 classes), entity extraction, credibility scoring, deduplication
- Output fields:
severity,emergency_level,distress_level,recommended_actions,auto_response
| Role | Login | Access |
|---|---|---|
| Citizen | Email + Password | Report incident, request safe route, SOS |
| Patrol Officer | Officer credential | Live patrol map, accept assignments |
| Supervisor | Supervisor access key | Full dashboard, analytics, incident management |
- Python โฅ 3.10
- Node.js โฅ 18
- TigerGraph Cloud account (or set
USE_MOCK_DB=trueinconfig.py)
# From project root
cd backend_python
pip install -r requirements.txt
# Start the FastAPI server
python main.py
# โ runs at http://localhost:8000
# โ API docs at http://localhost:8000/docsOr use the convenience launcher:
python start_backend.py# From project root
npm install
npm run dev
# โ runs at http://localhost:5173cd data
python load_to_tg.pyNote: The loader patches Python's DNS resolver to bypass institutional DNS restrictions that block TigerGraph Cloud hostnames.
All settings live in backend_python/config.py. Key variables:
| Variable | Default | Description |
|---|---|---|
TG_HOST |
TG Cloud URL | TigerGraph host |
TG_GRAPHNAME |
UrbanSafetyGraph |
Target graph |
TG_TOKEN |
JWT bearer | Auth token |
USE_MOCK_DB |
false |
Use in-memory mock instead of TG |
ENABLE_CV |
true |
Enable CV inference |
ENABLE_NLP |
true |
Enable NLP inference |
ENABLE_LSTM |
true |
Enable LSTM inference |
W_LSTM / W_CV / W_ANOMALY / W_GRAPH |
0.45 / 0.30 / 0.15 / 0.10 | Danger aggregation weights |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Service health + model status |
POST |
/api/v1/danger/score |
LSTM+CV+Anomaly aggregated danger score |
GET |
/api/v1/danger-score |
Per-intersection danger scores (TG-backed) |
GET |
/api/v1/graph/heatmap |
Heatmap data from TigerGraph |
GET |
/api/v1/intersections |
All intersection vertices |
GET |
/api/v1/incidents |
Incident list |
POST |
/api/v1/cctv/analyze |
CCTV frame crowd + anomaly analysis |
GET/POST |
/api/v1/reports |
List / submit + NLP-analyze incident reports |
GET |
/api/v1/safe-route |
Safe route between two intersections |
GET |
/api/v1/cluster-info |
Zone cluster statistics |
POST |
/api/v1/auth/signup |
User registration |
POST |
/api/v1/auth/login |
JWT login (citizen / officer / supervisor) |
POST |
/api/v1/user/sos |
SOS alert dispatch |
GET |
/api/v1/admin/stats |
Admin / supervisor analytics |
Full interactive docs: http://localhost:8000/docs
| Layer | Technologies |
|---|---|
| Frontend | React 19, Vite 8, Leaflet/React-Leaflet, Recharts, TailwindCSS |
| Backend | FastAPI 0.115, Uvicorn, Pydantic v2, python-jose (JWT) |
| Graph DB | TigerGraph Cloud โ UrbanSafetyGraph, pyTigerGraph 1.6 |
| AI โ LSTM | TensorFlow / Keras, scikit-learn (scaler), NumPy |
| AI โ CV | PyTorch, MobileNetV2, Ultralytics YOLOv8, Pillow |
| AI โ NLP | HuggingFace Transformers, scikit-learn, SciPy |
| Maps | OpenStreetMap tiles via Leaflet |
MIT โ feel free to fork and build on top of this for your own city-safety use case.