LeptaLuma commited on
Commit
8b65255
·
verified ·
1 Parent(s): 6a9912b

change custom tool to nap time

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -9,21 +9,30 @@ 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 check_hours_minutes_sum(date_str: str) -> bool: #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 checks if the sum of hours and minutes in a datetime string equals 67.
 
 
15
  Args:
16
- date_str: DateTime string in format "%Y-%m-%d %H:%M:%S"
 
 
 
17
  """
18
- # Split the datetime string to extract time part
19
- time_part = date_str.split(' ')[1]
 
 
 
 
20
 
21
- # Split hours and minutes
22
- hours, minutes, seconds = time_part.split(':')
 
 
23
 
24
- # Convert to integers and check if sum equals 67
25
- total = int(hours) + int(minutes)
26
- return total == 67
27
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def is_good_nap_time(datetime_str: str) -> bool:
13
+ """Checks whether the given time falls within a recommended nap window.
14
+
15
+ Good nap windows are 12:00–14:30 (post-lunch) and 16:30–18:30 (afternoon).
16
+
17
  Args:
18
+ datetime_str: DateTime string in format "%Y-%m-%d %H:%M:%S"
19
+
20
+ Returns:
21
+ True if the time is within a nap window, False otherwise.
22
  """
23
+ try:
24
+ dt = datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
25
+ except ValueError:
26
+ raise ValueError(f"Invalid datetime format: '{datetime_str}'. Expected '%Y-%m-%d %H:%M:%S'.")
27
+
28
+ t = dt.time()
29
 
30
+ window_1 = (datetime.strptime("12:00:00", "%H:%M:%S").time(),
31
+ datetime.strptime("14:30:00", "%H:%M:%S").time())
32
+ window_2 = (datetime.strptime("16:30:00", "%H:%M:%S").time(),
33
+ datetime.strptime("18:30:00", "%H:%M:%S").time())
34
 
35
+ return window_1[0] <= t <= window_1[1] or window_2[0] <= t <= window_2[1]
 
 
36
 
37
  @tool
38
  def get_current_time_in_timezone(timezone: str) -> str: