A weather app that integrates OpenAI's GPT model with OpenWeatherMap API to deliver precise and up-to-date weather forecasts.
The Weather Information App provides real-time weather information for any location using OpenAI's GPT model and the OpenWeatherMap API. It leverages LangGraph workflow to process user input and retrieve accurate weather data.
- Extracts city name from user input.
- Retrieves weather information from OpenWeatherMap API.
- Provides temperature in both Celsius and Fahrenheit.
- Python 3.7 or higher
- pip for package management
- .env file for API keys
-
Clone the repository
git clone https://github.com/your-username/weather-info-app.git cd weather-info-app
-
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages
pip install -r requirements.txt
-
Set up environment variables
Create a
.env
file in the root directory of the project and add your API keys:OPENWEATHERMAP_API_KEY=your_openweathermap_api_key OPENAI_API_KEY=your_openai_api_key
-
Run the Streamlit app
streamlit run app.py
-
Open the app in your browser at http://localhost:8501.
- Enter your location in the "Enter your location" field.
- Click the "Get Weather" button to fetch weather information.
- Review the weather report displayed on the screen.
- Environment Configuration: Loads API keys from the
.env
file and sets up Langsmith tracing. - LangChain Workflow: Defines a graph with nodes for extracting city names, fetching weather data, and providing temperature information.
- Streamlit Interface: Provides a user-friendly interface for inputting location and viewing results.
-
Environment Setup
load_dotenv() os.environ["OPENWEATHERMAP_API_KEY"] = os.environ.get("OPENWEATHERMAP_API_KEY") os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
-
Function Definitions
function_1
: Extracts city name from user input using GPT-3.5-turbo.function_2
: Fetches weather data using the OpenWeatherMap API.function_3
: Generates temperature information in Celsius and Fahrenheit.
-
LangChain Graph Workflow
workflow = Graph() workflow.add_node("agent", function_1) workflow.add_node("tool", function_2) workflow.add_node("responder", function_3) workflow.add_edge('agent', 'tool') workflow.add_edge('tool', 'responder') workflow.set_entry_point("agent") workflow.set_finish_point("responder") app = workflow.compile()
-
Streamlit App Configuration
st.set_page_config(page_title="Weather Information App", page_icon="🌦️", layout="wide") st.markdown("...")