A UK train travel expert system chatbot that helps you find cheap tickets, check journey details, and explore delay predictions.
- Python 3.10+
- A Google Gemini API key for the chatbot
- National Rail Open Data credentials for live ticket prices
-
Create a virtual environment
python -m venv venv
Activate it:
- Windows:
venv\Scripts\activate
- Windows:
-
Install dependencies
pip install -r requirements.txt pip install google-genai
-
Configure environment variables
Create a
.envfile in the project root:GEMINI_API_KEY=your_gemini_api_key NATIONAL_RAIL_USERNAME=your_username NATIONAL_RAIL_PASSWORD=your_password
-
Optional: station list
Place
StationNameAndCode.csvindata/for the full UK station list.
From the project root (with the virtual environment active):
python main.pyOpen http://localhost:3000 in your browser to use the chatbot.
The SQLite database (database/train.db) is created automatically on first run.
Delay prediction needs historical data and trained model files (not committed to git).
-
Add service detail CSVs under
data/service_details/(seeutils/preprocess_data.pyfor expected filenames). -
Build the cleaned dataset and train a model:
python utils/preprocess_data.py python models/randomforest.py
Other models:
python models/mlp.py,python models/k-nearest.py -
Load journey duration stats into the database:
python models/data_loader.py
| Path | Purpose |
|---|---|
main.py |
HTTP server and chatbot entry point |
chatbot/ |
Conversation flow and validation |
frontend/ |
Web UI (HTML/CSS) |
services/ |
Tickets, delays, LLM, journey history |
database/ |
SQLite setup and station data |
models/ |
ML training scripts and saved models |
tests/ |
Manual / integration test scripts |