ArceusInception commited on
Commit
5352f4b
·
verified ·
1 Parent(s): cbda721

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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
- # Fetch 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,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
- # Generate 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,10 +29,10 @@ def get_weather_and_insight(city):
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
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