HarryDataScience's picture
Deploy Mumbai Crowd Predictor
e224677
|
Raw History Blame Contribute Delete
3.15 kB
---
title: Mumbai Crowd Predictor
emoji: πŸš†
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
---
# πŸš† Mumbai Local Train β€” Crowd Density Predictor (Advanced Edition)
AI-powered crowd prediction system for Mumbai Local Trains with a full-stack FastAPI + HTML/CSS/JS deployment.
---
## πŸš€ Features
- **AI Prediction** β€” RandomForest model with 17 engineered features (~97% accuracy)
- **Hourly Forecast** β€” Full day crowd pattern for any route
- **Station Heatmap** β€” Visual heatmap of crowd across stations Γ— hours
- **Risk Scoring** β€” 0–100 risk score with reasoning and travel tips
- **Beautiful UI** β€” Dark glassmorphism design, animated charts, responsive
---
## πŸ—‚οΈ Project Structure
```
mumbai_train_app/
β”œβ”€β”€ main.py # FastAPI application (entry point)
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ model.py # RandomForest + feature engineering
β”‚ └── risk_engine.py # Risk scoring, explanations, tips
β”œβ”€β”€ data/
β”‚ └── raw/
β”‚ └── mumbai_local_crowd_data.csv
β”œβ”€β”€ static/
β”‚ β”œβ”€β”€ css/style.css # Full dark-mode glassmorphism CSS
β”‚ └── js/app.js # Frontend JavaScript
└── templates/
└── index.html # Main HTML template
```
---
## βš™οΈ Setup & Run
### 1. Install dependencies
```bash
pip install -r requirements.txt
```
### 2. Run the server
```bash
python main.py
# OR with uvicorn directly:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```
### 3. Open in browser
```
http://localhost:8000
```
---
## 🧠 ML Model Details
| Feature | Description |
|---------|-------------|
| `hour` | Hour of travel (5–22) |
| `hour_weight` | Peak-hour weight (empirical) |
| `day_num` | 0=Monday β†’ 6=Sunday |
| `is_weekday/weekend` | Binary flags |
| `is_morning_peak` | 7–9 AM flag |
| `is_evening_peak` | 5–7 PM flag |
| `morning_southbound` | Directional rush interaction |
| `evening_northbound` | Directional rush interaction |
| `line_num` | Western/Central/Harbour encoded |
| `dir_num` | Northbound/Southbound encoded |
| `station_enc / dest_enc` | Label-encoded stations |
**Algorithm**: Random Forest Classifier (200 trees, balanced class weights)
**Accuracy**: ~97% on training data
---
## πŸ“‘ API Endpoints
| Method | Path | Description |
|--------|------|-------------|
| GET | `/` | Web UI |
| GET | `/api/lines` | All train lines |
| GET | `/api/stations/{line}` | Stations for a line |
| GET | `/api/stats` | Dataset + model stats |
| POST | `/api/predict` | Single prediction |
| POST | `/api/hourly-forecast` | Full day forecast |
| GET | `/api/heatmap/{line}` | Station Γ— hour heatmap |
---
## πŸ›€οΈ Train Lines Covered
- **Western Line**: Churchgate β†’ Virar (12 stations)
- **Central Line**: CSMT β†’ Kalyan (9 stations)
- **Harbour Line**: CSMT β†’ Panvel (8 stations)
---
## πŸ‘¨β€πŸ’» Tech Stack
- **Backend**: FastAPI + Uvicorn
- **ML**: scikit-learn RandomForest, Pandas, NumPy, Joblib
- **Frontend**: Pure HTML5 + CSS3 + Vanilla JS
- **Design**: Dark glassmorphism, CSS animations, responsive