Juank0621 commited on
Commit
00c07a5
·
verified ·
1 Parent(s): 6bfc1b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -7,8 +7,8 @@ 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 currency_converter(amount: float, from_currency: str, to_currency: str) -> str:
13
  """Converts an amount from one currency to another using real-time exchange rates.
14
  Args:
@@ -30,8 +30,8 @@ def currency_converter(amount: float, from_currency: str, to_currency: str) -> s
30
  return "Invalid currency code."
31
  except Exception as e:
32
  return f"Error fetching exchange rate: {str(e)}"
33
-
34
- @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """A tool that fetches the current local time in a specified timezone.
37
  Args:
@@ -48,35 +48,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
48
 
49
 
50
  final_answer = FinalAnswerTool()
51
-
52
- # 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:
53
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
54
-
55
- model = HfApiModel(
56
- max_tokens=1024,
57
- temperature=0.5,
58
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
59
- custom_role_conversions=None,
60
  )
61
 
62
 
63
  # Import tool from Hub
64
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
65
 
 
66
  with open("prompts.yaml", 'r') as stream:
67
  prompt_templates = yaml.safe_load(stream)
68
 
69
  agent = CodeAgent(
70
  model=model,
71
- tools=[final_answer, currency_converter], ## add your tools here (don't remove final answer)
72
  max_steps=6,
73
  verbosity_level=1,
74
  grammar=None,
75
  planning_interval=None,
76
  name=None,
77
  description=None,
78
- prompt_templates=prompt_templates
79
  )
80
 
81
 
82
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
 
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
+
12
  def currency_converter(amount: float, from_currency: str, to_currency: str) -> str:
13
  """Converts an amount from one currency to another using real-time exchange rates.
14
  Args:
 
30
  return "Invalid currency code."
31
  except Exception as e:
32
  return f"Error fetching exchange rate: {str(e)}"
33
+
34
+
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """A tool that fetches the current local time in a specified timezone.
37
  Args:
 
48
 
49
 
50
  final_answer = FinalAnswerTool()
51
+ model = HfApiModel(
52
+ max_tokens=1024,
53
+ temperature=0.5,
54
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
55
+ custom_role_conversions=None,
 
 
 
 
56
  )
57
 
58
 
59
  # Import tool from Hub
60
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
61
 
62
+ # Load system prompt from prompt.yaml file
63
  with open("prompts.yaml", 'r') as stream:
64
  prompt_templates = yaml.safe_load(stream)
65
 
66
  agent = CodeAgent(
67
  model=model,
68
+ tools=[final_answer, currency_converter], # add your tools here (don't remove final_answer)
69
  max_steps=6,
70
  verbosity_level=1,
71
  grammar=None,
72
  planning_interval=None,
73
  name=None,
74
  description=None,
75
+ prompt_templates=prompt_templates # Pass system prompt to CodeAgent
76
  )
77
 
78
 
79
+ GradioUI(agent).launch()