Predicting air quality with cutting-edge deep learning and IoT integration
Live Dashboard | Backend API (HF Space) | Project Documentation | Contributors
VAYU is a production-grade air quality intelligence platform that combines advanced machine learning architectures with real-time IoT sensor networks. The system predicts Air Quality Index (AQI) with unprecedented accuracy by leveraging novel time-series deep learning models and real-world sensor data.
- 54.2% TypeScript (Next.js frontend, real-time visualization)
- 33.5% Jupyter Notebooks (ML research, model experimentation)
- 7.7% Python (FastAPI backend, data processing pipelines)
- 3% C++ (Arduino firmware for IoT edge devices)
- 1.6% CSS (UI styling and animations)
Multi-Architecture Model Comparison & Selection
- LSTM/GRU/SimpleRNN: Classical recurrent architectures for sequential dependency learning
- Temporal Convolutional Networks (TCN): Dilated convolutions for efficient long-range dependencies
- TKAN (Temporal Kolmogorov-Arnold Networks): Novel KAN-based architecture with improved expressiveness
- TKAT: Advanced temporal attention-based model for complex temporal patterns
Performance Metrics (on validation set):
| Model | MAE | RMSE | MAPE | Training Time |
|---|---|---|---|---|
| TKAT | 7.19 | 12.04 | 0.015 | 132.7s |
| TKAN | 7.42 | 11.20 | 0.016 | 14.2s |
| TCN | 7.52 | 11.38 | 0.016 | 16.6s |
| LSTM | 7.68 | 11.19 | 0.016 | 6.6s |
Multi-Source Data Ingestion
- Open-Meteo API: Historical and real-time weather data (temperature, humidity)
- Open-Meteo Air Quality API: PM2.5, PM10, CO, NO₂, O₃ measurements
- IoT Sensor Network: Custom ESP32-based nodes with:
- MQ-7 electrochemical CO sensor
- PMS5003 optical particulate matter sensor
- DS18B20 temperature sensor
- Firebase Realtime Database integration
Data Processing Pipeline
- Automatic missing data interpolation
- MinMax normalization for feature scaling
- Lagged feature engineering (1, 3, 6, 12, 24-hour lags)
- Time-series windowing for sequential model input
- 80/20 train-test split with chronological ordering
Backend (Python FastAPI)
- RESTful
/predictendpoint for AQI forecasting - Custom MinMaxScaler implementation with state persistence
- Keras/JAX model inference with custom layer support
- Real-time data retrieval and preprocessing
- Comprehensive error handling and logging
- Hosted on: Hugging Face Spaces (free tier with auto-sleep)
Frontend (Next.js 15 + TypeScript)
- Real-time AQI visualization with Recharts
- Interactive maps for geographic coverage
- React Query integration for data management
- Radix UI component library for accessible UI
- Tailwind CSS for responsive design
- Google Genkit AI integration for enhanced insights
- Live at: vayudashboard.vercel.app
Hardware Layer (C++)
- Multi-sensor data aggregation
- WiFi connectivity via ESP32 microcontroller
- Secure HTTPS communication with Firebase
- Hardware abstraction for sensor calibration
- NTP time synchronization
# AQI Calculation (Indian Standards)
# Pollutant-specific breakpoints with linear interpolation
# Maximum sub-index across all pollutants determines overall AQI
def calculate_sub_index(concentration, breakpoints, aqi_values):
# Linear interpolation between breakpoint ranges
# Returns AQI sub-index for individual pollutant- Python 3.8+
- Node.js 18+ (for frontend)
- ESP32 microcontroller (optional, for IoT sensors)
- CUDA/GPU support (optional, for faster training)
Option 1: Use Live Endpoints (Recommended for testing)
# Frontend Dashboard
https://vayudashboard.vercel.app
# Backend API (Hugging Face Spaces)
https://huggingface.co/spaces/nikethanreddy/project
# Note: HF Spaces auto-sleep after inactivity
# → Click "Restart" button on the Space page if you get timeout errors# Clone repository
git clone https://github.com/dsid271/VAYU.git
cd VAYU
# Install Python dependencies
pip install -r requirements.txt
# Environment configuration
export KERAS_BACKEND=jax # or tensorflow, torch
export JAX_PLATFORMS=cpu # or cuda for GPU
export JAX_ENABLE_X64=True
# Start FastAPI server
uvicorn VAYU_website.app:app --reload --host 0.0.0.0 --port 8000
# API will be available at http://localhost:8000
# Swagger UI docs: http://localhost:8000/docscd VAYU_website
# Install dependencies
npm install
# Development server with Turbopack
npm run dev # Runs on http://localhost:9002
# Build for production
npm run build
npm start# Launch Jupyter
jupyter notebook notebooks/
# Open and run: Revised_Time_Series_Forecast_Code.ipynb// Configure in cpp/IoT_Node_Sketch.ino:
#define WIFI_SSID "YOUR_NETWORK"
#define WIFI_PASSWORD "YOUR_PASSWORD"
#define FIREBASE_PROJECT_ID "your-project"
#define FIREBASE_DATABASE_SECRET "your-secret"
// Upload to ESP32 via Arduino IDEVAYU/
├── notebooks/
│ └── Revised_Time_Series_Forecast_Code.ipynb
│ ├── Data loading & preprocessing (AQI calculation)
│ ├── Feature engineering (lagged features)
│ ├── Model training (6 architectures)
│ ├── Hyperparameter tuning
│ └── Evaluation & visualization
│
├── VAYU_website/
│ ├── app.py # FastAPI backend
│ │ ├── MinMaxScaler implementation
│ │ ├── Real-time data retrieval
│ │ ├── Model inference pipeline
│ │ └── /predict endpoint
│ │
│ ├── src/
│ │ ├── app/ # Next.js pages
│ │ ├── components/ # React components
│ │ ├── ai/ # Google Genkit integration
│ │ └── lib/ # Utilities & hooks
│ │
│ ├── package.json # Frontend dependencies
│ ├── tailwind.config.ts # Styling configuration
│ └── tsconfig.json # TypeScript config
│
├── cpp/
│ └── IoT_Node_Sketch.ino # ESP32 firmware
│ ├── WiFi & NTP synchronization
│ ├── Sensor initialization (MQ-7, PMS5003, DS18B20)
│ ├── Data aggregation & validation
│ └── Firebase Realtime DB push
│
├── requirements.txt # Python dependencies
├── README.md # This file
└── LICENSE # MIT License
- Temporal Lags: 1, 3, 6, 12, 24-hour history captures multiple temporal scales
- Multi-Pollutant Input: PM2.5, PM10, CO, NO₂, O₃ interdependencies
- Normalization: MinMax scaling (0-1) for stable gradient flow
- Sequence Length: Adaptive timestep configuration for model compatibility
Input (T, 5 features)
↓
TKAN Layer (64 units, KAN-based)
↓
Dense Layer (1 output)
↓
Inverse Transform → AQI Prediction
- Advantages: Parameter efficiency, improved generalization, non-linear activation
- Trade-off: Longer training time (14.2s vs LSTM's 6.6s)
- Validation: Best RMSE (11.20) and competitive MAE (7.42)
# Training: fit on training data distribution
scaler.fit(X_train)
X_scaled = scaler.transform(X_train)
# Inference: apply same transformation
X_test_scaled = scaler.transform(X_test)
# Post-prediction: inverse transform with rolling median proxy
predictions = target_scaler.inverse_transform(model_output)Endpoint: POST /predict
Request:
{
"latitude": 28.7041,
"longitude": 77.1025,
"pm25": 45.2,
"pm10": 78.5,
"co": 1.2,
"temp": 25.3,
"n_ahead": 1
}Response:
{
"status": "success",
"message": "Prediction successful.",
"predictions": [
{
"timestamp": "2025-08-30 15:00:00",
"aqi": 78.5
}
]
}Data Flow:
- Fetch last 24 hours from Open-Meteo APIs
- Validate & interpolate missing values
- Calculate AQI using Indian standard breakpoints
- Scale using stored scaler attributes
- Run model inference (JAX backend for speed)
- Inverse transform predictions
- Return timestamped forecasts
ESP32 Sensor Node
- MQ-7 CO Sensor: Electrochemical sensing with Rs/R0 ratio calibration
- PMS5003 Particulate: Serial UART communication (9600 baud)
- DS18B20 Temperature: 1-Wire protocol with checksum validation
- Firebase Sync: HTTPS POST with authentication
- Update Interval: Hourly with 60-second warmup
Calibration Formula:
CO (ppm) = 99.042 × (Rs/R0)^(-1.518) # MQ-7 characteristic curve
CO (µg/m³) = CO (ppm) × 1145.0 # PPM to mass conversion
- Best Accuracy: TKAT (MAE: 7.19)
- Best Speed: SimpleRNN (5.06s training)
- Best Balance: TKAN (14.2s, MAE: 7.42)
- Production Choice: TKAN (fast enough, best reliability)
- API Response Time: ~2-3 seconds (Open-Meteo)
- Data Processing: ~1 second (preprocessing & scaling)
- Model Inference: ~100-500ms (depends on backend)
- End-to-End Latency: <5 seconds (local) / ~10-15s (HF Spaces)
- Concurrent Users: Horizontal scaling via Docker/Kubernetes
- Database: Firebase Realtime DB (scales to thousands of nodes)
- Frontend: Vercel deployment with edge caching
- Model Serving: Single instance handles ~100 req/s
- Tier: Free tier (Community GPU optional)
- Auto-Sleep: Spaces sleep after 48 hours of inactivity
- Cold Start: ~20-30 seconds on first request after sleep
- Restart: Manual restart button available on Space page
- Persistent Storage: Model weights preserved across restarts
# Backend tests
pytest VAYU_website/tests/
# Frontend tests
npm run test
# Type checking
npm run typecheck# In Jupyter notebook:
# 1. Load new data: pd.read_csv('new_air_quality_data.csv')
# 2. Run feature engineering pipeline
# 3. Train all 6 models
# 4. Compare metrics and save best model
# 5. Export scalers as JSON for inference# Production build
npm run build
# Deployment to Vercel (auto from git push)
git push origin main# 1. Create Space on Hugging Face Hub
# 2. Configure app.py as entry point
# 3. Add requirements.txt
# 4. Push to Space repository
# 5. Space auto-deploys from git- keras - Deep learning framework
- numpy, pandas - Numerical computing & data manipulation
- scikit-learn - Preprocessing & metrics
- jax - JAX backend for Keras
- fastapi - Web framework
- requests - API calls
- tensorflow - Alternative to JAX backend
- Next.js 15 - React framework with Turbopack
- React 18 - UI library
- Tailwind CSS - Utility-first styling
- Recharts - Chart visualization
- React Query - Server state management
- Radix UI - Accessible component library
- Google Genkit - AI/ML integration
- Arduino Core for ESP32
- OneWire - DS18B20 communication
- DallasTemperature - Temperature sensor library
- Multi-location forecasting with geographic interpolation
- LSTM attention mechanisms for feature importance
- Graph Neural Networks for spatial correlations
- Mobile app (React Native)
- Real-time alert system with notifications
- Model interpretability (SHAP values, attention visualization)
- Ensemble models combining multiple architectures
- Federated learning for privacy-preserving deployment
- Paid HF Spaces tier for zero cold-start latency
See detailed methodology in notebooks/Revised_Time_Series_Forecast_Code.ipynb
Interactive API docs available at:
- Local:
http://localhost:8000/docs(Swagger UI) - Live (HF Spaces): Available via Space interface
See cpp/README.md for ESP32 flashing and sensor calibration
- dsid271 - ML Architecture, Backend Development, Frontend Engineering
- sreenikethanreddy - Full-Stack Development, Hardware Integration, HF Spaces Deployment
This project is licensed under the MIT License - see LICENSE for details.
- Time Kolmogorov-Arnold Networks (TKAN) - Inspired our advanced architecture
- Open-Meteo - Real-time weather & air quality data
- Firebase - Real-time database and deployment platform
- Hugging Face - Free GPU compute and Space hosting
- Vercel - Frontend deployment infrastructure
- Keras/JAX Community - Excellent documentation and support
For questions, issues, or collaboration inquiries:
- Open an Issue
- Check Discussions
- Visit Live Dashboard
- Test Backend API
Made with ❤️ for cleaner air and smarter predictions