Skip to content

KolaSailaja/SmartCity

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ† Civora AI-Powered Smart Urban Safety & Emergency Response Platform

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.


๐Ÿš€ Project Overview

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.


โœจ Key Features

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

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        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)        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ—„๏ธ TigerGraph โ€” UrbanSafetyGraph

Graph name: UrbanSafetyGraph
Host: TigerGraph Cloud (accessed via JWT Bearer token; DNS-patch applied for institutional network)

Vertex Types

Type Key attributes
Intersection intersection_id, intersection_name, latitude, longitude

Edge Types

Type Description
RoadSegment (directed) Connects intersections; carries distance_km, risk_score, lighting_score

Data

  • 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

๐Ÿ“‚ Repository Structure

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

๐Ÿค– AI Pipelines

1. LSTM Danger Predictor

  • 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%

2. Computer Vision (CCTV Analysis)

  • MobileNetV2 โ€” crowd density classification (Low / Medium / High)
  • YOLOv8n โ€” person count + anomaly detection (weapons, suspicious objects)
  • Accepts JPEG/PNG uploads or Base-64 encoded frames

3. NLP Incident Classifier

  • 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

๐Ÿ‘ฅ User Roles

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

๐Ÿ› ๏ธ Running Locally

Prerequisites

  • Python โ‰ฅ 3.10
  • Node.js โ‰ฅ 18
  • TigerGraph Cloud account (or set USE_MOCK_DB=true in config.py)

Backend

# 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/docs

Or use the convenience launcher:

python start_backend.py

Frontend

# From project root
npm install
npm run dev
# โ†’ runs at http://localhost:5173

Loading Graph Data

cd data
python load_to_tg.py

Note: The loader patches Python's DNS resolver to bypass institutional DNS restrictions that block TigerGraph Cloud hostnames.


๐Ÿ”‘ Environment / Configuration

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

๐Ÿ”Œ API Reference (summary)

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


๐Ÿงฉ Tech Stack

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

๐Ÿ“œ License

MIT โ€” feel free to fork and build on top of this for your own city-safety use case.

About

Devcation IIT-D'26

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages