Isaac454 commited on
Commit
2cefb06
·
verified ·
1 Parent(s): 9441d3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -1,16 +1,14 @@
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
  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
@@ -18,6 +16,7 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
21
  @tool
22
  def translate_english_to_french(text: str) -> str:
23
  """
@@ -36,20 +35,14 @@ def translate_english_to_french(text: str) -> str:
36
  English:
37
  {text}
38
  """
39
-
40
  return prompt
41
 
42
 
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str:
45
- """A tool that fetches the current local time in a specified timezone.
46
- Args:
47
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
48
- """
49
  try:
50
- # Create timezone object
51
  tz = pytz.timezone(timezone)
52
- # Get current time in that timezone
53
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
54
  return f"The current local time in {timezone} is: {local_time}"
55
  except Exception as e:
@@ -58,26 +51,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
58
 
59
  final_answer = FinalAnswerTool()
60
 
61
- # 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:
62
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
63
-
64
  model = HfApiModel(
65
- max_tokens=2096,
66
- temperature=0.5,
67
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
68
- custom_role_conversions=None,
69
  )
70
 
71
-
72
  # Import tool from Hub
73
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
 
74
 
75
- with open("prompts.yaml", 'r') as stream:
76
  prompt_templates = yaml.safe_load(stream)
77
-
 
78
  agent = CodeAgent(
79
  model=model,
80
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
81
  max_steps=6,
82
  verbosity_level=1,
83
  grammar=None,
@@ -87,5 +82,4 @@ agent = CodeAgent(
87
  prompt_templates=prompt_templates
88
  )
89
 
90
-
91
- 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
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
10
  @tool
11
+ def my_custom_tool(arg1: str, arg2: int) -> str:
 
12
  """A tool that does nothing yet
13
  Args:
14
  arg1: the first argument
 
16
  """
17
  return "What magic will you build ?"
18
 
19
+
20
  @tool
21
  def translate_english_to_french(text: str) -> str:
22
  """
 
35
  English:
36
  {text}
37
  """
 
38
  return prompt
39
 
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
43
+ """A tool that fetches the current local time in a specified timezone."""
 
 
 
44
  try:
 
45
  tz = pytz.timezone(timezone)
 
46
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
47
  return f"The current local time in {timezone} is: {local_time}"
48
  except Exception as e:
 
51
 
52
  final_answer = FinalAnswerTool()
53
 
 
 
 
54
  model = HfApiModel(
55
+ max_tokens=2096,
56
+ temperature=0.5,
57
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
58
+ custom_role_conversions=None,
59
  )
60
 
 
61
  # Import tool from Hub
62
+ image_generation_tool = load_tool(
63
+ "agents-course/text-to-image", trust_remote_code=True
64
+ )
65
 
66
+ with open("prompts.yaml", "r") as stream:
67
  prompt_templates = yaml.safe_load(stream)
68
+
69
+ # 🔴 🔴 🔴 THIS IS THE ONLY CHANGE 🔴 🔴 🔴
70
  agent = CodeAgent(
71
  model=model,
72
+ tools=[
73
+ final_answer, # REQUIRED – do not remove
74
+ translate_english_to_french # 🔴 ADDED HERE
75
+ ],
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,
 
82
  prompt_templates=prompt_templates
83
  )
84
 
85
+ GradioUI(agent).launch()