Spaces:
Sleeping
Sleeping
Adding tools to get nba data
Browse files- agent.json +4 -1
- app.py +51 -0
- requirements.txt +1 -0
agent.json
CHANGED
|
@@ -49,6 +49,9 @@
|
|
| 49 |
"queue",
|
| 50 |
"time",
|
| 51 |
"collections",
|
| 52 |
-
"re"
|
|
|
|
|
|
|
|
|
|
| 53 |
]
|
| 54 |
}
|
|
|
|
| 49 |
"queue",
|
| 50 |
"time",
|
| 51 |
"collections",
|
| 52 |
+
"re",
|
| 53 |
+
"nba_api",
|
| 54 |
+
"seaborn",
|
| 55 |
+
"matplotlib"
|
| 56 |
]
|
| 57 |
}
|
app.py
CHANGED
|
@@ -3,9 +3,14 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from tools.web_search import DuckDuckGoSearchTool
|
| 8 |
|
|
|
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
@@ -19,6 +24,52 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@tool
|
| 23 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 24 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from typing import List
|
| 8 |
+
from nba_api.stats.static import players
|
| 9 |
+
from nba_api.stats.endpoints import leaguegamefinder,playbyplayv3
|
| 10 |
from tools.final_answer import FinalAnswerTool
|
| 11 |
from tools.web_search import DuckDuckGoSearchTool
|
| 12 |
|
| 13 |
+
|
| 14 |
from Gradio_UI import GradioUI
|
| 15 |
|
| 16 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 24 |
"""
|
| 25 |
return "What magic will you build ?"
|
| 26 |
|
| 27 |
+
@tool
|
| 28 |
+
def get_player_id(player_name:str) -> int:
|
| 29 |
+
"""A tool that fetches the player ID based on the player name.
|
| 30 |
+
Args:
|
| 31 |
+
player_name: The full name of the player.
|
| 32 |
+
Returns:
|
| 33 |
+
The player ID as an integer.
|
| 34 |
+
"""
|
| 35 |
+
try:
|
| 36 |
+
player_id = players.find_player_by_id(player_name)
|
| 37 |
+
return f"Player ID for {player_name} is: {player_id}"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return f"Error fetching player ID for '{player_name}': {str(e)}"
|
| 40 |
+
|
| 41 |
+
@tool
|
| 42 |
+
def get_playergame(player_id:int) -> List[str]:
|
| 43 |
+
"""A tool that fetches the game where a specific player played.
|
| 44 |
+
Args:
|
| 45 |
+
player_id: The ID of the player
|
| 46 |
+
Returns:
|
| 47 |
+
A list of gameids where the player played.
|
| 48 |
+
"""
|
| 49 |
+
try:
|
| 50 |
+
found_games = leaguegamefinder.LeagueGameFinder(player_id_nullable=player_id)
|
| 51 |
+
found_game_ids = found_games.get_data_frames()[0]["GAME_ID"].values.tolist()
|
| 52 |
+
return found_game_ids
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return f"Error fecthing games for player ID '{player_id}': {str(e)}"
|
| 55 |
+
|
| 56 |
+
@tool
|
| 57 |
+
def get_player_games_data(game_ids:List[str]) -> List[pd.DataFrame]:
|
| 58 |
+
""" A tool that fetches the play-by-play data for each games that a specific player played.
|
| 59 |
+
Args:
|
| 60 |
+
game_ids: A list of game IDs
|
| 61 |
+
Returns:
|
| 62 |
+
A list of dataframes containing play-by-play data for each game where a player played in it.
|
| 63 |
+
"""
|
| 64 |
+
try:
|
| 65 |
+
game_data = []
|
| 66 |
+
for game_id in game_ids:
|
| 67 |
+
play_by_play = playbyplayv3.PlayByPlayV3(game_id=game_id).get_data_frames()[0]
|
| 68 |
+
game_data.append(play_by_play)
|
| 69 |
+
return game_data
|
| 70 |
+
except Exception as e:
|
| 71 |
+
return f"Error fetching play-by-play data for game IDs '{game_ids}': {str(e)}"
|
| 72 |
+
|
| 73 |
@tool
|
| 74 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 75 |
"""A tool that fetches the current local time in a specified timezone.
|
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
nba_api
|