"Drishti" (ΰ€¦ΰ₯ΰ€·ΰ₯ΰ€ΰ€Ώ) means Vision in Hindi. Rail Drishti gives you intelligent, data-driven vision into India's railway network.
Rail Drishti is a full-stack AI-powered railway intelligence platform built on top of real Indian Railways data. It provides two distinct dashboards β one for Passengers and one for Railway Admins β each powered by Machine Learning models running on a FastAPI backend, with a sleek dark-themed frontend served via Vercel.
The system ingests 4 real datasets (stations, schedules, train details, historical delay data), merges them into a unified master dataset, trains Random Forest models in the background on startup, and exposes a clean REST API consumed by the frontend.
databrick-main/
βββ backend/
β βββ app.py # FastAPI server β all API routes
β βββ models.py # ML models: DelayPredictor, CongestionClassifier + analytics
β βββ data_loader.py # Data ingestion, cleaning, and master dataset builder
β βββ utils.py # Terminal/ANSI display utilities
β βββ requirements.txt # Python dependencies
βββ frontend/
β βββ index.html # Single-page app (Passenger + Admin tabs)
β βββ config.js # API base URL config
βββ data/
β βββ stations.json # GeoJSON β Indian railway stations with coords/zone/state
β βββ schedules.json # Train schedules per station
β βββ Train_details_22122017.csv # Train routes, stop sequences, timings
β βββ train_delay_data_rich.csv # Historical delay data (ML training set)
βββ Dockerfile
βββ docker-compose.yml
βββ railway.json # Railway.app deployment config
| Layer | Technology |
|---|---|
| Backend | Python 3, FastAPI, Uvicorn |
| ML | scikit-learn (RandomForestRegressor, RandomForestClassifier) |
| Data | Pandas, NumPy, joblib |
| Frontend | Vanilla HTML/CSS/JS (no framework) |
| Deployment | Railway (backend), Vercel (frontend), Docker |
- Python 3.10+
- pip
# 1. Install dependencies
cd backend
pip install -r requirements.txt
# 2. Start the server
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
# 3. Open frontend
open frontend/index.html
# OR set VITE_API_URL in frontend/config.js and serve via any static serverdocker-compose up --build| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 8000 |
RAILWAYS_DATA_DIR |
Path to data folder | ./data |
FRONTEND_URL |
Allowed CORS origin for your Vercel frontend | (none) |
Predicts arrival delay in minutes given route features.
Input features:
distance_kmβ distance between stations (clamped to 0β955 km)weatherβ Clear / Rainy / Foggy / Stormy / Hazyday_of_weekβ Monday to Sundaytime_of_dayβ Morning / Afternoon / Evening / Night / Late Nighttrain_typeβ Rajdhani / Shatabdi / Duronto / Superfast / Express / Local / Passenger
Output: Delay in minutes, scaled per train type:
- Rajdhani/Shatabdi: capped at 25β30 min
- Duronto: capped at 45 min
- Express/Superfast: capped at 75β90 min
- Local/Passenger: capped at 50β60 min
Config: 50 estimators, max_depth=10, min_samples_leaf=5
Classifies a route as Low / Medium / High congestion.
Same 5 input features as DelayPredictor.
Also supports predict_proba() to return probability breakdown per class.
Config: 50 estimators, max_depth=8
Enter any train number to fetch complete intelligence for that train:
- Train name, type, source, destination, distance
- Predicted delay (ML-powered, in minutes)
- Congestion level of the route (Low / Medium / High)
- Risk level (Low / Medium / High)
- Reliability score (0β100)
- Current weather context
- Time of day bucket
After predicting delay, the system generates human-readable reasons for it:
- π«οΈ Foggy conditions β reduced speed operations active
- π§οΈ Rainfall β track adhesion and signal visibility affected
- βοΈ Storm advisory β speed restrictions imposed
- π΄ Route heavily congested β multiple trains sharing track
- β±οΈ Peak hour (Morning/Evening) β signal queuing likely
β οΈ Cascading upstream delay- π¨ Severe delay β possible track maintenance
A 0β100 score calculated from:
- Number of stops (complexity penalty)
- Average route distance (exposure penalty)
- Median historical delay (delay penalty)
Displayed as both a number and a visual progress bar.
For each stop on the route (up to 15 shown):
- Station code + name
- Scheduled arrival and departure times
- Estimated arrival = scheduled time + predicted delay minutes
- Distance in km
- Platform number (where available)
Shows other trains that share at least 2 stations with the searched train β useful as alternatives when the main train is delayed.
Quick-load overview:
- Total trains in network
- Total stations
- Total route entries
- Zone-wise train distribution
Top-N stations ranked by congestion score:
congestion_score = trains_stopping Γ log(1 + routes_through)
Displays station code, name, zone, state, train count, route count, visual gauge bar, and Low/Medium/High badge.
Top-N route corridors (Source β Destination) ranked by route score:
route_score = trains_on_corridor Γ log(1 + stations_on_corridor)
Includes corridor name, train count, station count, max distance, and load gauge.
Predicts congestion risk across 3 time windows:
- Now β current conditions
- +2 Hours β near-future
- Tomorrow AM β next-day morning
For each window, runs 4 scenario predictions (Express/Superfast/Local/Foggy-Express) with predicted delay and congestion level.
Given a train number, simulates how its delay propagates to downstream trains:
- Analyses top route corridors for that train
- Predicts base delay per corridor (ML model)
- Applies a 1.4Γ cascade factor (each downstream stop picks up ~20β40% more delay)
- Classifies cascade risk as Low / Medium / High
- Returns: input train, affected trains, station hubs, delay passed in minutes
For a given train, finds alternative trains sharing β₯ 2 stations with it, ranked by shared station count. Returns top 5 with train number, name, route, and type.
Lists trains sorted by operational priority:
- P1 β Rajdhani, Shatabdi, Duronto (highest priority)
- P2 β Superfast
- P3 β Express
- P4 β Local, Passenger
Used to decide which trains get signal/track clearance first in a congestion scenario.
Shows all Indian railway zones with:
- Number of stations
- Number of trains
- Number of states covered
- Overall congestion level (Low / Medium / High)
Automatically identifies stations with extreme congestion:
- Flags stations above the 90th percentile congestion score threshold
- Classifies them as: High / Critical / Extreme
- Provides reason: "Congestion score above 90th percentile threshold"
| Endpoint | Description |
|---|---|
GET / |
Health ping |
GET /health |
Full status: loaded, train count, station count |
| Endpoint | Params | Description |
|---|---|---|
GET /api/user/train-info |
train_no |
Full train intelligence |
GET /api/user/alternatives |
train_no |
Alternative trains on same route |
GET /api/user/station-info |
station_code |
Station metadata |
GET /api/user/nearby-stations |
station_code, radius_km |
Haversine-based nearby stations |
| Endpoint | Params | Description |
|---|---|---|
GET /api/admin/congested-stations |
top_n |
Congestion-ranked stations |
GET /api/admin/congested-corridors |
top_n |
Congestion-ranked corridors |
GET /api/admin/congestion-risk |
β | Multi-window risk forecast |
GET /api/admin/cascading-delays |
train_no |
Cascade simulation |
GET /api/admin/rerouting |
train_no |
Rerouting options |
GET /api/admin/zone-summary |
β | Zone-level operational summary |
GET /api/admin/bottlenecks |
β | Network bottleneck stations |
GET /api/admin/priority-clearance |
top_n |
Priority-sorted train queue |
GET /api/admin/operational-dashboard |
β | Full KPI summary |
| File | Records | Description |
|---|---|---|
stations.json |
~8,000+ stations | GeoJSON with lat/lon, zone, state |
schedules.json |
~100,000+ entries | Arrival/departure times per stop |
Train_details_22122017.csv |
~200,000+ rows | Route sequences with distances & timings |
train_delay_data_rich.csv |
~10,000+ rows | Historical delay data (ML training set) |
The UI uses a dark-mode design with custom CSS variables:
| Token | Value | Use |
|---|---|---|
--bg-base |
#05090f |
Page background |
--accent-blue |
#1a8fff |
Primary actions |
--accent-cyan |
#00d4ff |
Highlights |
--accent-amber |
#f59e0b |
Warnings |
--accent-red |
#ef4444 |
Danger/high delay |
--accent-green |
#22c55e |
OK/low delay |
--font-display |
Bebas Neue | Headers |
--font-mono |
Space Mono | Codes/data |
--font-body |
DM Sans | Body text |
Additional UX features: noise texture overlay, animated pulse status dot, live clock ticker, gradient glows on cards, sticky header with tab switching.
// railway.json
{ "build": { "builder": "DOCKERFILE" }, "deploy": { "startCommand": "uvicorn backend.app:app ..." } }// vercel.json
{ "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }Set FRONTEND_URL env var on Railway to your Vercel deployment URL to enable CORS.
This project uses publicly available Indian Railways data. Built for educational and research purposes.
Rail Drishti β See the railway, understand it, optimise it.