Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,51 +8,42 @@ from bs4 import BeautifulSoup # for web scraping
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
-
|
| 12 |
-
@tool
|
| 13 |
-
def fetch_marathon_plan(goal_time: str) -> str:
|
| 14 |
-
"""Fetches a marathon training plan based on a goal time.
|
| 15 |
-
|
| 16 |
-
Args:
|
| 17 |
-
goal_time: Desired marathon completion time (e.g., '4:00', '3:30').
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
A link to a training plan or summary of key details.
|
| 21 |
-
"""
|
| 22 |
-
search_tool = DuckDuckGoSearchTool()
|
| 23 |
-
query = f"marathon training plan {goal_time} site:runnersworld.com"
|
| 24 |
-
results = search_tool.search(query)
|
| 25 |
-
|
| 26 |
-
if results:
|
| 27 |
-
return f"Here is a recommended training plan for {goal_time}: {results[0]['url']}"
|
| 28 |
-
else:
|
| 29 |
-
return f"Could not find a specific plan for {goal_time}, but you can check Runner's World for more details."
|
| 30 |
-
|
| 31 |
# Fetch marathons in Europe for 2025
|
| 32 |
@tool
|
| 33 |
def fetch_european_marathons_2025() -> str:
|
| 34 |
"""Fetches a list of marathons in Europe in 2025 from MarathonRunnersDiary."""
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
marathon_name = columns[0].get_text(strip=True)
|
| 53 |
-
marathon_date = columns[1].get_text(strip=True)
|
| 54 |
-
marathon_location = columns[2].get_text(strip=True)
|
| 55 |
-
marathons.append(f"{marathon_name} on {marathon_date} in {marathon_location}")
|
| 56 |
|
| 57 |
if marathons:
|
| 58 |
return "\n".join(marathons)
|
|
@@ -73,7 +64,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
-
tools=[final_answer,
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|
|
|
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Fetch marathons in Europe for 2025
|
| 12 |
@tool
|
| 13 |
def fetch_european_marathons_2025() -> str:
|
| 14 |
"""Fetches a list of marathons in Europe in 2025 from MarathonRunnersDiary."""
|
| 15 |
+
# Fetch the webpage
|
| 16 |
+
URL = "http://www.marathonrunnersdiary.com/races/europe-marathons-list.php"
|
| 17 |
+
page = requests.get(URL)
|
| 18 |
+
soup = BeautifulSoup(page.content, "html.parser")
|
| 19 |
+
|
| 20 |
+
# Find the section containing marathon events
|
| 21 |
+
results = soup.find(id="holder")
|
| 22 |
+
marathons = results.find_all(itemtype="http://schema.org/Event")
|
| 23 |
+
|
| 24 |
+
# Extract relevant details
|
| 25 |
+
marathon_list = []
|
| 26 |
+
for marathon in marathons:
|
| 27 |
+
# Extract name
|
| 28 |
+
name_tag = marathon.find(itemprop="name")
|
| 29 |
+
name = name_tag.text.strip() if name_tag else "N/A"
|
| 30 |
|
| 31 |
+
# Extract date
|
| 32 |
+
date_meta = marathon.find("meta", itemprop="startDate")
|
| 33 |
+
date = date_meta["content"] if date_meta else marathon.find("div", class_="leftdate").text.strip()
|
| 34 |
+
|
| 35 |
+
# Extract city and country
|
| 36 |
+
city_tag = marathon.find("div", class_="leftcity")
|
| 37 |
+
city = city_tag.text.strip() if city_tag else "N/A"
|
| 38 |
+
|
| 39 |
+
country_tag = marathon.find("div", class_="leftregion")
|
| 40 |
+
country = country_tag.text.strip() if country_tag else "N/A"
|
| 41 |
|
| 42 |
+
# Extract URL
|
| 43 |
+
link_tag = marathon.find("a")
|
| 44 |
+
link = link_tag["href"] if link_tag else "N/A"
|
| 45 |
+
|
| 46 |
+
marathon_list.append([name, date, city, country, link])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
if marathons:
|
| 49 |
return "\n".join(marathons)
|
|
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
+
tools=[final_answer, fetch_european_marathons_2025],
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|