This project is a Streamlit-based web app that uses OpenAI's GPT-4o and the Visual Crossing Weather API to provide weather information based on user input. The app leverages function calling, a cutting-edge feature of OpenAI's GPT-4, to interpret natural language queries and fetch relevant weather data.
- Natural Language Query:
- Users can type questions like "What's the weather like in Karachi today?", and the app intelligently processes the query.
- GPT-4 Function Calling:
- OpenAI's GPT-4 interprets user input and determines the location for which weather data should be fetched.
- Real-Time Weather Data:
- Weather data is fetched from the Visual Crossing Weather API, providing accurate and up-to-date forecasts.
- Streamlit Interface:
- A clean, interactive UI built using Streamlit for seamless user experience.
- Error Handling:
- Robust error messages for invalid inputs or API issues.
- User Query:
- The user types a question about the weather in natural language.
- GPT-4 Function Calling:
- GPT-4 analyzes the query and generates a function call with the location.
- Weather API Integration:
- The app uses the Visual Crossing Weather API to fetch weather data for the specified location.
- Response Display:
- The weather conditions and temperature are displayed on the Streamlit app interface.
- OpenAI GPT-4: For natural language processing and function calling.
- Visual Crossing Weather API: For retrieving real-time weather data.
- Streamlit: For building an interactive and user-friendly web app interface.
- Python: For backend logic and API integration.
- Requests Library: To make HTTP requests to the weather API.
- Purpose: Interprets natural language queries and identifies the location for weather data.
- Feature Used: Function Calling.
- Example Function Call:
{ "name": "get_weather", "parameters": { "type": "object", "properties": { "location": {"type": "string"} } } }
- Purpose: Fetches weather data based on the location provided.
- Endpoint:
https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/forecast - Required Parameters:
locations: Location for weather data.key: API key for authentication.unitGroup: Units for temperature (metricorus).contentType: Response format (e.g.,json).
- Python 3.8 or above.
- API keys for:
- OpenAI: Sign up at OpenAI.
- Visual Crossing Weather API: Get your free key at Visual Crossing.
-
Clone the Repository:
git clone https://github.com/SyedAffan10/WeatherBot-AI.git cd WeatherBot-AI -
Install Dependencies:
pip install -r requirements.txt
-
Place the KEYS:
- Place the keys in the code:
OPENAI_API_KEY=your_openai_api_key VISUALCROSSING_API_KEY=your_visualcrossing_api_key
- Place the keys in the code:
-
Run the Application:
streamlit run app.py
-
Access the App:
- Open the URL displayed in your terminal (e.g.,
http://localhost:8501) in your web browser.
- Open the URL displayed in your terminal (e.g.,
WeatherBot-AI/
│
├── app.py # Main Streamlit app
├── requirements.txt # Python dependencies
├── README.md # Project documentation
- Input:
- Type: "What's the weather in Karachi today?"
- Output:
- "The weather in Karachi is clear with a temperature of 30°C."
- Add multi-day forecasts.
- Implement voice input for queries.
- Support multiple units (Celsius/Fahrenheit).
- Include additional weather details like humidity and wind speed.