Weather Transformer Forecast API is a full-stack, deep learning-powered weather forecasting platform. It leverages a Transformer neural network to predict future temperature trends from historical and real-time weather data, and provides:
- 🚀 FastAPI backend for blazing-fast, async predictions
- 📊 Interactive dashboard for visualizing forecasts
- 🧠 Transformer model for state-of-the-art time series prediction
- 🌐 RESTful API for integration and automation
📁 time_series_transformer_project/
│
├── api/
│ ├── main.py # FastAPI app and routes
│ ├── predictor.py # Model inference and forecast logic
│ ├── model_loader.py # Model loading utilities
│ ├── weather_api.py # Weather data fetching from external API
│ ├── static/
│ │ └── css/style.css # Dashboard styles
│ ├── templates/
│ │ ├── index.html # Home page
│ │ └── forecast.html # Forecast dashboard
│ └── final_transformer_model.pth # Trained model weights
│
├── dataset.py # WeatherDataset class for data loading
├── model.py # Transformer model definition
├── train.py # Model training script
├── predict.py # Batch prediction and evaluation
├── live_predictor.py # Real-time prediction logic
├── utils/
│ ├── weather_fetcher.py # Real-time weather data utilities
│ └── history_saver.py # Save forecast history
├── checkpoints/
│ └── final_transformer_model.pth # Model checkpoint
├── Weather_Data_1980_2024(hourly).csv # Historical weather data
├── forecast.png # Example forecast plot
├── run_api.py # API runner script
├── render.yaml # Render.com deployment config
└── .gitignore
| Feature | Description |
|---|---|
| Architecture | Transformer Encoder |
| Input | Last 168 hours (7 days) of weather features |
| Output | Next 72 hours (3 days) of temperature |
| Features Used | Temperature, Humidity, Wind, VPD |
| Framework | PyTorch |
git clone https://github.com/yourusername/time_series_transformer_project.git
cd time_series_transformer_project
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateCreate a requirements.txt if missing:
fastapi
uvicorn
pandas
numpy
torch
scikit-learn
requests
jinja2
matplotlib
Then install:
pip install -r requirements.txt- Ensure
Weather_Data_1980_2024(hourly).csvis in the project root. - (Optional) Train your model:
python train.pypython run_api.py
# or
uvicorn api.main:app --reload| Route | Method | Description |
|---|---|---|
/ |
GET | Home page (HTML) |
/forecast |
GET | Get 72-hour forecast (JSON) |
/forecast/html |
GET | Forecast dashboard (HTML) |
/realtime-weather |
GET | Fetch current weather from API (JSON) |
/history |
GET | Get forecast history (JSON) |
/live-forecast |
GET | Predict using latest real-time data (JSON) |
- Visit
/forecast/htmlfor an interactive forecast chart. - The dashboard uses Chart.js for beautiful, responsive plots.
# Get JSON forecast
curl http://localhost:8000/forecast
# Get real-time weather
curl http://localhost:8000/realtime-weather- Change Model/Features: Edit
model.pyanddataset.py. - Add New Endpoints: Edit
api/main.py. - Switch Data Source: Update
utils/weather_fetcher.pyorapi/weather_api.py.
- Ready for deployment on Render.com (see
render.yaml). - Can be deployed on any platform supporting Python and FastAPI.
Pull requests, issues, and suggestions are welcome!
Please open an issue or submit a PR for improvements.
MIT License.
See LICENSE for details.
Made with ❤️ for weather forecasting and deep learning.

