Spaces:
Sleeping
Sleeping
Update app.py
Browse files11 unmodified lines1213141515161718192017181920222324212223242526272829262728293031323334323536373832 unmodified lines717273717475767711 unmodified linesdef get_weather(city: str) -> str: """Fetches current weather information for a specified city. Args: city: Name of the city (e.g., 'Paris'). city: Name of the city (e.g., 'London') """ try: api_key = os.getenv("OPENWEATHERMAP_API_KEY") if not api_key: return "OPENWEATHERMAP_API_KEY key not found" api_key = os.getenv("OPENWEATHERMAP_API_KEY") if not api_key: return "API key not found. Make sure OPENWEATHERMAP_API_KEY is set in Hugging Face secrets."
response = requests.get( f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric" ) try: url = f"http://api.openweathermap.org/data/2.5/weather" params = {"q": city, "appid": api_key, "units": "metric"} response = requests.get(url, params=params) data = response.json() if data.get("cod") != 200: return f"Could not fetch weather: {data.get('message', 'Unknown error')}" temp = data['main']['temp'] condition = data['weather'][0]['description']
if response.status_code != 200: return f"Error: {data.get('message', 'Unknown error')}"
temp = data["main"]["temp"] condition = data["weather"][0]["description"] return f"Current weather in {city}: {temp}°C, {condition}."
except Exception as e: return f"Error fetching weather: {str(e)}" return f"An error occurred while fetching weather data: {str(e)}"
@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified lines agent = CodeAgent( model=model, tools=[get_current_time_in_timezone, get_weather, final_answer], ## add your tools here (don't remove final answer) tools=[get_current_time_in_timezone, get_weather, final_answer], max_steps=6, verbosity_level=1, grammar=None,app.py+17-14