ArceusInception commited on
Commit
29771be
·
verified ·
1 Parent(s): 0d69cd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,20 +1,20 @@
1
  import gradio as gr
2
  import requests
3
  import os
4
- from groq import Groq
5
 
6
- def get_weather(city_name):
7
  # Initialize the Groq client with your API key
8
  groq_client = Groq(api_key=os.getenv("GROQ_API_KEY"))
9
 
10
- # Use Groq to interpret the city name (this is a simplified example, adjust based on actual API usage)
11
- processed_city = groq_client.interpret(city_name)
12
 
13
  API_Key = os.getenv("OPENWEATHER_API_KEY")
14
  if not API_Key:
15
  return "API Key is not set. Please set the OPENWEATHER_API_KEY environment variable."
16
 
17
- url = f'https://api.openweathermap.org/data/2.5/weather?q={processed_city}&appid={API_Key}&units=metric'
18
  response = requests.get(url)
19
 
20
  if response.status_code == 200:
@@ -23,21 +23,19 @@ def get_weather(city_name):
23
  temp = data['main']['temp']
24
  humidity = data['main']['humidity']
25
 
26
- # Adding emojis and creative text
27
  weather_emoji = "☀️" if "clear" in weather else "☁️" if "cloud" in weather else "🌧️" if "rain" in weather else "❄️" if "snow" in weather else "🌫️"
28
- return (f"In {processed_city}, the weather is currently {weather} {weather_emoji}. "
29
- f"The temperature is a comfy {temp}°C 🌡️. "
30
- f"Also, humidity levels are at {humidity}%, so keep hydrated! 💧")
31
  else:
32
  return "Failed to retrieve data. Please check the city name and try again."
33
 
34
  # Define Gradio interface
35
  iface = gr.Interface(
36
- fn=get_weather,
37
  inputs=gr.Textbox(label="Enter City Name", placeholder="Type here..."),
38
- outputs=gr.Textbox(label="Weather Update"),
39
  title="WeatherAssistantApp",
40
- description="Enter a city name to get a lively description of the current weather, temperature, and humidity."
41
  )
42
 
43
  # Launch the interface
 
1
  import gradio as gr
2
  import requests
3
  import os
4
+ from groq import Groq # Assuming Groq or a similar LLM can provide insights
5
 
6
+ def get_weather_and_insight(city_name):
7
  # Initialize the Groq client with your API key
8
  groq_client = Groq(api_key=os.getenv("GROQ_API_KEY"))
9
 
10
+ # Use Groq to get a short insight about the city
11
+ insight = groq_client.get_insight(city_name, max_words=10) # Assumed method and parameter
12
 
13
  API_Key = os.getenv("OPENWEATHER_API_KEY")
14
  if not API_Key:
15
  return "API Key is not set. Please set the OPENWEATHER_API_KEY environment variable."
16
 
17
+ url = f'https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={API_Key}&units=metric'
18
  response = requests.get(url)
19
 
20
  if response.status_code == 200:
 
23
  temp = data['main']['temp']
24
  humidity = data['main']['humidity']
25
 
 
26
  weather_emoji = "☀️" if "clear" in weather else "☁️" if "cloud" in weather else "🌧️" if "rain" in weather else "❄️" if "snow" in weather else "🌫️"
27
+ return (f"🔍 {insight} | In {city_name}, it's {weather} {weather_emoji}. "
28
+ f"Temperature: {temp}°C 🌡️, Humidity: {humidity}% 💧")
 
29
  else:
30
  return "Failed to retrieve data. Please check the city name and try again."
31
 
32
  # Define Gradio interface
33
  iface = gr.Interface(
34
+ fn=get_weather_and_insight,
35
  inputs=gr.Textbox(label="Enter City Name", placeholder="Type here..."),
36
+ outputs=gr.Textbox(label="Weather Update and Insight"),
37
  title="WeatherAssistantApp",
38
+ description="Enter a city name to get an interesting insight and the current weather details."
39
  )
40
 
41
  # Launch the interface