Skip to content

A weather app that integrates OpenAI's GPT model with OpenWeatherMap API to deliver precise and up-to-date weather forecasts.

Notifications You must be signed in to change notification settings

gurveenkaur6/real-time-weather-forecast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Real-time-weather-forecast

A weather app that integrates OpenAI's GPT model with OpenWeatherMap API to deliver precise and up-to-date weather forecasts.

Table of Contents

Overview

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.

Features

  • Extracts city name from user input.
  • Retrieves weather information from OpenWeatherMap API.
  • Provides temperature in both Celsius and Fahrenheit.

Prerequisites

  • Python 3.7 or higher
  • pip for package management
  • .env file for API keys

Setup and Running

  1. Clone the repository

    git clone https://github.com/your-username/weather-info-app.git
    cd weather-info-app
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the required packages

    pip install -r requirements.txt
  4. 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
    

Running the Application

  1. Run the Streamlit app

    streamlit run app.py
  2. Open the app in your browser at http://localhost:8501.

Usage

  1. Enter your location in the "Enter your location" field.
  2. Click the "Get Weather" button to fetch weather information.
  3. Review the weather report displayed on the screen.

Code Overview

  • 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.

Code Components

  1. 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")
  2. 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.
  3. 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()
  4. Streamlit App Configuration

    st.set_page_config(page_title="Weather Information App", page_icon="🌦️", layout="wide")
    st.markdown("...")

App Usage ScreenShorts

Screenshot 2024-07-29 at 5 12 57 PM

App Trace in LangSmith

Screenshot 2024-07-29 at 5 14 13 PM

App workflow matplotlib graph

Screenshot 2024-07-29 at 5 23 01 PM

About

A weather app that integrates OpenAI's GPT model with OpenWeatherMap API to deliver precise and up-to-date weather forecasts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages