DridiEya commited on
Commit
73397dd
·
verified ·
1 Parent(s): 77b9c76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -27
app.py CHANGED
@@ -1,13 +1,13 @@
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:
13
  """
@@ -20,7 +20,6 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
20
  Returns:
21
  A string indicating the equivalent time in seconds.
22
  """
23
- # Dictionary to convert different time units to seconds
24
  time_units = {
25
  "seconds": 1,
26
  "minutes": 60,
@@ -28,59 +27,69 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
28
  "days": 86400
29
  }
30
 
31
- # Check if the provided arg1 is a valid time unit
32
- if arg1.lower() in time_units:
33
- total_seconds = arg2 * time_units[arg1.lower()]
34
- return f"{arg2} {arg1} is equal to {total_seconds} seconds."
35
- else:
36
- return "Invalid time unit. Please use 'seconds', 'minutes', 'hours', or 'days'."
 
 
 
 
37
 
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str:
40
- """A tool that fetches the current local time in a specified timezone.
 
 
41
  Args:
42
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
43
  """
44
  try:
45
- # Create timezone object
46
  tz = pytz.timezone(timezone)
47
- # Get current time in that timezone
48
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
49
  return f"The current local time in {timezone} is: {local_time}"
50
  except Exception as e:
51
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
52
 
53
 
54
- final_answer = FinalAnswerTool()
55
 
56
- # 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:
57
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
58
 
59
  model = HfApiModel(
60
- max_tokens=2096,
61
- temperature=0.5,
62
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
63
- custom_role_conversions=None,
64
  )
65
 
66
-
67
- # Import tool from Hub
68
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
69
 
70
- with open("prompts.yaml", 'r') as stream:
 
71
  prompt_templates = yaml.safe_load(stream)
72
-
 
 
73
  agent = CodeAgent(
74
  model=model,
75
- tools=[final_answer], ## add your tools here (don't remove final answer)
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,
79
  planning_interval=None,
80
  name=None,
81
  description=None,
82
- prompt_templates=prompt_templates
83
  )
84
 
 
85
 
86
- GradioUI(agent).launch(share=True)
 
 
 
1
  import datetime
2
  import requests
3
  import pytz
4
  import yaml
5
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
 
9
+ # Custom Tools
10
+
11
  @tool
12
  def my_custom_tool(arg1: str, arg2: int) -> str:
13
  """
 
20
  Returns:
21
  A string indicating the equivalent time in seconds.
22
  """
 
23
  time_units = {
24
  "seconds": 1,
25
  "minutes": 60,
 
27
  "days": 86400
28
  }
29
 
30
+ try:
31
+ unit = arg1.lower()
32
+ if unit in time_units:
33
+ total_seconds = arg2 * time_units[unit]
34
+ return f"{arg2} {arg1} is equal to {total_seconds} seconds."
35
+ else:
36
+ return "Invalid time unit. Please use 'seconds', 'minutes', 'hours', or 'days'."
37
+ except Exception as e:
38
+ return f"Error: {str(e)}"
39
+
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
43
+ """
44
+ A tool that fetches the current local time in a specified timezone.
45
+
46
  Args:
47
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
48
+
49
+ Returns:
50
+ A string with the local time in the given timezone.
51
  """
52
  try:
 
53
  tz = pytz.timezone(timezone)
 
54
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
55
  return f"The current local time in {timezone} is: {local_time}"
56
  except Exception as e:
57
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
58
 
59
 
60
+ # Model Configuration
61
 
62
+ final_answer = FinalAnswerTool()
 
63
 
64
  model = HfApiModel(
65
+ max_tokens=2096,
66
+ temperature=0.5,
67
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # This model may be overloaded
68
+ custom_role_conversions=None,
69
  )
70
 
71
+ # Import tool from Hugging Face Hub
 
72
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
73
 
74
+ # Load prompts from YAML file
75
+ with open("prompts.yaml", "r") as stream:
76
  prompt_templates = yaml.safe_load(stream)
77
+
78
+ # Agent Setup
79
+
80
  agent = CodeAgent(
81
  model=model,
82
+ tools=[final_answer], # Add other tools here if needed
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
86
  planning_interval=None,
87
  name=None,
88
  description=None,
89
+ prompt_templates=prompt_templates,
90
  )
91
 
92
+ # Launch the Gradio UI
93
 
94
+ if __name__ == "__main__":
95
+ GradioUI(agent).launch()