Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,39 +9,62 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
#Marathon trining plan tool
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
Args:
|
| 16 |
goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
Returns:
|
| 19 |
-
A
|
| 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"
|
| 27 |
else:
|
| 28 |
-
return f"Could not find
|
| 29 |
-
|
| 30 |
-
@tool
|
| 31 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 32 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 33 |
-
Args:
|
| 34 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 35 |
-
"""
|
| 36 |
-
try:
|
| 37 |
-
# Create timezone object
|
| 38 |
-
tz = pytz.timezone(timezone)
|
| 39 |
-
# Get current time in that timezone
|
| 40 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 41 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 42 |
-
except Exception as e:
|
| 43 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 44 |
-
|
| 45 |
|
| 46 |
final_answer = FinalAnswerTool()
|
| 47 |
|
|
|
|
| 9 |
|
| 10 |
#Marathon trining plan tool
|
| 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 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 recommended training duration and plan.
|
| 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"{gender} marathon training plan {goal_time} {weeks_needed}-week site:runnersworld.com"
|
| 62 |
results = search_tool.search(query)
|
| 63 |
|
| 64 |
if results:
|
| 65 |
+
return f"Based on your response ({experience}, {gender}, training {training_days} days/week), you need a {weeks_needed}-week plan. Here’s a suggested plan: {results[0]['url']}"
|
| 66 |
else:
|
| 67 |
+
return f"Could not find an exact match, but you can check Runner's World for more details."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
final_answer = FinalAnswerTool()
|
| 70 |
|