jacksontaylor commited on
Commit
d96ef12
·
verified ·
1 Parent(s): dc94fd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -34
app.py CHANGED
@@ -1,14 +1,10 @@
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
  search_tool = DuckDuckGoSearchTool() # Initialize outside the function
13
 
14
  @tool
@@ -29,55 +25,43 @@ def lookup_fact(query: str) -> str:
29
  except Exception as e:
30
  return f"Error during search: {str(e)}"
31
 
32
- #Example of how to use the tool outside of the agent.
33
- #print(lookup_fact("What is the capital of Japan?"))
34
-
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str:
37
- """A tool that fetches the current local time in a specified timezone.
 
38
  Args:
39
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
40
  """
41
  try:
42
- # Create timezone object
43
  tz = pytz.timezone(timezone)
44
- # Get current time in that timezone
45
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
46
  return f"The current local time in {timezone} is: {local_time}"
47
  except Exception as e:
48
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
49
 
50
-
51
  final_answer = FinalAnswerTool()
52
 
53
- # 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:
54
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
55
-
56
  model = HfApiModel(
57
- max_tokens=2096,
58
- temperature=0.5,
59
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
60
- custom_role_conversions=None,
61
  )
62
 
63
-
64
- # Import tool from Hub
65
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
66
 
67
  with open("prompts.yaml", 'r') as stream:
68
  prompt_templates = yaml.safe_load(stream)
69
-
70
- agent = CodeAgent(
71
- model=model,
72
- tools=[final_answer, image_generation_tool, lookup_fact], ## add your tools here (don't remove final answer)
73
- max_steps=6,
74
- verbosity_level=1,
75
- grammar=None,
76
- planning_interval=None,
77
- name=None,
78
- description=None,
79
- prompt_templates=prompt_templates
80
- )
81
-
82
 
83
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
 
3
  import pytz
4
  import yaml
5
  from tools.final_answer import FinalAnswerTool
 
6
  from Gradio_UI import GradioUI
7
 
 
 
8
  search_tool = DuckDuckGoSearchTool() # Initialize outside the function
9
 
10
  @tool
 
25
  except Exception as e:
26
  return f"Error during search: {str(e)}"
27
 
 
 
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
30
+ """
31
+ A tool that fetches the current local time in a specified timezone.
32
  Args:
33
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
34
  """
35
  try:
 
36
  tz = pytz.timezone(timezone)
 
37
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
38
  return f"The current local time in {timezone} is: {local_time}"
39
  except Exception as e:
40
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
41
 
 
42
  final_answer = FinalAnswerTool()
43
 
 
 
 
44
  model = HfApiModel(
45
+ max_tokens=2096,
46
+ temperature=0.5,
47
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
48
+ custom_role_conversions=None,
49
  )
50
 
 
 
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(stream)
55
+ agent = CodeAgent(
56
+ model=model,
57
+ tools=[final_answer, image_generation_tool, lookup_fact, get_current_time_in_timezone], # add all your tools here
58
+ max_steps=6,
59
+ verbosity_level=1,
60
+ grammar=None,
61
+ planning_interval=None,
62
+ name=None,
63
+ description=None,
64
+ prompt_templates=prompt_templates
65
+ )
 
 
66
 
67
  GradioUI(agent).launch()