Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from langchain_core.prompts import ChatPromptTemplate
|
|
| 6 |
from langchain_core.output_parsers import StrOutputParser
|
| 7 |
|
| 8 |
def get_weather_and_insight(city):
|
| 9 |
-
#
|
| 10 |
url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={os.getenv("OPENWEATHER_API_KEY")}&units=metric'
|
| 11 |
res = requests.get(url)
|
| 12 |
data = res.json()
|
|
@@ -18,7 +18,7 @@ def get_weather_and_insight(city):
|
|
| 18 |
temp = data.get('main', {}).get('temp')
|
| 19 |
description = data.get('weather', [{}])[0].get('description')
|
| 20 |
|
| 21 |
-
#
|
| 22 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 23 |
system = f"You are a local weather reporter bringing the latest update for {city}. Right now, it's \n🌡️ {temp}°C, degrees Celsius with about 💧 {humidity}% percent humidity. The weather of the city can be best described as {description} with a short fun fact."
|
| 24 |
human = "{text}"
|
|
@@ -29,10 +29,10 @@ def get_weather_and_insight(city):
|
|
| 29 |
chain = prompt | chat | StrOutputParser()
|
| 30 |
output = chain.invoke({"text": city})
|
| 31 |
|
| 32 |
-
#
|
| 33 |
weather_emoji = "☀️" if "clear" in description else "☁️" if "cloud" in description else "🌧️" if "rain" in description else "❄️" if "snow" in description else "🌫️"
|
| 34 |
|
| 35 |
-
#
|
| 36 |
final_response = f"🌍 {city.upper()} Weather Insight: {output} {weather_emoji}"
|
| 37 |
|
| 38 |
return final_response
|
|
|
|
| 6 |
from langchain_core.output_parsers import StrOutputParser
|
| 7 |
|
| 8 |
def get_weather_and_insight(city):
|
| 9 |
+
# Fetching weather data
|
| 10 |
url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={os.getenv("OPENWEATHER_API_KEY")}&units=metric'
|
| 11 |
res = requests.get(url)
|
| 12 |
data = res.json()
|
|
|
|
| 18 |
temp = data.get('main', {}).get('temp')
|
| 19 |
description = data.get('weather', [{}])[0].get('description')
|
| 20 |
|
| 21 |
+
# Generating a creative weather summary using LangChain LLM
|
| 22 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 23 |
system = f"You are a local weather reporter bringing the latest update for {city}. Right now, it's \n🌡️ {temp}°C, degrees Celsius with about 💧 {humidity}% percent humidity. The weather of the city can be best described as {description} with a short fun fact."
|
| 24 |
human = "{text}"
|
|
|
|
| 29 |
chain = prompt | chat | StrOutputParser()
|
| 30 |
output = chain.invoke({"text": city})
|
| 31 |
|
| 32 |
+
# Adding emojis for visual flair
|
| 33 |
weather_emoji = "☀️" if "clear" in description else "☁️" if "cloud" in description else "🌧️" if "rain" in description else "❄️" if "snow" in description else "🌫️"
|
| 34 |
|
| 35 |
+
# Creating the final response string
|
| 36 |
final_response = f"🌍 {city.upper()} Weather Insight: {output} {weather_emoji}"
|
| 37 |
|
| 38 |
return final_response
|