Spaces:
Sleeping
Sleeping
change custom tool to nap time
Browse files
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
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 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:
|