Skip to content

Multivariate weather forecasting with Transformers and FastAPI — featuring real-time predictions and interactive visualization

Notifications You must be signed in to change notification settings

Ali-hey-0/forecast-fusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌦️✨ Weather Transformer Forecast API

Python FastAPI PyTorch License: MIT


🌍 Accurate, Modern, and Interactive Weather Forecasting with Deep Learning Transformers

Forecast Example

✨ Overview

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

🗂️ Project Structure

📁 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

🧠 Model Highlights

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

🚦 Quickstart

1. Clone & Setup

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\activate

2. Install Dependencies

Create a requirements.txt if missing:

fastapi
uvicorn
pandas
numpy
torch
scikit-learn
requests
jinja2
matplotlib

Then install:

pip install -r requirements.txt

3. Prepare Data & Model

  • Ensure Weather_Data_1980_2024(hourly).csv is in the project root.
  • (Optional) Train your model:
python train.py

4. Run the API

python run_api.py
# or
uvicorn api.main:app --reload

🌐 API Endpoints

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)

📊 Dashboard Preview

  • Visit /forecast/html for an interactive forecast chart.
  • The dashboard uses Chart.js for beautiful, responsive plots.

Dashboard Preview


📝 Example Usage

# Get JSON forecast
curl http://localhost:8000/forecast

# Get real-time weather
curl http://localhost:8000/realtime-weather

🛠️ Customization

  • Change Model/Features: Edit model.py and dataset.py.
  • Add New Endpoints: Edit api/main.py.
  • Switch Data Source: Update utils/weather_fetcher.py or api/weather_api.py.

☁️ Deployment

  • Ready for deployment on Render.com (see render.yaml).
  • Can be deployed on any platform supporting Python and FastAPI.

🤝 Contributing

Pull requests, issues, and suggestions are welcome!
Please open an issue or submit a PR for improvements.


📄 License

MIT License.
See LICENSE for details.


🙏 Acknowledgements


Made with ❤️ for weather forecasting and deep learning.

About

Multivariate weather forecasting with Transformers and FastAPI — featuring real-time predictions and interactive visualization

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published