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 concise weather report with an
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|
|
|
|
| 18 |
temp = data.get('main', {}).get('temp')
|
| 19 |
description = data.get('weather', [{}])[0].get('description')
|
| 20 |
|
| 21 |
+
# Generate a creative weather summary using LangChain LLM
|
| 22 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 23 |
+
system = f"Local weather update for {city}: {temp}°C, {description}. Provide 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 |
+
# Add 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 |
+
# Create the final response string, avoiding repetition
|
| 36 |
+
final_response = f"🌍 Weather Update for {city}: {temp}°C, {humidity}% humidity, described as {description} {weather_emoji}. Insight: {output}"
|
| 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 AI-generated insight."
|
| 47 |
)
|
| 48 |
|
| 49 |
iface.launch()
|