nikhilkomakula commited on
Commit
cf346ba
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -8,6 +8,39 @@ from tools.final_answer import FinalAnswerTool
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: #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
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+
12
+ @tool
13
+ def convert_time_only(time_str, from_tz_str, to_tz_str, fmt="%H:%M"):
14
+ """A tool that converts a given time from a source timezone to a destination timezone using today's date.
15
+
16
+ Args:
17
+ time_str (str): The time to convert, in 24-hour format (e.g., '15:30').
18
+ from_tz_str (str): The IANA timezone name of the source timezone (e.g., 'Asia/Kolkata').
19
+ to_tz_str (str): The IANA timezone name of the destination timezone (e.g., 'America/New_York').
20
+
21
+ Returns:
22
+ str: The converted time in the destination timezone, in 24-hour format (e.g., '05:00').
23
+
24
+ Note:
25
+ This tool uses the current date for conversion, which may affect results due to daylight saving time differences.
26
+ """
27
+
28
+ from datetime import datetime, date
29
+ import pytz
30
+
31
+ # Use today's date with the provided time
32
+ today = date.today()
33
+ dt = datetime.strptime(time_str, fmt)
34
+ dt_with_date = datetime.combine(today, dt.time())
35
+ # Localize to source timezone
36
+ from_tz = pytz.timezone(from_tz_str)
37
+ localized_dt = from_tz.localize(dt_with_date)
38
+ # Convert to target timezone
39
+ to_tz = pytz.timezone(to_tz_str)
40
+ target_dt = localized_dt.astimezone(to_tz)
41
+
42
+ return target_dt.strftime(fmt)
43
+
44
  @tool
45
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
46
  #Keep this format for the description / args / args description but feel free to modify the tool