Spaces:
Sleeping
Sleeping
Download app.py from decodingdatascience/weather-test: direct link, hf CLI and curl.
- Browser
- Download file 698 Bytes
-
https://huggingface.co/spaces/decodingdatascience/weather-test/resolve/main/app.py
- Command line
-
hf download hf://spaces/decodingdatascience/weather-test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/decodingdatascience/weather-test/resolve/main/app.py
698 Bytes
| 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() | |