Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,49 @@ 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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
arg1: the
|
| 17 |
-
arg2: the
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +90,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer,
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 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: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""This tool is used to obtain information regarding FIFA World Cup winners for the male and female soccer competition
|
| 15 |
Args:
|
| 16 |
+
arg1: this argument accepts an integer denoting the year
|
| 17 |
+
arg2: this argument accepts a string denoting if the competition to be checked is either for the Male or Female Soccer competition
|
| 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:
|
| 36 |
+
cols = row.find_all("td")
|
| 37 |
+
if len(cols) >= 2:
|
| 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 |
+
if __name__ == "__main__":
|
| 45 |
+
if arg2 not in ["Men", "Women"]:
|
| 46 |
+
return f" Invalid Category"
|
| 47 |
+
fifa_winners = get_fifa_winners()
|
| 48 |
+
years=fifa_winners[arg2]
|
| 49 |
+
if arg1 not in years:
|
| 50 |
+
return f" Invalid Year"
|
| 51 |
+
#print(f"\n{category} World Cup Winners:")
|
| 52 |
+
|
| 53 |
+
return f" The winner of the {arg2}'s competition for the year {arg1} is {years[arg1]}"
|
| 54 |
+
|
| 55 |
|
| 56 |
@tool
|
| 57 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 90 |
|
| 91 |
agent = CodeAgent(
|
| 92 |
model=model,
|
| 93 |
+
tools=[final_answer,scrape_wiki_fifa_winners, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 94 |
max_steps=6,
|
| 95 |
verbosity_level=1,
|
| 96 |
grammar=None,
|