Aakash010 commited on
Commit
f76072a
·
verified ·
1 Parent(s): 2438d70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -1,25 +1,22 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
-
9
-
10
-
11
  from Gradio_UI import GradioUI
12
 
13
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's important to specify the return type
16
- #Keep this format for the description / args / args description but feel free to modify the tool
17
  """A tool that prints a line given number of times
18
  Args:
19
  arg1: The string to be printed
20
  arg2: How many times the string is to be printed
21
  """
22
- return (arg1 for i in range (arg2))
 
 
23
 
24
  @tool
25
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -28,40 +25,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
28
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
29
  """
30
  try:
31
- # Create timezone object
32
  tz = pytz.timezone(timezone)
33
- # Get current time in that timezone
34
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
35
  return f"The current local time in {timezone} is: {local_time}"
36
  except Exception as e:
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
 
39
 
40
- web_search_tool = DuckDuckGoSearchTool(max_results=5)
41
-
42
-
43
  final_answer = FinalAnswerTool()
44
 
45
- # 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:
46
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
47
 
48
  model = HfApiModel(
49
- max_tokens=2096,
50
- temperature=0.5,
51
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
52
- custom_role_conversions=None,
53
  )
54
 
55
-
56
- # Import tool from Hub
57
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
58
 
59
  with open("prompts.yaml", 'r') as stream:
60
  prompt_templates = yaml.safe_load(stream)
61
-
62
  agent = CodeAgent(
63
  model=model,
64
- tools=[final_answer,my_custom_tool,get_current_time_in_timezone,web_search_tool], ## add your tools here (don't remove final answer)
 
65
  max_steps=6,
66
  verbosity_level=1,
67
  grammar=None,
@@ -71,5 +62,4 @@ agent = CodeAgent(
71
  prompt_templates=prompt_templates
72
  )
73
 
74
-
75
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
 
 
7
  from Gradio_UI import GradioUI
8
 
9
+
10
  @tool
11
+ def my_custom_tool(arg1: str, arg2: int) -> str:
 
12
  """A tool that prints a line given number of times
13
  Args:
14
  arg1: The string to be printed
15
  arg2: How many times the string is to be printed
16
  """
17
+ # BUG FIX: was `return (arg1 for i in range(arg2))` — a generator, not a string
18
+ return "\n".join(arg1 for i in range(arg2))
19
+
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
25
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
26
  """
27
  try:
 
28
  tz = pytz.timezone(timezone)
 
29
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
30
  return f"The current local time in {timezone} is: {local_time}"
31
  except Exception as e:
32
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
33
 
34
 
 
 
 
35
  final_answer = FinalAnswerTool()
36
 
37
+ # web_search_tool is defined here
38
+ web_search_tool = DuckDuckGoSearchTool(max_results=5)
39
 
40
  model = HfApiModel(
41
+ max_tokens=2096,
42
+ temperature=0.5,
43
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
44
+ custom_role_conversions=None,
45
  )
46
 
 
 
47
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
48
 
49
  with open("prompts.yaml", 'r') as stream:
50
  prompt_templates = yaml.safe_load(stream)
51
+
52
  agent = CodeAgent(
53
  model=model,
54
+ # web_search_tool is NOW included in the tools list
55
+ tools=[final_answer, my_custom_tool, get_current_time_in_timezone, web_search_tool, image_generation_tool],
56
  max_steps=6,
57
  verbosity_level=1,
58
  grammar=None,
 
62
  prompt_templates=prompt_templates
63
  )
64
 
 
65
  GradioUI(agent).launch()