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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,13 +1,20 @@
1
  import gradio as gr
2
  import requests
3
  import os
 
4
 
5
  def get_weather(city_name):
 
 
 
 
 
 
6
  API_Key = os.getenv("OPENWEATHER_API_KEY")
7
  if not API_Key:
8
  return "API Key is not set. Please set the OPENWEATHER_API_KEY environment variable."
9
 
10
- url = f'https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={API_Key}&units=metric'
11
  response = requests.get(url)
12
 
13
  if response.status_code == 200:
@@ -18,7 +25,7 @@ def get_weather(city_name):
18
 
19
  # Adding emojis and creative text
20
  weather_emoji = "☀️" if "clear" in weather else "☁️" if "cloud" in weather else "🌧️" if "rain" in weather else "❄️" if "snow" in weather else "🌫️"
21
- return (f"In {city_name}, the weather is currently {weather} {weather_emoji}. "
22
  f"The temperature is a comfy {temp}°C 🌡️. "
23
  f"Also, humidity levels are at {humidity}%, so keep hydrated! 💧")
24
  else:
 
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:
 
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: