charlesfeng1 commited on
Commit
0d2a7dc
·
verified ·
1 Parent(s): c7d3eea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -13,14 +13,28 @@ from Gradio_UI import GradioUI
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
17
  #Keep this format for the description / args / args description but feel free to modify the tool
18
- """A tool that does nothing yet
 
19
  Args:
20
- arg1: the first argument
21
- arg2: the second argument
 
 
22
  """
23
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -77,9 +91,15 @@ def dicebear_pixel_avatar(seed: str,
77
  resp = requests.get(url, timeout=20)
78
  resp.raise_for_status()
79
 
80
- # Encode image in base64
81
- encoded = base64.b64encode(resp.content).decode("utf-8")
82
- return f"data:image/{fmt};base64,{encoded}"
 
 
 
 
 
 
83
  except Exception as e:
84
  return f"Error generating avatar: {e}"
85
 
@@ -107,7 +127,7 @@ with open("prompts.yaml", 'r') as stream:
107
 
108
  agent = CodeAgent(
109
  model=model,
110
- tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_web, visit_page, dicebear_pixel_avatar], ## add your tools here (don't remove final answer)
111
  max_steps=6,
112
  verbosity_level=1,
113
  grammar=None,
 
13
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
+ def compare_numbers(a:str, b:str)-> str: #it's import to specify the return type
17
  #Keep this format for the description / args / args description but feel free to modify the tool
18
+ """
19
+ Compare two numeric values literally (float comparison).
20
  Args:
21
+ a: First number (string).
22
+ b: Second number (string).
23
+ Returns:
24
+ A string stating which one is larger, or if they are equal.
25
  """
26
+ try:
27
+ num_a = float(a)
28
+ num_b = float(b)
29
+
30
+ if num_a > num_b:
31
+ return f"{a} is larger than {b}"
32
+ elif num_a < num_b:
33
+ return f"{b} is larger than {a}"
34
+ else:
35
+ return f"{a} and {b} are equal"
36
+ except Exception as e:
37
+ return f"Error comparing values '{a}' and '{b}': {e}"
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str:
 
91
  resp = requests.get(url, timeout=20)
92
  resp.raise_for_status()
93
 
94
+ out_dir = "outputs"
95
+ os.makedirs(out_dir, exist_ok=True)
96
+ safe_seed = "".join(c for c in seed if c.isalnum() or c in ("-", "_"))[:40] or "seed"
97
+ filename = os.path.join(out_dir, f"dicebear_pixel_{safe_seed}_{size}.{fmt}")
98
+
99
+ with open(filename, "wb") as f:
100
+ f.write(resp.content)
101
+
102
+ return filename
103
  except Exception as e:
104
  return f"Error generating avatar: {e}"
105
 
 
127
 
128
  agent = CodeAgent(
129
  model=model,
130
+ tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search_web, visit_page, dicebear_pixel_avatar, compare_numbers], ## add your tools here (don't remove final answer)
131
  max_steps=6,
132
  verbosity_level=1,
133
  grammar=None,