jbisal commited on
Commit
47fef3f
·
verified ·
1 Parent(s): 2f07bbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -39
app.py CHANGED
@@ -6,7 +6,7 @@ import yaml
6
  import matplotlib.pyplot as plt
7
  import pandas as pd
8
  import re
9
- from bs4 import BeautifulSoup
10
  from tools.final_answer import FinalAnswerTool
11
 
12
  from Gradio_UI import GradioUI
@@ -30,7 +30,7 @@ def get_box_score_links() -> list:
30
  box_score_links.append(BASE_URL + href)
31
 
32
  # Return unique links while preserving order
33
- return list(dict.fromkeys(box_score_links))[:3] # Limit to first 3 games
34
 
35
  except requests.exceptions.RequestException as e:
36
  # Return error message as a list to maintain consistent return type
@@ -61,18 +61,12 @@ def get_box_score_data(links: list) -> dict:
61
 
62
  # Check if the expected tables exist before accessing
63
  if len(tables) > 0:
64
- df_team1 = tables[0]
65
- # Filter to relevant columns only if they exist
66
- relevant_cols = ['Starters', 'PTS', 'AST', 'TRB']
67
- df_team1 = df_team1[df_team1.columns.intersection(relevant_cols)]
68
- df_team1 = df_team1.dropna().to_dict(orient='records')
69
  else:
70
  df_team1 = [{"Error": "Team 1 data not found"}]
71
 
72
  if len(tables) > 8:
73
- df_team2 = tables[8]
74
- df_team2 = df_team2[df_team2.columns.intersection(relevant_cols)]
75
- df_team2 = df_team2.dropna().to_dict(orient='records')
76
  else:
77
  df_team2 = [{"Error": "Team 2 data not found"}]
78
 
@@ -89,32 +83,6 @@ def get_box_score_data(links: list) -> dict:
89
  except Exception as e:
90
  return {"Error": f"Error fetching boxScore data: {str(e)}"}
91
 
92
-
93
- @tool
94
- def get_stats_from_boxScore_data(box_scores: dict, stat: str) -> dict:
95
- """A tool that fetches the player names and box score statistic for the provided stat and from the provided box score data.
96
- Args:
97
- box_scores: A dictionary representing the box score data for all of last nights games.
98
- stat: A string representing the statistic that this function will return for each player in box_scores.
99
- """
100
- try:
101
- stats = {}
102
- for team, players in box_scores.items():
103
- team_stats = []
104
- for player in players:
105
- # Extract player name and requested stat if it exists
106
- player_name = player.get('Starters', 'Unknown')
107
- stat_value = player.get(stat, 'N/A')
108
- team_stats.append({player_name: stat_value})
109
- stats[team] = team_stats
110
-
111
- return stats
112
-
113
- except Exception as e:
114
- return {"Error": f"Error fetching boxScore data for given statistic: {str(e)}"}
115
-
116
-
117
-
118
  final_answer = FinalAnswerTool()
119
  search_tool = DuckDuckGoSearchTool()
120
  visit_webpage_tool = VisitWebpageTool()
@@ -147,8 +115,7 @@ agent = CodeAgent(
147
  visit_webpage_tool,
148
  user_input_tool,
149
  get_box_score_links,
150
- get_box_score_data,
151
- get_stats_from_boxScore_data
152
  ], # Add your tools here (don't remove final answer)
153
  max_steps=6,
154
  verbosity_level=1,
@@ -161,4 +128,4 @@ agent = CodeAgent(
161
  )
162
 
163
  # Launch Gradio UI
164
- GradioUI(agent).launch()
 
6
  import matplotlib.pyplot as plt
7
  import pandas as pd
8
  import re
9
+ from bs4 import BeautifulSoup # Fixed Import
10
  from tools.final_answer import FinalAnswerTool
11
 
12
  from Gradio_UI import GradioUI
 
30
  box_score_links.append(BASE_URL + href)
31
 
32
  # Return unique links while preserving order
33
+ return list(dict.fromkeys(box_score_links))
34
 
35
  except requests.exceptions.RequestException as e:
36
  # Return error message as a list to maintain consistent return type
 
61
 
62
  # Check if the expected tables exist before accessing
63
  if len(tables) > 0:
64
+ df_team1 = tables[0].to_dict(orient='records')
 
 
 
 
65
  else:
66
  df_team1 = [{"Error": "Team 1 data not found"}]
67
 
68
  if len(tables) > 8:
69
+ df_team2 = tables[8].to_dict(orient='records')
 
 
70
  else:
71
  df_team2 = [{"Error": "Team 2 data not found"}]
72
 
 
83
  except Exception as e:
84
  return {"Error": f"Error fetching boxScore data: {str(e)}"}
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  final_answer = FinalAnswerTool()
87
  search_tool = DuckDuckGoSearchTool()
88
  visit_webpage_tool = VisitWebpageTool()
 
115
  visit_webpage_tool,
116
  user_input_tool,
117
  get_box_score_links,
118
+ get_box_score_data
 
119
  ], # Add your tools here (don't remove final answer)
120
  max_steps=6,
121
  verbosity_level=1,
 
128
  )
129
 
130
  # Launch Gradio UI
131
+ GradioUI(agent).launch()