Spaces:
Sleeping
Sleeping
Update app.py
Browse files11 unmodified lines12131415161718192021222324252627282930313233343532 unmodified lines6869707172737411 unmodified linesdef get_weather(city: str) -> str:"""Fetches current weather information for a specified city.Args:city: Name of the city (e.g., 'Paris')."""try:api_key = os.getenv("OPENWEATHERMAP_API_KEY")if not api_key:return "OPENWEATHERMAP_API_KEY key not found"response = requests.get(f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric")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']return f"Current weather in {city}: {temp}°C, {condition}."except Exception as e:return f"Error fetching weather: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = CodeAgent(model=model,tools=[get_current_time_in_timezone, get_weather, final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,11 unmodified lines12131415161718192021222324252627282930313233343536373832 unmodified lines7172737475767711 unmodified linesdef get_weather(city: str) -> str:"""Fetches current weather information for a specified city.Args:city: Name of the city (e.g., 'London')"""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."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 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"An error occurred while fetching weather data: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = CodeAgent(model=model,tools=[get_current_time_in_timezone, get_weather, final_answer],max_steps=6,verbosity_level=1,grammar=None,
app.py+17-14