A full-stack weather prediction application that combines real-time weather data from OpenWeatherMap with machine learning predictions using an LSTM model to provide accurate forecasts for Peshawar.
- Primary sensor data — collected at the National Center of Artificial Intelligence (NCAI), UET Peshawar (hosted under CISNR — the Center for Intelligent Systems and Networks Research), using the centre's own on-site weather sensors.
- External / open data —
OpenDatatemperature-and-rain-trends-peshawar-climate.csvwas obtained from an external open-data source (not NCAI sensors). Supplementary datasets also draw on external sources such as Visual Crossing and Kaggle.
- Real-time Weather Data: Fetches current weather conditions from OpenWeatherMap API
- 7-Day Forecast: Provides weather predictions for the next 7 days using LSTM neural network
- Interactive Frontend: React-based UI with charts and visualizations
- Admin Panel: Secure admin interface for managing prediction windows and viewing history
- Caching: Optimized performance with weather data caching and model pre-compilation
- Logging: Comprehensive logging for predictions and API calls
- Flask: Web framework for API endpoints
- TensorFlow/Keras: LSTM model for weather predictions
- NumPy: Numerical computations
- Joblib: Model and scaler serialization
- Requests: HTTP client for OpenWeatherMap API
- React: User interface framework
- Chart.js: Data visualization library
- CSS: Styling
- Python 3.8+
- Node.js 14+
- OpenWeatherMap API Key (required — free tier works; get one at https://openweathermap.org/api)
-
Navigate to the backend directory:
cd backend -
Create a virtual environment (recommended):
python -m venv venv venv\Scripts\activate # On Windows # source venv/bin/activate # On macOS/Linux
-
Install Python dependencies:
pip install -r requirements.txt
-
Navigate to the frontend directory:
cd frontend -
Install Node.js dependencies:
npm install
- Ensure you're in the backend directory and virtual environment is activated
- Run the Flask server:
python app.py
The backend will start on http://localhost:5000
- Open a new terminal and navigate to the frontend directory
- Start the React development server:
npm start
The frontend will start on http://localhost:3000 and proxy API calls to the backend.
- Main Application: http://localhost:3000
- Backend API Home: http://localhost:5000
- Current Weather API: http://localhost:5000/api/current
- Forecast API: http://localhost:5000/api/forecast
GET /- API status and available endpointsGET /api/current- Current weather predictionGET /api/forecast- 7-day weather forecastGET /health- Health check endpointGET /debug_predict- Debug prediction data
POST /api/admin/verify- Verify an admin token (used by the frontend login)GET /api/admin/window- Get current prediction window dataPOST /api/admin/update- Update prediction window data
To access the admin panel:
- Set the
ADMIN_TOKENenv var on the backend to a secret value. If it is left unset, all admin endpoints are disabled. - On the main page, enter that token and click "Login". The token is sent to the backend (
POST /api/admin/verify) and verified server-side with a constant-time comparison — the browser never holds any secret. - Once verified, access advanced features like viewing/modifying the prediction window and history.
Copy backend/.env.example to backend/.env and fill in your values (the .env file is git-ignored).
OPENWEATHER_API_KEY(required): Your OpenWeatherMap API key — get one at https://openweathermap.org/apiADMIN_TOKEN(optional): Secret token for the admin panel. If unset, admin endpoints are disabled entirely. Set it to a strong value to enable admin access.
best_lstm.keras: Trained LSTM modelscaler_X.pkl,scaler_y.pkl: Feature scalerswindow.npy: Current prediction window (30x5 features)history.npy: Prediction historypredictions.log: Application logs
- Model Loading Errors: Ensure all model files (
best_lstm.keras, scalers) are present in the backend directory - API Key Issues: Check your OpenWeatherMap API key if using a custom one
- Port Conflicts: Ensure ports 3000 and 5000 are available
- CORS Errors: The backend has CORS enabled for frontend communication
Check backend/predictions.log for detailed error information.
# Test individual endpoints
curl http://localhost:5000/
curl http://localhost:5000/api/current
curl http://localhost:5000/api/forecastcd frontend
npm testThe React frontend deploys to Vercel as a static site (vercel.json at the repo root handles the build).
- In Vercel, Import this GitHub repo and select the
vercel-deploybranch. - Vercel reads
vercel.jsonautomatically (build:frontend, output:frontend/build). - Add an environment variable
REACT_APP_API_URL= the URL of your deployed backend (seefrontend/.env.example). Leave it unset only for local dev, where the CRA proxy is used. - Deploy.
The Flask backend depends on TensorFlow and keeps persistent state, so it will not run on
Vercel's serverless functions (250 MB size limit + stateless execution). Host it on a container
platform instead — Render, Railway, Fly.io, or Hugging Face Spaces — then point
REACT_APP_API_URL at that deployment. The backend also needs its model files
(best_lstm.keras, scaler_X.pkl, scaler_y.pkl) present at runtime.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request