Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,62 +9,23 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
#Marathon training plan
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
"""
|
| 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 estimation factor
|
| 25 |
-
full_hours = int(estimated_full_time // 60)
|
| 26 |
-
full_minutes = int(estimated_full_time % 60)
|
| 27 |
-
return f"{full_hours}:{full_minutes:02d}"
|
| 28 |
-
except:
|
| 29 |
-
return "Invalid half-marathon time format. Please use HH:MM."
|
| 30 |
-
|
| 31 |
-
@tool
|
| 32 |
-
def fetch_marathon_plan(goal_time: str, gender: str, training_days: int, current_time: str = None, half_time: str = None) -> str:
|
| 33 |
-
"""Fetches a marathon training plan based on goal time, gender, and weekly commitment.
|
| 34 |
|
| 35 |
Args:
|
| 36 |
goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
|
| 37 |
-
gender: 'male' or 'female' (affects training pace).
|
| 38 |
-
training_days: Days per week the user can train.
|
| 39 |
-
current_time: User's current marathon time (if available).
|
| 40 |
-
half_time: User's half-marathon time (if available).
|
| 41 |
|
| 42 |
Returns:
|
| 43 |
-
A
|
| 44 |
"""
|
| 45 |
-
# Determine experience level
|
| 46 |
-
if current_time:
|
| 47 |
-
experience = "experienced"
|
| 48 |
-
elif half_time:
|
| 49 |
-
estimated_full = estimate_marathon_time(half_time)
|
| 50 |
-
experience = f"estimated full marathon time of {estimated_full}"
|
| 51 |
-
else:
|
| 52 |
-
experience = "beginner"
|
| 53 |
-
|
| 54 |
-
# Adjust training duration
|
| 55 |
-
if training_days >= 5:
|
| 56 |
-
weeks_needed = 8
|
| 57 |
-
else:
|
| 58 |
-
weeks_needed = 12
|
| 59 |
-
|
| 60 |
search_tool = DuckDuckGoSearchTool()
|
| 61 |
-
query = f"
|
| 62 |
results = search_tool.search(query)
|
| 63 |
|
| 64 |
if results:
|
| 65 |
-
return f"
|
| 66 |
else:
|
| 67 |
-
return f"Could not find
|
| 68 |
|
| 69 |
final_answer = FinalAnswerTool()
|
| 70 |
|
|
|
|
| 9 |
|
| 10 |
#Marathon training plan
|
| 11 |
@tool
|
| 12 |
+
def fetch_marathon_plan(goal_time: str) -> str:
|
| 13 |
+
"""Fetches a marathon training plan based on a goal time.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Args:
|
| 16 |
goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
Returns:
|
| 19 |
+
A link to a training plan or summary of key details.
|
| 20 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
search_tool = DuckDuckGoSearchTool()
|
| 22 |
+
query = f"marathon training plan {goal_time} site:runnersworld.com"
|
| 23 |
results = search_tool.search(query)
|
| 24 |
|
| 25 |
if results:
|
| 26 |
+
return f"Here is a recommended training plan for {goal_time}: {results[0]['url']}"
|
| 27 |
else:
|
| 28 |
+
return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
|
| 29 |
|
| 30 |
final_answer = FinalAnswerTool()
|
| 31 |
|