harryab commited on
Commit
c79b491
·
verified ·
1 Parent(s): 5d84383

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -45
app.py CHANGED
@@ -9,67 +9,55 @@ from Gradio_UI import GradioUI
9
 
10
  #Marathon training plan
11
  @tool
12
- def estimate_marathon_time(marathon_time: str) -> str:
13
- """
14
- Estimate a full marathon time from the given marathon time.
15
-
16
- marathon_time (str): The marathon time in "HH:MM" format (e.g., "3:45").
 
 
 
17
  """
18
  try:
19
- hours, minutes = map(int, marathon_time.split(":"))
20
  total_minutes = hours * 60 + minutes
21
- estimated_full_time = total_minutes * 2.1 # Common factor for estimation
22
  full_hours = int(estimated_full_time // 60)
23
  full_minutes = int(estimated_full_time % 60)
24
  return f"{full_hours}:{full_minutes:02d}"
25
  except:
26
- return "Invalid marathon time format. Please use HH:MM."
27
 
28
  @tool
29
- def check_missing_info() -> str:
30
- """Checks if required info is missing and asks for it."""
31
- missing = []
32
 
33
- if "marathon_time" not in user_data:
34
- missing.append("What is your best marathon time?")
 
 
 
 
35
 
36
- if "gender" not in user_data:
37
- missing.append("Are you male or female? This affects the training plan.")
38
-
39
- if "training_days" not in user_data:
40
- missing.append("How many days per week can you commit to training?")
41
-
42
- if missing:
43
- return "I need more details before creating your plan:\n" + "\n".join(missing)
44
- return "All information collected. Ready to generate your plan!"
45
-
46
- @tool
47
- def save_user_response(question: str, answer: str):
48
- """Saves user responses to memory."""
49
- if "marathon time" in question.lower():
50
- user_data["marathon_time"] = answer
51
- elif "male" in answer.lower() or "female" in answer.lower():
52
- user_data["gender"] = answer.lower()
53
- elif answer.isdigit():
54
- user_data["training_days"] = int(answer)
55
-
56
- @tool
57
- def fetch_marathon_plan(goal_time: str) -> str:
58
- """Generates a marathon training plan ONLY IF all required inputs are provided."""
59
- missing_info = check_missing_info()
60
- if "I need more details" in missing_info:
61
- return missing_info # Keep asking until all details are given
62
-
63
  # Determine experience level
64
- experience = "experienced" if "marathon_time" in user_data else "beginner"
 
 
 
 
 
 
65
 
66
  # Adjust training duration
67
- training_days = user_data["training_days"]
68
- weeks_needed = 8 if training_days >= 5 else 12
 
 
69
 
70
- # Search for a plan
71
  search_tool = DuckDuckGoSearchTool()
72
- gender = user_data["gender"]
73
  query = f"{gender} marathon training plan {goal_time} {weeks_needed}-week site:runnersworld.com"
74
  results = search_tool.search(query)
75
 
 
9
 
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 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