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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -9,17 +9,17 @@ 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:
@@ -39,6 +39,16 @@ def check_missing_info() -> str:
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,10 +57,7 @@ def fetch_marathon_plan(goal_time: str) -> str:
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,16 +74,6 @@ def fetch_marathon_plan(goal_time: str) -> str:
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:
 
9
 
10
  #Marathon training plan
11
  @tool
12
+ def estimate_marathon_time(marathon_time: str) -> str:
13
+ """Estimates a full marathon time based on a given marathon time."""
14
  try:
15
+ hours, minutes = map(int, marathon_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 marathon time format. Please use HH:MM."
23
 
24
  @tool
25
  def check_missing_info() -> str:
 
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 save_user_response(question: str, answer: str):
44
+ """Saves user responses to memory."""
45
+ if "marathon time" in question.lower():
46
+ user_data["marathon_time"] = answer
47
+ elif "male" in answer.lower() or "female" in answer.lower():
48
+ user_data["gender"] = answer.lower()
49
+ elif answer.isdigit():
50
+ user_data["training_days"] = int(answer)
51
+
52
  @tool
53
  def fetch_marathon_plan(goal_time: str) -> str:
54
  """Generates a marathon training plan ONLY IF all required inputs are provided."""
 
57
  return missing_info # Keep asking until all details are given
58
 
59
  # Determine experience level
60
+ experience = "experienced" if "marathon_time" in user_data else "beginner"
 
 
 
61
 
62
  # Adjust training duration
63
  training_days = user_data["training_days"]
 
74
  else:
75
  return f"Could not find an exact match, but you can check Runner's World for more details."
76
 
 
 
 
 
 
 
 
 
 
 
77
  final_answer = FinalAnswerTool()
78
 
79
  # 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: