BoddyGus commited on
Commit
9d660fa
·
verified ·
1 Parent(s): f3130ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -9
app.py CHANGED
@@ -1,4 +1,36 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import datetime
3
  import requests
4
  import pytz
@@ -7,31 +39,55 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
- def get_current_time_in_timezone(timezone:str)->str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  try:
 
13
  tz = pytz.timezone(timezone)
14
- local_time=datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
15
  return f"The current local time in {timezone} is: {local_time}"
16
  except Exception as e:
17
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
18
 
 
19
  final_answer = FinalAnswerTool()
 
 
 
 
20
  model = HfApiModel(
21
  max_tokens=2096,
22
  temperature=0.5,
23
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
24
  custom_role_conversions=None,
25
  )
26
 
27
- image_generation_tool = load_tool("agents-course/text-to-image",trust_remote_code=True)
 
 
28
 
29
  with open("prompts.yaml", 'r') as stream:
30
  prompt_templates = yaml.safe_load(stream)
31
-
32
- agent=CodeAgent(
33
  model=model,
34
- tool=[final_answer],
35
  max_steps=6,
36
  verbosity_level=1,
37
  grammar=None,
@@ -41,4 +97,5 @@ agent=CodeAgent(
41
  prompt_templates=prompt_templates
42
  )
43
 
44
- GradioUI(agent).launch
 
 
1
+ Hugging Face's logo
2
+
3
+
4
+
5
+ agents-course
6
+ /
7
+ First_agent_template
8
+
9
+ like
10
+ 477
11
+ App
12
+ Files
13
+ Community
14
+ 363
15
+ First_agent_template
16
+ /
17
+ app.py
18
+
19
+ Jofthomas's picture
20
+ Jofthomas
21
+ Suggest using endpoint if agent is not answering
22
+ ae7a494
23
+ verified
24
+ raw
25
+
26
+ Copy download link
27
+ history
28
+ blame
29
+ contribute
30
+ delete
31
+
32
+ 2.23 kB
33
+ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
34
  import datetime
35
  import requests
36
  import pytz
 
39
 
40
  from Gradio_UI import GradioUI
41
 
42
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
43
  @tool
44
+ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
45
+ #Keep this format for the description / args / args description but feel free to modify the tool
46
+ """A tool that does nothing yet
47
+ Args:
48
+ arg1: the first argument
49
+ arg2: the second argument
50
+ """
51
+ return "What magic will you build ?"
52
+
53
+ @tool
54
+ def get_current_time_in_timezone(timezone: str) -> str:
55
+ """A tool that fetches the current local time in a specified timezone.
56
+ Args:
57
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
58
+ """
59
  try:
60
+ # Create timezone object
61
  tz = pytz.timezone(timezone)
62
+ # Get current time in that timezone
63
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
64
  return f"The current local time in {timezone} is: {local_time}"
65
  except Exception as e:
66
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
67
 
68
+
69
  final_answer = FinalAnswerTool()
70
+
71
+ # 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:
72
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
73
+
74
  model = HfApiModel(
75
  max_tokens=2096,
76
  temperature=0.5,
77
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
78
  custom_role_conversions=None,
79
  )
80
 
81
+
82
+ # Import tool from Hub
83
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
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,
 
97
  prompt_templates=prompt_templates
98
  )
99
 
100
+
101
+ GradioUI(agent).launch()