A routing application tailored for Kozhikode, Kerala that helps users find the safest path to their destination by predicting accident risks along the route. It uses an XGBoost model trained on historical data, road features, and real-time conditions (like weather and time of day).
Standard navigation apps optimize for the shortest or fastest route. This project optimizes for safety. By analyzing factors like road curvature, junction frequency, speed limits, and current weather, it overlays a risk probability score on road segments and routes you around potential accident hotspots.
- Backend: Python, Flask
- ML & Data: XGBoost, Scikit-Learn, Pandas
- Routing & Maps: NetworkX, OSMnx, Shapely
- Frontend: HTML/JS, Progressive Web App (PWA) support
app_flask.py: The main Flask server endpoints and UI rendering.risk_aware_navigation.py: The routing engine. Finds shortest paths and evaluates risk scores using the ML model.train_accident_model.py: Script to train the XGBoost model on thekozhikode_accident_history.csvdataset.csv_graph_loader.py: A custom fast-loader for OSM data, bypassing heavy spatial databases.start_ngrok.py: Utility to quickly expose the local server using ngrok for mobile testing.
Windows users:
Just double-click setup.bat or run it in your terminal. It will create a virtual environment (.venv) and install all dependencies automatically.
Linux / macOS users:
chmod +x setup.sh
./setup.shManual installation:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtStart the main Flask server:
python app_flask.pyIt will run locally at http://localhost:5000.
(Optional) Expose it to the internet to test the PWA on your phone:
python start_ngrok.py- Open the web interface.
- Enter an Origin (or leave it blank to use your current location) and a Destination.
- Click Analyze Route.
- The system calculates the path, highlights the top 5 most dangerous points, and outputs a Google Maps navigation link that routes you safely by setting risk zones as waypoints.
If you want to tweak features or add new data, run the training pipeline:
python train_accident_model.pyThis searches for the best hyperparameters, plots metrics, and exports a new accident_model.pkl.