File size: 2,842 Bytes
df265b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

---

# 🌍 AQI Forecasting Web App with Map Visualization

This Flask-based web application allows users to input geographical coordinates (latitude and longitude) and receive air quality forecasts (AQI) for the next three days. It combines a deep learning model with real-time data from the Weatherbit API, and visualizes predictions on an interactive map using Folium.

---

## πŸš€ Features

- 🌐 **Interactive Map**: View AQI predictions across different locations.
- πŸ“‘ **Real-Time Data**: Integrates live air quality data from Weatherbit API.
- 🧠 **Deep Learning Model**: Predicts AQI for the next 3 days based on PM2.5, PM10, NO2, SO2, CO, and current AQI.
- πŸ“Š **Comparative Visualization**: Shows bar plots comparing model predictions and API forecasts.
- πŸ“ **CSV Logging**: Stores prediction data and actual AQI values from API into CSV files.

---

## πŸ› οΈ Setup Instructions

### 1. Clone the Repository

```bash
git clone https://github.com/your-username/aqi-forecast-app.git
cd aqi-forecast-app
```

### 2. Install Requirements

We recommend using a virtual environment.

```bash
pip install -r requirements.txt
```

### 3. Add Your API Key

Replace the `API_KEY` variable in `app.py` with your [Weatherbit API key](https://www.weatherbit.io/account/create).

```python
API_KEY = "your_api_key_here"
```

### 4. Add Model and Scalers

Ensure the following model and scaler files are in the project directory:

- `FUTURE_AQI_v1.json`
- `FUTURE_AQI_v1.weights.h5`
- `scaler_X_cpcb_4.pkl`
- `scaler_y_cpcb_4.pkl`

> These are required to load the trained model and scale inputs/outputs.

### 5. Run the App

```bash
python app.py
```

Visit [http://127.0.0.1:5000](http://127.0.0.1:5000) in your browser.

---

## πŸ“‚ File Structure

```
.
β”œβ”€β”€ app.py                       # Main Flask app
β”œβ”€β”€ FUTURE_AQI_v1.json          # Model architecture
β”œβ”€β”€ FUTURE_AQI_v1.weights.h5    # Trained model weights
β”œβ”€β”€ scaler_X_cpcb_4.pkl         # Scaler for input features
β”œβ”€β”€ scaler_y_cpcb_4.pkl         # Scaler for output predictions
β”œβ”€β”€ aqi_data.csv                # Stores model predictions
β”œβ”€β”€ aqi_data_actual_api.csv     # Stores actual API forecast data
└── templates/
    └── aqi_forecast_with_legend.html  # HTML template
```

---

## πŸ“Š AQI Color Codes

The app uses the following colors for AQI categories:

| AQI Range      | Color        |
|----------------|--------------|
| 0–50           | Green        |
| 51–100         | Light Green  |
| 101–150        | Orange       |
| 151–200        | Red          |
| 201–300        | Purple       |
| 301+           | Gray         |

---

## πŸ“Œ Future Improvements

- πŸ“ Add support for historical AQI trends
- ⏳ Allow user-defined forecasting range
- πŸ“ˆ Deploy on cloud for public access

---