Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,34 +8,13 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
#Marathon training plan
|
| 11 |
-
@tool
|
| 12 |
-
def estimate_marathon_time(half_time: str) -> str:
|
| 13 |
-
"""
|
| 14 |
-
Estimates a full marathon time based on a given half-marathon time.
|
| 15 |
-
|
| 16 |
-
Parameters:
|
| 17 |
-
half_time (str): The recorded half-marathon time in the format 'HH:MM'.
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
str: The estimated full marathon time in 'HH:MM' format.
|
| 21 |
-
"""
|
| 22 |
-
try:
|
| 23 |
-
hours, minutes = map(int, half_time.split(":"))
|
| 24 |
-
total_minutes = hours * 60 + minutes
|
| 25 |
-
estimated_full_time = total_minutes * 2.1 # Common estimation factor
|
| 26 |
-
full_hours = int(estimated_full_time // 60)
|
| 27 |
-
full_minutes = int(estimated_full_time % 60)
|
| 28 |
-
return f"{full_hours}:{full_minutes:02d}"
|
| 29 |
-
except ValueError:
|
| 30 |
-
return "Invalid half-marathon time format. Please use 'HH:MM'."
|
| 31 |
-
|
| 32 |
@tool
|
| 33 |
def check_missing_info() -> str:
|
| 34 |
"""Checks if required info is missing and asks for it."""
|
| 35 |
missing = []
|
| 36 |
|
| 37 |
-
if "marathon_time" not in user_data
|
| 38 |
-
missing.append("What is your best marathon time?
|
| 39 |
|
| 40 |
if "gender" not in user_data:
|
| 41 |
missing.append("Are you male or female? This affects the training plan.")
|
|
@@ -53,8 +32,6 @@ def save_user_response(question: str, answer: str):
|
|
| 53 |
if "marathon time" in question.lower():
|
| 54 |
if ":" in answer:
|
| 55 |
user_data["marathon_time"] = answer
|
| 56 |
-
elif "half" in question.lower():
|
| 57 |
-
user_data["half_marathon_time"] = answer
|
| 58 |
elif "male" in answer.lower() or "female" in answer.lower():
|
| 59 |
user_data["gender"] = answer.lower()
|
| 60 |
elif answer.isdigit():
|
|
@@ -68,13 +45,7 @@ def fetch_marathon_plan(goal_time: str) -> str:
|
|
| 68 |
return missing_info # Keep asking until all details are given
|
| 69 |
|
| 70 |
# Determine experience level
|
| 71 |
-
if "marathon_time" in user_data
|
| 72 |
-
experience = "experienced"
|
| 73 |
-
elif "half_marathon_time" in user_data:
|
| 74 |
-
estimated_full = estimate_marathon_time(user_data["half_marathon_time"])
|
| 75 |
-
experience = f"estimated full marathon time of {estimated_full}"
|
| 76 |
-
else:
|
| 77 |
-
experience = "beginner"
|
| 78 |
|
| 79 |
# Adjust training duration
|
| 80 |
training_days = user_data["training_days"]
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
#Marathon training plan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
def check_missing_info() -> str:
|
| 13 |
"""Checks if required info is missing and asks for it."""
|
| 14 |
missing = []
|
| 15 |
|
| 16 |
+
if "marathon_time" not in user_data:
|
| 17 |
+
missing.append("What is your best marathon time?")
|
| 18 |
|
| 19 |
if "gender" not in user_data:
|
| 20 |
missing.append("Are you male or female? This affects the training plan.")
|
|
|
|
| 32 |
if "marathon time" in question.lower():
|
| 33 |
if ":" in answer:
|
| 34 |
user_data["marathon_time"] = answer
|
|
|
|
|
|
|
| 35 |
elif "male" in answer.lower() or "female" in answer.lower():
|
| 36 |
user_data["gender"] = answer.lower()
|
| 37 |
elif answer.isdigit():
|
|
|
|
| 45 |
return missing_info # Keep asking until all details are given
|
| 46 |
|
| 47 |
# Determine experience level
|
| 48 |
+
experience = "experienced" if "marathon_time" in user_data else "beginner"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Adjust training duration
|
| 51 |
training_days = user_data["training_days"]
|