tejasri19 commited on
Commit
7245734
·
verified ·
1 Parent(s): dc37459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -12
app.py CHANGED
@@ -1,5 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
- import datetime
3
  import requests
4
  import pytz
5
  import yaml
@@ -8,22 +8,43 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  import os
11
- if not os.getenv("HF_TOKEN"):
12
- print("Error: HF_TOKEN is not set or is empty.")
13
- else:
14
- print("HF_TOKEN is set.")
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
17
  @tool
18
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
19
- #Keep this format for the description / args / args description but feel free to modify the tool
20
  """A tool that does nothing yet
21
  Args:
22
- arg1: the first argument
23
- arg2: the second argument
 
 
24
  """
25
- return "What magic will you build ?"
26
 
 
 
 
 
 
 
 
 
27
  @tool
28
  def get_current_time_in_timezone(timezone: str) -> str:
29
  """A tool that fetches the current local time in a specified timezone.
@@ -43,7 +64,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
43
  final_answer = FinalAnswerTool()
44
 
45
  # 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:
46
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
47
 
48
  model = HfApiModel(
49
  max_tokens=2096,
@@ -53,6 +74,8 @@ custom_role_conversions=None,
53
  )
54
 
55
 
 
 
56
  # Import tool from Hub
57
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
58
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ from datetime import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
8
  from Gradio_UI import GradioUI
9
 
10
  import os
11
+ from smolagents import LiteLLMModel
12
+
13
+ def get_time_in_seconds(timezone_name: str) -> int:
14
+ """
15
+ Returns the current time in the given timezone as seconds since epoch.
16
+
17
+ Args:
18
+ timezone_name (str): Name of the timezone (e.g., 'America/New_York')
19
+
20
+ Returns:
21
+ int: Seconds since the Unix epoch in the given timezone.
22
+ """
23
+ tz = pytz.timezone(timezone_name)
24
+ now = datetime.now(tz)
25
+ # Convert to UTC then to timestamp (seconds since epoch)
26
+ return int(now.astimezone(pytz.utc).timestamp())
27
+
28
 
 
29
  @tool
30
+ def calculate_time_difference(timezone: str, other_timezone: str)-> float:
31
+
32
  """A tool that does nothing yet
33
  Args:
34
+ timezone: the reference timezone
35
+ other_timezone: the timezone to compare against the reference
36
+ Returns:
37
+ int: the time difference between the two timezones in hours, negative value means the other tiemzone is behind
38
  """
 
39
 
40
+ time1_seconds = get_time_in_seconds(timezone)
41
+ time2_seconds = get_time_in_seconds(other_timezone)
42
+ diff = time1_seconds - time2_seconds
43
+
44
+ hours = diff/3600
45
+
46
+ return hours
47
+
48
  @tool
49
  def get_current_time_in_timezone(timezone: str) -> str:
50
  """A tool that fetches the current local time in a specified timezone.
 
64
  final_answer = FinalAnswerTool()
65
 
66
  # 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:
67
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
68
 
69
  model = HfApiModel(
70
  max_tokens=2096,
 
74
  )
75
 
76
 
77
+ model = LiteLLMModel(model_id="gemini/gemini-2.0-flash-lite", api_key=os.getenv(key="GEMINI_API_KEY"))
78
+
79
  # Import tool from Hub
80
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
81