A production-style Streamlit forecasting system for Delhi Air Quality Index (AQI/PM2.5).
+-------------------+ +----------------------+ +-----------------------+
| OpenAQ API | ----> | b) Offline Update | ----> | Historical Data |
| (Historical Data) | | (fetch_history.py) | | (Standardized CSV/DB) |
+-------------------+ +----------------------+ +-----------+-----------+
|
v
+-----------------------+
| Feature Engineering |
| (make_features.py) |
+-----------+-----------+
|
+-------------------+ +----------------------+ v
| OpenAQ API | ----> | Inference Engine | +-----------------------+
| (Real-time Data) | | (fetch_recent.py) | | Model Training |
+-------------------+ | (predict.py) | <---- | (train_models.py) |
| +-----------+----------+ | (XGBoost 6h/12h/24h)|
| | +-----------------------+
v v
+--------------------------------------------------+
| Streamlit Dashboard |
| (User selects 6h / 12h / 24h) |
+--------------------------------------------------+
/data: Scripts for data acquisition and storage./training: Offline training pipeline (cleaning, feature engineering, modeling)./inference: Online inference logic (fetching recent data, generating predictions)./models: Trained model artifacts (.pkl).app.py: Main Streamlit application.
pip install -r requirements.txtFetch historical data (last 1 year +):
python data/fetch_history.pyTrain the XGBoost models for 6h, 12h, and 24h horizons:
# 1. Clean and resample to hourly
python training/build_hourly.py
# 2. Generate features and target
python training/make_features.py
# 3. Train models
python training/train_models.pyModels will be saved to the /models directory.
streamlit run app.py-
Push to GitHub:
- Create a GitHub repository.
- Push all files, including the
/modelsdirectory (this is crucial!). - Make sure
requirements.txtis in the root.
-
Connect to Streamlit Cloud:
- Go to share.streamlit.io and log in.
- Click "New App".
- Select your GitHub repository.
- Set Main file path to
app.py.
-
Add Your API Key (Secrets):
- Once deployed (or before), go to the app's Settings -> Secrets.
- Add your OpenAQ key like this:
OPENAQ_API_KEY = "your_actual_api_key_here"
- Save. The app will restart and automatically pick up the key!
To run locally, you can create a .env file in the root:
OPENAQ_API_KEY=your_key_hereOr verify it works by creating .streamlit/secrets.toml.