Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,18 +10,11 @@ from Gradio_UI import GradioUI
|
|
| 10 |
#Marathon training plan
|
| 11 |
@tool
|
| 12 |
def estimate_marathon_time(half_time: str) -> str:
|
| 13 |
-
"""Estimates a full marathon time based on a given half-marathon time.
|
| 14 |
-
|
| 15 |
-
Args:
|
| 16 |
-
half_time: Half-marathon completion time in HH:MM format.
|
| 17 |
-
|
| 18 |
-
Returns:
|
| 19 |
-
Estimated full marathon time in HH:MM format.
|
| 20 |
-
"""
|
| 21 |
try:
|
| 22 |
hours, minutes = map(int, half_time.split(":"))
|
| 23 |
total_minutes = hours * 60 + minutes
|
| 24 |
-
estimated_full_time = total_minutes * 2.1 # Common
|
| 25 |
full_hours = int(estimated_full_time // 60)
|
| 26 |
full_minutes = int(estimated_full_time % 60)
|
| 27 |
return f"{full_hours}:{full_minutes:02d}"
|
|
@@ -29,8 +22,8 @@ def estimate_marathon_time(half_time: str) -> str:
|
|
| 29 |
return "Invalid half-marathon time format. Please use HH:MM."
|
| 30 |
|
| 31 |
@tool
|
| 32 |
-
def
|
| 33 |
-
"""Checks
|
| 34 |
missing = []
|
| 35 |
|
| 36 |
if "marathon_time" not in user_data and "half_marathon_time" not in user_data:
|
|
@@ -43,23 +36,28 @@ def ask_missing_info() -> str:
|
|
| 43 |
missing.append("How many days per week can you commit to training?")
|
| 44 |
|
| 45 |
if missing:
|
| 46 |
-
return "
|
| 47 |
return "All information collected. Ready to generate your plan!"
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@tool
|
| 50 |
def fetch_marathon_plan(goal_time: str) -> str:
|
| 51 |
-
"""Generates a marathon training plan
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
Returns:
|
| 57 |
-
A recommended training duration and plan.
|
| 58 |
-
"""
|
| 59 |
-
# Check if any info is missing
|
| 60 |
-
missing_info = ask_missing_info()
|
| 61 |
-
if "Before generating" in missing_info:
|
| 62 |
-
return missing_info # Ask for missing details
|
| 63 |
|
| 64 |
# Determine experience level
|
| 65 |
if "marathon_time" in user_data:
|
|
|
|
| 10 |
#Marathon training plan
|
| 11 |
@tool
|
| 12 |
def estimate_marathon_time(half_time: str) -> str:
|
| 13 |
+
"""Estimates a full marathon time based on a given half-marathon time."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
hours, minutes = map(int, half_time.split(":"))
|
| 16 |
total_minutes = hours * 60 + minutes
|
| 17 |
+
estimated_full_time = total_minutes * 2.1 # Common factor for estimation
|
| 18 |
full_hours = int(estimated_full_time // 60)
|
| 19 |
full_minutes = int(estimated_full_time % 60)
|
| 20 |
return f"{full_hours}:{full_minutes:02d}"
|
|
|
|
| 22 |
return "Invalid half-marathon time format. Please use HH:MM."
|
| 23 |
|
| 24 |
@tool
|
| 25 |
+
def check_missing_info() -> str:
|
| 26 |
+
"""Checks if required info is missing and asks for it."""
|
| 27 |
missing = []
|
| 28 |
|
| 29 |
if "marathon_time" not in user_data and "half_marathon_time" not in user_data:
|
|
|
|
| 36 |
missing.append("How many days per week can you commit to training?")
|
| 37 |
|
| 38 |
if missing:
|
| 39 |
+
return "I need more details before creating your plan:\n" + "\n".join(missing)
|
| 40 |
return "All information collected. Ready to generate your plan!"
|
| 41 |
|
| 42 |
+
@tool
|
| 43 |
+
def save_user_response(question: str, answer: str):
|
| 44 |
+
"""Saves user responses to memory."""
|
| 45 |
+
if "marathon time" in question.lower():
|
| 46 |
+
if ":" in answer:
|
| 47 |
+
user_data["marathon_time"] = answer
|
| 48 |
+
elif "half" in question.lower():
|
| 49 |
+
user_data["half_marathon_time"] = answer
|
| 50 |
+
elif "male" in answer.lower() or "female" in answer.lower():
|
| 51 |
+
user_data["gender"] = answer.lower()
|
| 52 |
+
elif answer.isdigit():
|
| 53 |
+
user_data["training_days"] = int(answer)
|
| 54 |
+
|
| 55 |
@tool
|
| 56 |
def fetch_marathon_plan(goal_time: str) -> str:
|
| 57 |
+
"""Generates a marathon training plan ONLY IF all required inputs are provided."""
|
| 58 |
+
missing_info = check_missing_info()
|
| 59 |
+
if "I need more details" in missing_info:
|
| 60 |
+
return missing_info # Keep asking until all details are given
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Determine experience level
|
| 63 |
if "marathon_time" in user_data:
|