A modern, interactive weather application built with Streamlit that provides real-time weather information, advanced machine learning-powered forecasting, and AI-powered local event recommendations based on current weather conditions.
- Real-time weather data from Open-Meteo API
- Dual location detection:
- Automatic geolocation using Streamlit's geolocation module
- Manual location search with text input and geocoding
- Interactive map showing your current location
- Comprehensive weather details including:
- Temperature (Celsius/Fahrenheit) with unit conversion
- Weather conditions with detailed WMO code descriptions
- Current date and local time display
- Wind speed with appropriate units (km/h or mph)
- Advanced 5-Day Weather Forecast powered by machine learning:
- WeatherHistoricalAnalyzer class for sophisticated data processing
- Historical weather data analysis (up to 1 year of data)
- Random Forest models with feature engineering
- Lagged features and rolling averages for improved accuracy
- Temperature predictions for the next 5 days
- Weather condition forecasts with meteorological logic
- Seasonal pattern analysis and day-of-year matching
- Realistic weather variation and randomness
- Local event discovery using SerpAPI
- Weather-appropriate recommendations powered by ChatGPT (GPT-4o-mini)
- Smart clothing suggestions based on current weather conditions
- Personalized event filtering considering weather suitability
- Contextual recommendations with specific location addresses
- Clean, modern interface with Streamlit
- Dual view modes: Weather Info and Local Events
- Consistent styling across current weather and forecast sections
- Intuitive layout with weather icons and clear information hierarchy
- Responsive design with sidebar navigation
- Real-time updates with intelligent caching for optimal performance
- Comprehensive error handling with user-friendly messages
- Session state management for persistent user experience
- Python 3.11 or higher
- API keys for:
- OpenAI (for AI recommendations)
- SerpAPI (for local events)
-
Clone the repository
git clone https://github.com/c85/weather-app-streamlit/ cd weather-app-streamlit -
Install dependencies
pip install -r requirements.txt
-
Set up secrets for local development Copy the example secrets file and add your API keys:
cp .streamlit/secrets.toml.example .streamlit/secrets.toml
Then edit
.streamlit/secrets.tomlwith your actual API keys:SERPAPI_API_KEY = "your_serpapi_key_here" OPENAI_API_KEY = "your_openai_key_here"
-
Run the application
streamlit run app.py
-
Open your browser Navigate to
http://localhost:8501
-
Build the Docker image
docker build -t weather-app . -
Run the container
docker run -p 8501:8501 weather-app
Note: For Docker deployment, you'll need to set up secrets through your deployment platform. The Dockerfile includes both
app.pyandhistorical.pyfiles. -
Access the app Open
http://localhost:8501in your browser
-
OpenAI API Key
- Sign up at OpenAI
- Create an API key in your dashboard
- Used for AI-powered event recommendations
-
SerpAPI Key
- Sign up at SerpAPI
- Get your API key from the dashboard
- Used for fetching local events
- Open-Meteo: Weather data, geocoding, and historical weather data
- SerpAPI: Local event discovery
- OpenAI: AI recommendations
- Nominatim: Geocoding and reverse geocoding services
- streamlit: Web application framework
- pandas: Data manipulation and analysis
- numpy: Numerical computing
- scikit-learn: Machine learning algorithms
- requests: HTTP library for API calls
- openai: OpenAI API client
- streamlit-geolocation: Browser geolocation integration
- python-dateutil: Date/time utilities
- pytz: Timezone handling
weather-app-streamlit/
βββ app.py # Main Streamlit application
βββ historical.py # WeatherHistoricalAnalyzer class for ML forecasting
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ README.md # Project documentation
app.py: Main application with UI, location services, and weather displayhistorical.py: Machine learning engine for weather forecastingrequirements.txt: All necessary Python packagesDockerfile: Container configuration for deployment
- Frontend: Streamlit web interface with responsive design
- Backend: Python with intelligent caching and session management
- APIs: RESTful API integrations with error handling
- AI: OpenAI GPT-4o-mini for intelligent recommendations
- ML Engine: Custom WeatherHistoricalAnalyzer class for forecasting
- Automatic Detection: Streamlit's geolocation module
- Manual Search: Text-based location search with geocoding
- Reverse Geocoding: Nominatim API for location resolution
- Fallback Handling: Graceful degradation when location services fail
- Real-time Data: Open-Meteo API for current weather
- Historical Data: Open-Meteo Archive API for ML training
- Data Processing: Pandas and NumPy for data manipulation
- Feature Engineering: Advanced meteorological feature creation
- Data Collection: Fetches up to 1 year of historical weather data
- Feature Engineering:
- Time-based features (hour, day_of_year, month, day_of_week)
- Lagged features (1h, 2h, 3h, 6h, 12h, 24h delays)
- Rolling averages (6h, 12h, 24h windows)
- Meteorological parameters (temperature, humidity, pressure, etc.)
- Data Preprocessing: MinMaxScaler for feature normalization
- Model Training: Random Forest with scikit-learn
- Prediction Pipeline: Multi-step forecasting with feature updates
- Weather Logic: Meteorological rules for weather condition determination
- Event Discovery: SerpAPI for local event data
- Contextual Analysis: Weather-aware event filtering
- Recommendation Engine: GPT-4o-mini for personalized suggestions
- Clothing Advice: Weather-appropriate attire recommendations
- Historical Data: 1-hour TTL for expensive API calls
- Current Weather: 5-minute TTL for real-time updates
- Geocoding: 10-minute TTL for location services
- AI Responses: 5-minute TTL for event recommendations
- Streamlit Caching: Optimized with proper parameter handling
- Intelligent Caching: Multi-tier caching strategy for optimal performance
- Error Handling: Comprehensive error management with user feedback
- Session Management: Persistent state across user interactions
- Responsive Design: Adaptive layout for various screen sizes
- Health Checks: Docker health monitoring for deployment
- Memory Management: Efficient data handling for large datasets
- Launch the app and choose your preferred temperature unit (Β°F or Β°C)
- Select location method:
- Automatic: Click "π Get Weather" to use your device's location
- Manual: Enter a city name or address in the "Location Search" field
- Allow location permissions when prompted (for automatic detection)
- View current weather with comprehensive details:
- Current temperature and weather conditions
- Date and local time
- Interactive map showing your location
- Explore 5-day forecast powered by machine learning:
- Temperature predictions for the next 5 days
- Weather condition forecasts with meteorological accuracy
- Seasonal pattern analysis for improved predictions
- Switch to "Local Events" using the sidebar radio button
- Get AI recommendations based on current weather:
- Weather-appropriate event suggestions
- Smart clothing recommendations
- Personalized filtering based on conditions
- Clear location data using the "ποΈ Clear Location" button
- Switch between view modes using the sidebar
- Change temperature units at any time (updates all displays)
Create .streamlit/secrets.toml:
SERPAPI_API_KEY = "your_serpapi_key_here"
OPENAI_API_KEY = "your_openai_key_here"Add secrets through the web interface in your app settings.
- Temperature units (Celsius/Fahrenheit)
- Caching duration (configurable TTL)
- Weather code descriptions (WMO codes)
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
For support, please open an issue in the GitHub repository or contact the development team.
Built with β€οΈ using Streamlit, OpenAI, and modern web APIs