harryab commited on
Commit
7ef133e
·
verified ·
1 Parent(s): 0f61d55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -14
app.py CHANGED
@@ -7,7 +7,7 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
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.
@@ -29,35 +29,54 @@ def estimate_marathon_time(half_time: str) -> str:
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
 
 
7
 
8
  from Gradio_UI import GradioUI
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.
 
29
  return "Invalid half-marathon time format. Please use HH:MM."
30
 
31
  @tool
32
+ def ask_missing_info() -> str:
33
+ """Checks which user inputs are missing and asks for them."""
34
+ missing = []
35
+
36
+ if "marathon_time" not in user_data and "half_marathon_time" not in user_data:
37
+ missing.append("What is your best marathon time? If you don’t have one, provide your best half-marathon time.")
38
+
39
+ if "gender" not in user_data:
40
+ missing.append("Are you male or female? This affects the training plan.")
41
+
42
+ if "training_days" not in user_data:
43
+ missing.append("How many days per week can you commit to training?")
44
+
45
+ if missing:
46
+ return "Before generating your plan, I need some details:\n" + "\n".join(missing)
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 only if all required inputs are provided.
52
 
53
  Args:
54
  goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
 
 
 
 
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:
66
  experience = "experienced"
67
+ elif "half_marathon_time" in user_data:
68
+ estimated_full = estimate_marathon_time(user_data["half_marathon_time"])
69
  experience = f"estimated full marathon time of {estimated_full}"
70
  else:
71
  experience = "beginner"
72
 
73
  # Adjust training duration
74
+ training_days = user_data["training_days"]
75
+ weeks_needed = 8 if training_days >= 5 else 12
 
 
76
 
77
+ # Search for a plan
78
  search_tool = DuckDuckGoSearchTool()
79
+ gender = user_data["gender"]
80
  query = f"{gender} marathon training plan {goal_time} {weeks_needed}-week site:runnersworld.com"
81
  results = search_tool.search(query)
82