Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -34,6 +34,35 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -66,4 +95,13 @@ agent = CodeAgent(
66
  )
67
 
68
 
 
 
 
 
 
 
 
 
 
69
  GradioUI(agent).launch()
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+
38
+ @tool
39
+ def get_weather_by_city(city: str) -> str:
40
+ """
41
+ A tool that fetches the current weather for a specified city.
42
+
43
+ Args:
44
+ city: Name of the city (e.g., 'Jakarta').
45
+ """
46
+ try:
47
+ # Ganti 'YOUR_API_KEY' dengan API key dari OpenWeatherMap
48
+ api_key = "YOUR_API_KEY"
49
+ url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
50
+ response = requests.get(url)
51
+ data = response.json()
52
+
53
+ if response.status_code != 200 or "main" not in data:
54
+ return f"Failed to get weather for {city}: {data.get('message', 'Unknown error')}"
55
+
56
+ temp = data['main']['temp']
57
+ weather = data['weather'][0]['description']
58
+ humidity = data['main']['humidity']
59
+ return f"The weather in {city} is {weather} with a temperature of {temp}°C and humidity of {humidity}%."
60
+
61
+ except Exception as e:
62
+ return f"Error fetching weather: {str(e)}"
63
+
64
+
65
+
66
  final_answer = FinalAnswerTool()
67
 
68
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
95
  )
96
 
97
 
98
+ tools = [
99
+ final_answer,
100
+ get_current_time_in_timezone,
101
+ my_custom_tool,
102
+ image_generation_tool,
103
+ get_weather_by_city
104
+ ]
105
+
106
+
107
  GradioUI(agent).launch()