Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,27 +9,31 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def scrape_wiki_fifa_winners(arg1:int, arg2:str)-> str:
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
arg1:
|
| 17 |
-
arg2:
|
| 18 |
-
"""
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
import requests
|
| 21 |
from bs4 import BeautifulSoup
|
| 22 |
-
|
| 23 |
def get_fifa_winners():
|
| 24 |
url = "https://en.wikipedia.org/wiki/List_of_FIFA_World_Cup_finals"
|
| 25 |
response = requests.get(url)
|
| 26 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 27 |
-
|
| 28 |
winners = {}
|
| 29 |
tables = soup.find_all("table", {"class": "wikitable"})
|
| 30 |
-
|
| 31 |
categories = ["Men", "Women"]
|
| 32 |
-
|
| 33 |
for idx, table in enumerate(tables[:2]): # First two tables (Men's and Women's WC)
|
| 34 |
rows = table.find_all("tr")[1:] # Skip header row
|
| 35 |
for row in rows:
|
|
@@ -38,19 +42,20 @@ def scrape_wiki_fifa_winners(arg1:int, arg2:str)-> str: #it's import to specify
|
|
| 38 |
year = cols[0].text.strip()
|
| 39 |
winner = cols[1].text.strip()
|
| 40 |
winners.setdefault(categories[idx], {})[year] = winner
|
| 41 |
-
|
| 42 |
return winners
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
return f" Invalid Year"
|
| 51 |
-
#print(f"\n{category} World Cup Winners:")
|
| 52 |
-
|
| 53 |
-
return f" The winner of the {arg2} competition for the year {arg1} is {years[arg1]}"
|
| 54 |
|
| 55 |
|
| 56 |
@tool
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def scrape_wiki_fifa_winners(arg1: int, arg2: str) -> str:
|
| 13 |
+
"""This tool is used to obtain information regarding FIFA World Cup winners
|
| 14 |
+
for the male and female soccer competition.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
arg1 (int): The year of the World Cup.
|
| 18 |
+
arg2 (str): The competition category, either "Men" or "Women".
|
|
|
|
| 19 |
|
| 20 |
+
Returns:
|
| 21 |
+
str: The winner of the given category and year or an error message.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
import requests
|
| 25 |
from bs4 import BeautifulSoup
|
| 26 |
+
|
| 27 |
def get_fifa_winners():
|
| 28 |
url = "https://en.wikipedia.org/wiki/List_of_FIFA_World_Cup_finals"
|
| 29 |
response = requests.get(url)
|
| 30 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 31 |
+
|
| 32 |
winners = {}
|
| 33 |
tables = soup.find_all("table", {"class": "wikitable"})
|
| 34 |
+
|
| 35 |
categories = ["Men", "Women"]
|
| 36 |
+
|
| 37 |
for idx, table in enumerate(tables[:2]): # First two tables (Men's and Women's WC)
|
| 38 |
rows = table.find_all("tr")[1:] # Skip header row
|
| 39 |
for row in rows:
|
|
|
|
| 42 |
year = cols[0].text.strip()
|
| 43 |
winner = cols[1].text.strip()
|
| 44 |
winners.setdefault(categories[idx], {})[year] = winner
|
| 45 |
+
|
| 46 |
return winners
|
| 47 |
+
|
| 48 |
+
if arg2 not in ["Men", "Women"]:
|
| 49 |
+
return "Error: Invalid category. Choose either 'Men' or 'Women'."
|
| 50 |
+
|
| 51 |
+
fifa_winners = get_fifa_winners()
|
| 52 |
|
| 53 |
+
year_str = str(arg1) # Convert year to string since dictionary keys are strings
|
| 54 |
+
if year_str not in fifa_winners[arg2]:
|
| 55 |
+
return f"Error: No data available for the year {arg1} in the {arg2} category."
|
| 56 |
+
|
| 57 |
+
return f"The winner of the {arg2} World Cup in {arg1} was {fifa_winners[arg2][year_str]}."
|
| 58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
@tool
|