weatherapp / app.py
patmakur's picture
Create app.py
c0b444c verified
raw
history blame contribute delete
643 Bytes
import gradio as gr
import requests
def get_weather(city):
api_key = "YOUR_API_KEY"
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid=333d785759d9b8d5a4bdd735a013bd9e&units=metric"
response = requests.get(url)
data = response.json()
if data["cod"] == 200:
temp = data["main"]["temp"]
description = data["weather"][0]["description"]
return f"The current temperature in {city} is {temp}°C with {description}."
else:
return "Sorry, I couldn't find weather information for that city."
iface = gr.Interface(fn=get_weather, inputs="text", outputs="text")
iface.launch()