Spaces:
Sleeping
Sleeping
Update app.py
Browse filesremoved few errors
app.py
CHANGED
|
@@ -12,25 +12,16 @@ from Gradio_UI import GradioUI
|
|
| 12 |
@tool
|
| 13 |
def calculate_age(birthdate: str) -> int:
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
Args:
|
| 18 |
-
birthdate: The user's birthdate as a string (any format).
|
| 19 |
-
|
| 20 |
-
Returns:
|
| 21 |
-
The calculated age as an integer, or -1 if parsing fails.
|
| 22 |
"""
|
| 23 |
try:
|
| 24 |
-
birth_date = parser.parse(birthdate, fuzzy=True)
|
| 25 |
today = datetime.today()
|
| 26 |
-
if birth_date > today:
|
| 27 |
-
return -1
|
| 28 |
-
|
| 29 |
age = today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))
|
| 30 |
return age
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return -1
|
| 34 |
@tool
|
| 35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 36 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -103,7 +94,7 @@ def determine_user_preference(user_input: str) -> bool:
|
|
| 103 |
|
| 104 |
|
| 105 |
@tool
|
| 106 |
-
def get_lifestyle_recommendations(age: int) -> str:
|
| 107 |
"""Fetches lifestyle recommendations based on age.
|
| 108 |
Args:
|
| 109 |
age: The calculated age of the user.
|
|
|
|
| 12 |
@tool
|
| 13 |
def calculate_age(birthdate: str) -> int:
|
| 14 |
"""
|
| 15 |
+
Parses a natural language birthdate string and calculates the age.
|
| 16 |
+
Returns -1 if parsing fails.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"""
|
| 18 |
try:
|
| 19 |
+
birth_date = parser.parse(birthdate, fuzzy=True) # Smart date parsing
|
| 20 |
today = datetime.today()
|
|
|
|
|
|
|
|
|
|
| 21 |
age = today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))
|
| 22 |
return age
|
| 23 |
+
except Exception:
|
| 24 |
+
return -1
|
|
|
|
| 25 |
@tool
|
| 26 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 27 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
@tool
|
| 97 |
+
def get_lifestyle_recommendations(age: int,user_input: str) -> str:
|
| 98 |
"""Fetches lifestyle recommendations based on age.
|
| 99 |
Args:
|
| 100 |
age: The calculated age of the user.
|