File size: 643 Bytes
c0b444c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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()