Jad-efact commited on
Commit
bc2c340
·
verified ·
1 Parent(s): 5a94ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -47
app.py CHANGED
@@ -1,19 +1,15 @@
1
  import os
2
-
3
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
4
  import datetime
5
  import requests
6
  import pytz
7
  import yaml
8
  from tools.final_answer import FinalAnswerTool
9
-
10
  from Gradio_UI import GradioUI
11
 
12
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
15
- #Keep this format for the description / args / args description but feel free to modify the tool
16
- """A tool that does nothing yet
17
  Args:
18
  arg1: the first argument
19
  arg2: the second argument
@@ -27,48 +23,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
27
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
28
  """
29
  try:
30
- # Create timezone object
31
  tz = pytz.timezone(timezone)
32
- # Get current time in that timezone
33
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
34
  return f"The current local time in {timezone} is: {local_time}"
35
  except Exception as e:
36
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
37
 
38
-
39
  final_answer = FinalAnswerTool()
40
 
41
- # 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:
42
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
43
-
44
  model = HfApiModel(
45
- max_tokens=2096,
46
- temperature=0.5,
47
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
48
- custom_role_conversions=None,
49
  )
50
 
51
-
52
- # Import tool from Hub
53
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
54
 
55
- print(f"Current working directory: {os.getcwd()}")
56
- print(f"Files in current directory: {os.listdir('.')}")
57
- print(f"Does prompts.yaml exist? {os.path.exists('prompts.yaml')}")
58
-
59
  try:
60
  with open("prompts.yaml", 'r') as stream:
61
  prompt_templates = yaml.safe_load(stream)
62
- print("--- LOADED PROMPT TEMPLATES ---")
63
- print(f"Type: {type(prompt_templates)}")
64
- if isinstance(prompt_templates, dict):
65
- print(f"Keys: {prompt_templates.keys()}")
66
- else:
67
- print(f"Content: {prompt_templates}")
68
- print("--- END LOADED PROMPT TEMPLATES ---")
69
  except Exception as e:
70
  print(f"!!! ERROR LOADING prompts.yaml: {e} !!!")
71
- prompt_templates = {} # Assign empty dict on error to potentially see a different error later
 
 
72
 
73
  agent = CodeAgent(
74
  model=model,
@@ -79,23 +59,7 @@ agent = CodeAgent(
79
  planning_interval=None,
80
  name=None,
81
  description=None,
82
- prompt_templates=prompt_templates # Pass the potentially loaded dict
83
  )
84
 
85
- #with open("prompts.yaml", 'r') as stream:
86
- # prompt_templates = yaml.safe_load(stream)
87
- #
88
- #agent = CodeAgent(
89
- # model=model,
90
- # tools=[final_answer], ## add your tools here (don't remove final answer)
91
- # max_steps=6,
92
- # verbosity_level=1,
93
- # grammar=None,
94
- # planning_interval=None,
95
- # name=None,
96
- # description=None,
97
- # prompt_templates=prompt_templates
98
- #)
99
-
100
-
101
  GradioUI(agent).launch()
 
1
  import os
 
2
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
3
  import datetime
4
  import requests
5
  import pytz
6
  import yaml
7
  from tools.final_answer import FinalAnswerTool
 
8
  from Gradio_UI import GradioUI
9
 
 
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
15
  arg2: the second argument
 
23
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
24
  """
25
  try:
 
26
  tz = pytz.timezone(timezone)
 
27
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
28
  return f"The current local time in {timezone} is: {local_time}"
29
  except Exception as e:
30
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
31
 
 
32
  final_answer = FinalAnswerTool()
33
 
 
 
 
34
  model = HfApiModel(
35
+ max_tokens=2096,
36
+ temperature=0.5,
37
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
38
+ custom_role_conversions=None,
39
  )
40
 
 
 
41
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
42
 
43
+ prompt_templates = {}
 
 
 
44
  try:
45
  with open("prompts.yaml", 'r') as stream:
46
  prompt_templates = yaml.safe_load(stream)
 
 
 
 
 
 
 
47
  except Exception as e:
48
  print(f"!!! ERROR LOADING prompts.yaml: {e} !!!")
49
+
50
+ if isinstance(prompt_templates, dict) and 'final_answer' not in prompt_templates:
51
+ prompt_templates['final_answer'] = "{{final_answer}}"
52
 
53
  agent = CodeAgent(
54
  model=model,
 
59
  planning_interval=None,
60
  name=None,
61
  description=None,
62
+ prompt_templates=prompt_templates
63
  )
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  GradioUI(agent).launch()