ArceusInception commited on
Commit
49ea3bb
·
verified ·
1 Parent(s): 772206c

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -40
app.py DELETED
@@ -1,40 +0,0 @@
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
- if response.status_code == 200:
13
- data = response.json()
14
- weather = data['weather'][0]['description']
15
- temp = data['main']['temp']
16
- humidity = data['main']['humidity']
17
-
18
- # Adding emojis and creative text
19
- weather_emoji = "☀️" if "clear" in weather else "☁️" if "cloud" in weather else "🌧️" if "rain" in weather else "❄️" if "snow" in weather else "🌫️"
20
- return (f"In {city_name}, the weather is currently {weather} {weather_emoji}. "
21
- f"The temperature is a comfy {temp}°C 🌡️. "
22
- f"Also, humidity levels are at {humidity}%, so keep hydrated! 💧")
23
- else:
24
- return "Failed to retrieve data. Please check the city name and try again."
25
-
26
- # Define Gradio interface
27
- iface = gr.Interface(
28
- fn=get_weather,
29
- inputs=gr.Textbox(label="Enter City Name"),
30
- outputs=[
31
- gr.Textbox(label="Weather"),
32
- gr.Textbox(label="Temperature"),
33
- gr.Textbox(label="Humidity")
34
- ],
35
- title="Weather App",
36
- description="Enter a city name to get the current weather description, temperature, and humidity."
37
- )
38
-
39
- # Launch the interface
40
- iface.launch()