ZapataRoman commited on
Commit
313d833
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -7
app.py CHANGED
@@ -9,14 +9,89 @@ 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: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +130,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def convert_time_to_pacific(source_datetime: str, source_timezone: str) -> str:
13
+ """Converts a date/time from any timezone to Pacific Time.
 
14
  Args:
15
+ source_datetime: The date and time to convert. Use formats like '2026-07-06 15:00', '2026-07-06 3:00 PM', or '2026-07-06 3pm'.
16
+ source_timezone: The source timezone. Use an IANA timezone like 'America/New_York', 'Europe/London', or aliases like 'ET', 'CT', 'UTC'.
17
  """
18
+ try:
19
+ timezone_aliases = {
20
+ "pt": "America/Los_Angeles",
21
+ "pacific": "America/Los_Angeles",
22
+ "pst": "America/Los_Angeles",
23
+ "pdt": "America/Los_Angeles",
24
+
25
+ "mt": "America/Denver",
26
+ "mountain": "America/Denver",
27
+
28
+ "ct": "America/Chicago",
29
+ "central": "America/Chicago",
30
+
31
+ "et": "America/New_York",
32
+ "eastern": "America/New_York",
33
+ "est": "America/New_York",
34
+ "edt": "America/New_York",
35
+
36
+ "utc": "UTC",
37
+ "gmt": "GMT",
38
+
39
+ "london": "Europe/London",
40
+ "uk": "Europe/London",
41
+ "paris": "Europe/Paris",
42
+ "berlin": "Europe/Berlin",
43
+ "tokyo": "Asia/Tokyo",
44
+ "india": "Asia/Kolkata",
45
+ }
46
+
47
+ source_tz_name = timezone_aliases.get(
48
+ source_timezone.strip().lower(),
49
+ source_timezone.strip()
50
+ )
51
+
52
+ source_tz = pytz.timezone(source_tz_name)
53
+ pacific_tz = pytz.timezone("America/Los_Angeles")
54
+
55
+ cleaned_datetime = (
56
+ source_datetime
57
+ .strip()
58
+ .replace("T", " ")
59
+ .replace("pm", " PM")
60
+ .replace("am", " AM")
61
+ )
62
+
63
+ formats = [
64
+ "%Y-%m-%d %H:%M",
65
+ "%Y-%m-%d %H:%M:%S",
66
+ "%Y-%m-%d %I:%M %p",
67
+ "%Y-%m-%d %I %p",
68
+ ]
69
+
70
+ parsed_datetime = None
71
+
72
+ for fmt in formats:
73
+ try:
74
+ parsed_datetime = datetime.datetime.strptime(cleaned_datetime, fmt)
75
+ break
76
+ except ValueError:
77
+ continue
78
+
79
+ if parsed_datetime is None:
80
+ return (
81
+ "Could not parse the datetime. "
82
+ "Use something like '2026-07-06 15:00' or '2026-07-06 3:00 PM'."
83
+ )
84
+
85
+ localized_datetime = source_tz.localize(parsed_datetime)
86
+ pacific_datetime = localized_datetime.astimezone(pacific_tz)
87
+
88
+ return (
89
+ f"{source_datetime} in {source_tz_name} is "
90
+ f"{pacific_datetime.strftime('%Y-%m-%d %I:%M %p %Z')}."
91
+ )
92
+
93
+ except Exception as e:
94
+ return f"Error converting time to Pacific Time: {str(e)}"
95
 
96
  @tool
97
  def get_current_time_in_timezone(timezone: str) -> str:
 
130
 
131
  agent = CodeAgent(
132
  model=model,
133
+ tools=[get_current_time_in_timezone, final_answer, convert_time_to_pacific], ## add your tools here (don't remove final answer)
134
  max_steps=6,
135
  verbosity_level=1,
136
  grammar=None,