harryab commited on
Commit
6e38f1b
·
verified ·
1 Parent(s): 25bf8b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -27,38 +27,21 @@ def fetch_marathon_plan(goal_time: str) -> str:
27
  else:
28
  return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
29
 
30
- # Fetch marathons in Europe for 2025
31
  @tool
32
  def fetch_european_marathons_2025() -> str:
33
- """Fetches a list of marathons in Europe in 2025 from MarathonRunnersDiary."""
34
- url = "http://www.marathonrunnersdiary.com/races/europe-marathons-list.php"
35
- response = requests.get(url)
36
 
37
- if response.status_code != 200:
38
- return "Failed to fetch marathon data."
39
-
40
- soup = BeautifulSoup(response.text, 'html.parser')
41
-
42
- # Locate the marathon table (this is based on the structure of the website)
43
- marathons = []
44
- table = soup.find('table', {'class': 'racedatatable'}) # Adjust the class if necessary
45
-
46
- if table:
47
- rows = table.find_all('tr')[1:] # Skip the header row
48
- for row in rows:
49
- columns = row.find_all('td')
50
- if len(columns) >= 4:
51
- marathon_name = columns[0].get_text(strip=True)
52
- marathon_date = columns[1].get_text(strip=True)
53
- marathon_location = columns[2].get_text(strip=True)
54
- marathons.append(f"{marathon_name} on {marathon_date} in {marathon_location}")
55
 
56
- if marathons:
57
- return "\n".join(marathons)
58
  else:
59
- return "No marathons found for 2025."
60
-
61
- final_answer = FinalAnswerTool()
62
 
63
  # 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:
64
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
27
  else:
28
  return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
29
 
 
30
  @tool
31
  def fetch_european_marathons_2025() -> str:
32
+ """Fetches a list of marathons in Europe for 2025.
 
 
33
 
34
+ Returns:
35
+ A link to a webpage or a summary of key details.
36
+ """
37
+ search_tool = DuckDuckGoSearchTool()
38
+ query = "marathons in Europe 2025 site:marathonrunnersdiary.com"
39
+ results = search_tool.search(query)
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
+ if results:
42
+ return f"Here is a list of marathons in Europe for 2025: {results[0]['url']}"
43
  else:
44
+ return "Could not find any marathons for 2025 in Europe, but you can check Marathon Runner's Diary for more details."
 
 
45
 
46
  # 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:
47
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'