A multi-page, real-time Air Quality Index monitoring dashboard with a self-correcting forecast model and a live performance hub, built with Python and Dash.
BreatheEasy is a full-stack air quality analysis and forecasting dashboard. It provides a clean, intuitive web interface for major Indian cities to:
- Analyze historical Air Quality Index (AQI) trends.
- Display real-time AQI and weather information.
- Generate an intelligent, 3-day AQI forecast that self-corrects based on live data.
- Translate complex air quality data into clear, understandable health risks based on the official CPCB (Central Pollution Control Board) standard.
- Monitor the application's own system health via a live performance hub.
This repository contains the complete source code for the project, including a Dash-based multi-page frontend and a robust Python backend for data processing, API integration, and machine learning.
The application features a fully responsive, dual-theme interface that adapts to your system preferences.
| Light Theme | Dark Theme |
|---|---|
![]() |
![]() |
- Interactive Main Dashboard: A user-friendly interface to view current AQI, pollutant risks, historical trends, and educational information. Features a seamless dual-theme (light/dark) experience.
- Intelligent 3-Day Forecast: A sophisticated "Anchor and Trend" forecasting model that uses a raw LightGBM prediction and calibrates it against live AQI data for improved accuracy. The smoothing factor is dynamic, trusting the model more when its predictions are accurate and less when they are not.
- Live Performance Hub: A real-time monitoring page (
/performance) that displays live system metrics (CPU, Memory, Network I/O) via time-series graphs, tracks application process details, and provides a view of the live application logs. - Persistent Background Data Collection: A background process collects system metrics continuously from the moment the app starts, ensuring a complete history is available whenever the performance hub is viewed.
- Dynamic UI Components: The dashboard features custom-built SVG gauges and responsive layouts that adapt to different screen sizes.
A massive thank you to the talented team that brought BreatheEasy to life. Their dedication and collaboration were instrumental to this project's success.
The application is architected with a clear separation between the backend data processes and the frontend presentation layers.
-
Model Training (Offline):
- The
src/modeling/train.pyscript trains aLightGBMmodel for each city on theMaster_Daily_Features.csvdataset. - The trained models are saved as
.pklfiles in the/modelsdirectory, along with their validation scores and feature importances.
- The
-
Application Startup (Backend):
- When
python app.pyis run, the main Dash application starts. - A hidden
dcc.Intervalinapp.pyimmediately begins a background task, continuously collecting system metrics (CPU, RAM, Network) and storing them in a centralshared_data.pyfile.
- When
-
User Interaction (Frontend):
- A user navigates to the main dashboard (
/). Selecting a city triggers callbacks inpages/dashboard.py. - Forecasting: The
predictor.pymodule is called. It loads the pre-trained LightGBM model, fetches a weather forecast, generates a raw AQI prediction, and then applies the "Anchor and Trend" logic by comparing it to a live AQI value. - Real-time Data: The application fetches current AQI, pollutant levels, and weather from external APIs.
- The UI is dynamically updated with the forecast, gauges, and health advisories.
- A user navigates to the main dashboard (
-
Performance Monitoring:
- A user navigates to the performance hub (
/performance). - Callbacks in
pages/performance.pyread from the continuously updated data stores inshared_data.pyto render the live graphs and scorecards, providing a real-time view of the application's health.
- A user navigates to the performance hub (
- Framework: Dash, Plotly
- UI Components: Dash Core Components, Dash HTML Components, Dash Bootstrap Components
- Custom Visualization:
dash-svgfor the dynamic AQI gauge. - Styling: Custom CSS for a dual-theme (light/dark) responsive layout.
- Language: Python 3.10+
- Machine Learning: LightGBM, Scikit-learn
- Data Manipulation: Pandas, NumPy
- System Monitoring:
psutil - API Interaction:
requests
- Configuration:
PyYAMLforconfig.yaml,python-dotenvfor API keys. - Testing:
pytest - Environment: Jupyter Notebooks for initial data exploration.
The repository is organized into a modular structure that separates concerns, making it clean and maintainable.
├── app.py # Main Dash app entry point handles background tasks
├── shared_data.py # Central data store for performance hub
├── requirements.txt # Python package dependencies
├── config/
│ └── config.yaml # Central configuration for the application
├── assets/ # CSS, images, logos, and favicon
│ ├── performance_style.css # Stylesheet for the performance hub
│ └── style.css # Stylesheet for the main dashboard
├── data/ # Datasets used for training and analysis
│ └── Post-Processing/
│ └── CSV_Files/
│ └── Master_Daily_Features.csv
├── models/ # Trained LightGBM models and performance artifacts
│ ├── Bangalore_lgbm_daily_model.pkl
│ ├── Chennai_lgbm_daily_model.pkl
│ ├── Kolkata_lgbm_daily_model.pkl
│ ├── Mumbai_lgbm_daily_model.pkl
│ └── ... (and feature_importance/validation_score files)
├── pages/ # Multi-page app layouts and callbacks
│ ├── dashboard.py
│ └── performance.py
├── src/ # Core backend source code
│ ├── analysis/ # Historical data analysis functions
│ ├── api_integration/ # External API clients
│ ├── health_rules/ # AQI scales and interpretation logic
│ └── modeling/
│ ├── predictor.py # Generates final, calibrated forecasts
│ └── train.py # Trains the LightGBM models
├── notebook/ # Jupyter notebooks for exploration and development
├── scripts/ # Helper scripts for data processing tasks
└── tests/ # Automated tests for the backend
Follow these steps to set up and run the BreatheEasy dashboard on your local machine.
- Python 3.10 or newer.
gitinstalled on your system.
git clone https://github.com/cp099/BreatheEasy
cd BreatheEasyIt is strongly recommended to use a virtual environment to manage project dependencies.
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
# On Windows
python -m venv venv
.\venv\Scripts\activateInstall all required Python packages from the requirements.txt file.
pip install -r requirements.txtThe application requires API keys from two services to fetch live, real-time data.
- Create the
.envfile: In the root directory of the project, create a new file named.env. - Get API Keys:
- WeatherAPI: Sign up for a free key at weatherapi.com
- AQICN: Get a free token from the World Air Quality Index Project.
- Add Keys to
.env: Open the.envfile and add your keys in the following format:WEATHERAPI_API_KEY="YOUR_ACTUAL_WEATHERAPI_KEY_HERE" AQICN_API_TOKEN="YOUR_ACTUAL_AQICN_TOKEN_HERE"
Security Note: The
.gitignorefile is already configured to prevent your.envfile from being committed to Git.
With the setup complete, you can now run the Dash application directly.
python app.pyThe application will start, and you can access the dashboard by navigating to the following URLs in your web browser:
- Main Dashboard:
http://127.0.0.1:8050/ - Performance Hub:
http://127.0.0.1:8050/performance
If you wish to retrain the models with new data:
- Prepare Data: Ensure your
data/Post-Processing/CSV_Files/Master_Daily_Features.csvis up to date. - Run Training Script: Execute the training script from the project's root directory. This will overwrite the existing model files in the
/modelsdirectory.python src/modeling/train.py
Contributions to the BreatheEasy project are welcome! If you have suggestions for improvements or find any issues, please feel free to:
- Open an Issue: Describe the bug or feature proposal in detail.
- Fork the Repository: Create your own copy of the project on GitHub.
- Create a Feature Branch: (
git checkout -b feature/AmazingFeature) - Commit Your Changes: (
git commit -m 'Add some AmazingFeature') - Push to the Branch: (
git push origin feature/AmazingFeature) - Open a Pull Request: Create a PR back to the main repository with a clear description of your changes.
This project is distributed under the Apache License, Version 2.0. See the LICENSE and NOTICE files for more information.



