Spaces:
Running on Zero
Running on Zero
Download tools/get_weather.py from Ark4u/First_agent_template: direct link, hf CLI and curl.
- Browser
- Download file 898 Bytes
-
https://huggingface.co/spaces/Ark4u/First_agent_template/resolve/main/tools/get_weather.py
- Command line
-
hf download hf://spaces/Ark4u/First_agent_template/tools/get_weather.py
-
curl -L -o get_weather.py https://huggingface.co/spaces/Ark4u/First_agent_template/resolve/main/tools/get_weather.py
898 Bytes
| from urllib.parse import quote | |
| import requests | |
| from smolagents import tool | |
| def get_weather(location: str) -> str: | |
| """Fetches the current live weather report and temperature for a given city or location. | |
| Args: | |
| location: The name of the city or location (e.g., 'Paris', 'Tokyo', 'San Francisco'). | |
| """ | |
| try: | |
| encoded_loc = quote(location) | |
| url = f"https://wttr.in/{encoded_loc}?format=%C+%t+(feels+like+%f)+wind:+%w" | |
| headers = {"User-Agent": "HF-Agents-Course-ArkAssistant/1.0"} | |
| resp = requests.get(url, headers=headers, timeout=10) | |
| if resp.status_code == 200 and resp.text: | |
| return f"Weather for {location}: {resp.text.strip()}" | |
| return f"Could not retrieve weather for {location} (status code {resp.status_code})." | |
| except Exception as e: | |
| return f"Error fetching weather for '{location}': {str(e)}" | |