harryab commited on
Commit
ce6a9ac
·
verified ·
1 Parent(s): 17b5ad6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -8,6 +8,19 @@ from tools.final_answer import FinalAnswerTool
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."""
@@ -26,27 +39,6 @@ def check_missing_info() -> str:
26
  return "I need more details before creating your plan:\n" + "\n".join(missing)
27
  return "All information collected. Ready to generate your plan!"
28
 
29
- @tool
30
- def save_user_response(question: str, answer: str):
31
- """Saves user responses to memory.
32
-
33
- This function saves the user's responses to the memory based on the question asked.
34
-
35
- Args:
36
- question (str): A string representing the question asked to the user. For example, "What is your marathon time?".
37
- answer (str): A string representing the user's response. For example, "3:30" or "Male".
38
-
39
- Example:
40
- save_user_response("What is your marathon time?", "3:30")
41
- """
42
- if "marathon time" in question.lower():
43
- if ":" in answer:
44
- user_data["marathon_time"] = answer
45
- elif "male" in answer.lower() or "female" in answer.lower():
46
- user_data["gender"] = answer.lower()
47
- elif answer.isdigit():
48
- user_data["training_days"] = int(answer)
49
-
50
  @tool
51
  def fetch_marathon_plan(goal_time: str) -> str:
52
  """Generates a marathon training plan ONLY IF all required inputs are provided."""
@@ -55,7 +47,10 @@ def fetch_marathon_plan(goal_time: str) -> str:
55
  return missing_info # Keep asking until all details are given
56
 
57
  # Determine experience level
58
- experience = "experienced" if "marathon_time" in user_data else "beginner"
 
 
 
59
 
60
  # Adjust training duration
61
  training_days = user_data["training_days"]
@@ -72,6 +67,16 @@ def fetch_marathon_plan(goal_time: str) -> str:
72
  else:
73
  return f"Could not find an exact match, but you can check Runner's World for more details."
74
 
 
 
 
 
 
 
 
 
 
 
75
  final_answer = FinalAnswerTool()
76
 
77
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
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."""
14
+ try:
15
+ hours, minutes = map(int, half_time.split(":"))
16
+ total_minutes = hours * 60 + minutes
17
+ estimated_full_time = total_minutes * 2.1 # Common factor for estimation
18
+ full_hours = int(estimated_full_time // 60)
19
+ full_minutes = int(estimated_full_time % 60)
20
+ return f"{full_hours}:{full_minutes:02d}"
21
+ except:
22
+ return "Invalid half-marathon time format. Please use HH:MM."
23
+
24
  @tool
25
  def check_missing_info() -> str:
26
  """Checks if required info is missing and asks for it."""
 
39
  return "I need more details before creating your plan:\n" + "\n".join(missing)
40
  return "All information collected. Ready to generate your plan!"
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  @tool
43
  def fetch_marathon_plan(goal_time: str) -> str:
44
  """Generates a marathon training plan ONLY IF all required inputs are provided."""
 
47
  return missing_info # Keep asking until all details are given
48
 
49
  # Determine experience level
50
+ if "marathon_time" in user_data:
51
+ experience = "experienced"
52
+ else:
53
+ experience = "beginner"
54
 
55
  # Adjust training duration
56
  training_days = user_data["training_days"]
 
67
  else:
68
  return f"Could not find an exact match, but you can check Runner's World for more details."
69
 
70
+ # Collect user responses directly
71
+ def collect_user_responses(question: str, answer: str):
72
+ """Collects and stores user responses in the user_data dictionary."""
73
+ if "marathon time" in question.lower():
74
+ user_data["marathon_time"] = answer
75
+ elif "male" in answer.lower() or "female" in answer.lower():
76
+ user_data["gender"] = answer.lower()
77
+ elif answer.isdigit():
78
+ user_data["training_days"] = int(answer)
79
+
80
  final_answer = FinalAnswerTool()
81
 
82
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder: