Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,13 +5,14 @@ from langchain_huggingface import HuggingFaceEndpoint
|
|
| 5 |
from langchain_core.messages import BaseMessage, HumanMessage
|
| 6 |
from langgraph.graph import MessageGraph, END
|
| 7 |
from typing import Sequence
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# streamlit app
|
| 10 |
st.title("City Weather Information with AI Review")
|
| 11 |
-
OPENWEATHER_API_KEY = st.sidebar.text_input("Enter Weather API Key", type="password")
|
| 12 |
-
st.sidebar.write("Check out this [Weather API](https://home.openweathermap.org/api_keys) to generate API key")
|
| 13 |
-
HF_TOKEN = st.sidebar.text_input("Enter Hugging Face API Key", type="password")
|
| 14 |
-
st.sidebar.write("Check out this [Hugging Face Token](https://huggingface.co/settings/tokens) to generate token")
|
| 15 |
city = st.text_input("Enter the name of a city:")
|
| 16 |
|
| 17 |
# Initialize the HuggingFace inference endpoint
|
|
@@ -25,7 +26,7 @@ llm = HuggingFaceEndpoint(
|
|
| 25 |
# Define nodes
|
| 26 |
def fetch_weather_node(state: Sequence[BaseMessage]) -> str:
|
| 27 |
city = state[0].content.strip()
|
| 28 |
-
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={
|
| 29 |
|
| 30 |
try:
|
| 31 |
response = httpx.get(url)
|
|
|
|
| 5 |
from langchain_core.messages import BaseMessage, HumanMessage
|
| 6 |
from langgraph.graph import MessageGraph, END
|
| 7 |
from typing import Sequence
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
load_dotenv()
|
| 11 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 12 |
+
WEATHER_TOKEN = os.getenv("WEATHER_TOKEN")
|
| 13 |
|
| 14 |
# streamlit app
|
| 15 |
st.title("City Weather Information with AI Review")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
city = st.text_input("Enter the name of a city:")
|
| 17 |
|
| 18 |
# Initialize the HuggingFace inference endpoint
|
|
|
|
| 26 |
# Define nodes
|
| 27 |
def fetch_weather_node(state: Sequence[BaseMessage]) -> str:
|
| 28 |
city = state[0].content.strip()
|
| 29 |
+
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={WEATHER_TOKEN}&units=metric"
|
| 30 |
|
| 31 |
try:
|
| 32 |
response = httpx.get(url)
|