How 22bet10009-shuvam/aerosence works
Project type and purpose
• This is a full-stack, single-page web application built with Flask (Python) on the backend and a lightweight JavaScript/CSS frontend.
• Purpose: Let users search any location, fetch current weather from Open-Meteo, and predict PM2.5 via a hybrid ML pipeline (RandomForest + ExtraTrees) or a heuristic fallback.
File structure
Top level
• app.py – Flask app defining HTTP endpoints, ties together weather API calls and ML inference.
• requirements.txt – lists Python dependencies (Flask, scikit-learn, joblib, requests, etc.).
• README.md, ABSOLUTE_DETAIL.txt – documentation.
Directories
• templates/index.html – single‐page app shell.
• static/app.js, static/style.css – client logic and dark UI styling.
• ml/
– train_hybrid.py: offline training script producing pm25_pipeline.pkl
– features.py, eval_cv.py: feature engineering and evaluation modules
– last_metrics.json: stored evaluation results
– (after training) pm25_pipeline.pkl: serialized pipeline (feature transformer + hybrid model)
• data/pm25_weather_kaggleish.csv – example dataset used by train_hybrid.py (synthetic by default).
README for additional insights
• Confirms no API keys required (Open-Meteo geocoding+forecast).
• Describes the fallback heuristic if the model is missing.
• Mentions offline training workflow separated from runtime inference.
a. Main components
1) Client (Browser SPA)
– index.html, app.js, style.css
2) Flask Backend
– HTTP endpoints: search → /geocode & /forecast to Open-Meteo, /predict → local ML
3) External Weather Service
– Open-Meteo Geocoding API
– Open-Meteo Forecast API
4) ML Inference
– pm25_pipeline.pkl loaded at startup
– feature engineering (ml/features.py)
– hybrid model (RandomForest + ExtraTrees with log1p transform)
– fallback heuristic logic
5) Offline Training (optional, separate flow)
– train_hybrid.py
– data/pm25_weather_kaggleish.csv or real dataset
– output: pm25_pipeline.pkl
b. Relationships and data flow
1) User enters location in UI → app.js sends AJAX to Flask /search endpoint.
2) Flask → calls Open-Meteo geocoding → returns lat/lon.
3) Flask → calls Open-Meteo weather → returns temperature, humidity, wind speed, etc.
4) Flask → passes weather features into pm25_pipeline (or heuristic) → PM2.5 prediction.
5) Flask → bundles weather + PM2.5 → JSON response back to client.
6) Client → renders results in UI.
7) Offline: Developer runs python ml/train_hybrid.py → trains new pipeline → serializes to .pkl.
c. Architectural patterns/design principles
• Separation of concerns:
– Presentation (SPA) vs. Business logic (Flask) vs. ML inference vs. Data training.
• API‐driven backend with clear REST endpoints.
• Modular ML pipeline (scikit-learn Pipeline, feature modules).
• Fallback to ensure uptime (heuristic rule when no model).
d. Key technologies/frameworks
• Backend: Python, Flask
• ML: scikit-learn (RandomForest, ExtraTrees), joblib/pickle for serialization
• Frontend: vanilla JavaScript (fetch API), CSS (animated skeleton loaders)
• External: Open-Meteo APIs