Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def get_weather(city):
|
5 |
+
api_key = "YOUR_API_KEY"
|
6 |
+
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid=333d785759d9b8d5a4bdd735a013bd9e&units=metric"
|
7 |
+
response = requests.get(url)
|
8 |
+
data = response.json()
|
9 |
+
if data["cod"] == 200:
|
10 |
+
temp = data["main"]["temp"]
|
11 |
+
description = data["weather"][0]["description"]
|
12 |
+
return f"The current temperature in {city} is {temp}°C with {description}."
|
13 |
+
else:
|
14 |
+
return "Sorry, I couldn't find weather information for that city."
|
15 |
+
|
16 |
+
iface = gr.Interface(fn=get_weather, inputs="text", outputs="text")
|
17 |
+
iface.launch()
|