Weather_Simulation / README.md
theabeerrai's picture
Update README.md
1f15b4e verified
---
title: Weather Simulation & Traffic Risk
emoji: 🌦️
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
---
# 🌦️ Weather-Traffic Risk Prediction Pipeline
This project implements a full E2E pipeline that fetches weather data, cleans it, performs feature engineering, and uses a Machine Learning model to predict traffic risk.
## πŸš€ Components
1. **Weather Pipeline (`weather_pipeline.py`)**:
* Fetches real-time data from **WeatherAPI.com**.
* Handles missing values and normalizes conditions (Rainy, Cloudy, etc.).
* Calculates a "Risk Score" based on heuristics.
* Implements caching (10 min) to optimize API usage.
2. **ML Model (`model.py`)**:
* Uses a **Random Forest Classifier** trained on synthetic data.
* Predicts `Low`, `Medium`, or `High` traffic risk based on temperature, rainfall, and weather condition.
* Includes a training script to generate baseline patterns.
3. **FastAPI Server (`app.py`)**:
* Exposes a REST API endpoint: `/weather/{city}`.
* Returns structured JSON with weather details and ML risk prediction.
* Visual alerts (Green/Yellow/Red) included in responses.
## πŸ› οΈ Setup
1. **Install dependencies**:
```bash
pip install -r requirements.txt
```
2. **Configure API Key**:
* Open `.env` and replace `your_api_key_here` with your OpenWeather API key.
3. **Run the Server**:
```bash
python app.py
```
4. **Test the endpoint**:
* Open `http://localhost:8000/weather/Dehradun` in your browser.
## πŸ“Š Output Format
```json
{
"city": "Dehradun",
"weather": {
"temperature": 28,
"rainfall_1h": 12,
"condition": "Rainy",
"base_risk_score": 3
},
"ml_prediction": {
"traffic_risk_level": "High",
"confidence": 0.89,
"status_color": "πŸ”΄ Red"
}
}
```
## πŸ€— Deploying to Hugging Face Spaces
This project is configured for easy deployment on Hugging Face using Docker.
1. **Create a New Space**:
* Go to [huggingface.co/new-space](https://huggingface.co/new-space).
* Select **Docker** as the SDK.
* Choose the **Blank** template or upload your files directly.
2. **Add Secret (API Key)**:
* In your Space settings, go to **Variables and secrets**.
* Add a new secret named `WEATHER_API_KEY` and paste your key.
3. **Upload Files**:
* Upload `app.py`, `weather_pipeline.py`, `model.py`, `requirements.txt`, `Dockerfile`, and the `.pkl` files.
* Hugging Face will automatically build and deploy your container on port 7860.
4. **Test**:
* Access your API at `https://huggingface.co/spaces/[YOUR_USERNAME]/[YOUR_SPACE_NAME]/weather/Dehradun`.