Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,9 +18,9 @@ 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"
|
| 24 |
human = "{text}"
|
| 25 |
prompt = ChatPromptTemplate.from_messages(
|
| 26 |
[("system", system), ("human", human)]
|
|
@@ -29,11 +29,11 @@ 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"
|
| 37 |
|
| 38 |
return final_response
|
| 39 |
|
|
@@ -43,7 +43,7 @@ iface = gr.Interface(
|
|
| 43 |
inputs=gr.Textbox(label="Enter City Name", placeholder="Type city here..."),
|
| 44 |
outputs=gr.Textbox(label="Weather Report and Insight"),
|
| 45 |
title="WeatherAssistantApp",
|
| 46 |
-
description="Enter a city name to get a
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
|
|
|
| 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"Today in {city}, it feels like {temp}°C with {humidity}% humidity. The sky is {description}. Can you share a fun fact about {city}?"
|
| 24 |
human = "{text}"
|
| 25 |
prompt = ChatPromptTemplate.from_messages(
|
| 26 |
[("system", system), ("human", human)]
|
|
|
|
| 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()} Update: {output} {weather_emoji}"
|
| 37 |
|
| 38 |
return final_response
|
| 39 |
|
|
|
|
| 43 |
inputs=gr.Textbox(label="Enter City Name", placeholder="Type city here..."),
|
| 44 |
outputs=gr.Textbox(label="Weather Report and Insight"),
|
| 45 |
title="WeatherAssistantApp",
|
| 46 |
+
description="Enter a city name to get a concise weather report with an engaging AI-generated city insight."
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|