Erfan97 commited on
Commit
2b33562
·
verified ·
1 Parent(s): 8c5c24b
Files changed (1) hide show
  1. app.py +47 -11
app.py CHANGED
@@ -7,16 +7,7 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
- @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
- Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
- """
19
- return "What magic will you build ?"
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -34,6 +25,44 @@ 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:
@@ -55,7 +84,14 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
 
 
 
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+
 
 
 
 
 
 
 
 
 
11
 
12
  @tool
13
  def get_current_time_in_timezone(timezone: str) -> str:
 
25
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
26
 
27
 
28
+ @tool
29
+ def get_weather(city: str) -> str:
30
+ """Get the current weather for a given city.
31
+ Args:
32
+ city: City name (e.g., "Berlin", "Tokyo", "New York")
33
+ """
34
+ try:
35
+ # Step 1: Geocode the city
36
+ geo_url = "https://geocoding-api.open-meteo.com/v1/search"
37
+ geo_resp = requests.get(geo_url, params={"name": city, "count": 1}).json()
38
+
39
+ if "results" not in geo_resp or len(geo_resp["results"]) == 0:
40
+ return f"Could not find city '{city}'. Try another spelling."
41
+
42
+ loc = geo_resp["results"][0]
43
+ lat, lon = loc["latitude"], loc["longitude"]
44
+ display_name = f"{loc['name']}, {loc.get('country', '')}"
45
+
46
+ # Step 2: Fetch current weather
47
+ weather_url = "https://api.open-meteo.com/v1/forecast"
48
+ weather_resp = requests.get(weather_url, params={
49
+ "latitude": lat,
50
+ "longitude": lon,
51
+ "current_weather": True
52
+ }).json()
53
+
54
+ current = weather_resp.get("current_weather", None)
55
+ if not current:
56
+ return f"Weather data unavailable for {display_name}."
57
+
58
+ temp = current["temperature"]
59
+ wind = current["windspeed"]
60
+ return f"🌤 Current weather in {display_name}: {temp}°C, wind {wind} km/h."
61
+
62
+ except Exception as e:
63
+ return f"Weather lookup failed: {str(e)}"
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:
 
84
 
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[
88
+ final_answer,
89
+ DuckDuckGoSearchTool(), # Web search
90
+ image_generation_tool, # HF Hub tool
91
+ my_custom_tool, # Your custom tool
92
+ get_current_time_in_timezone,
93
+ get_weather # Extra creative tool!
94
+ ],
95
  max_steps=6,
96
  verbosity_level=1,
97
  grammar=None,