File size: 698 Bytes
0ade6d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
import requests

def get_weather(city):
    api_key = "YOUR_REAL_API_KEY"  # not recommended for public repos
    url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
    response = requests.get(url)
    data = response.json()
    if data.get("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")

if __name__ == "__main__":
    iface.launch()