Pawan2605 commited on
Commit
8f445a2
Β·
verified Β·
1 Parent(s): a19e1b3

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +3 -9
  3. app.py +1071 -0
  4. game_details_with_season-latest.csv +3 -0
  5. requirements.txt +5 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ game_details_with_season-latest.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Player Wise NBA Stats
3
- emoji: 🐒
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.2.0
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Player_Wise_NBA_Stats
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 5.36.2
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,1071 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import plotly.graph_objects as go
4
+ import plotly.express as px
5
+ from plotly.subplots import make_subplots
6
+ import numpy as np
7
+ from sklearn.linear_model import LinearRegression
8
+ import warnings
9
+ warnings.filterwarnings('ignore')
10
+
11
+ # Custom CSS for styling
12
+ custom_css = """
13
+ @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');
14
+
15
+ * {
16
+ font-family: 'JetBrains Mono', monospace !important;
17
+ }
18
+
19
+ .gradio-container {
20
+ background-color: #000000 !important;
21
+ }
22
+
23
+ .tab-nav button {
24
+ background-color: #1a1a1a !important;
25
+ color: #ffffff !important;
26
+ border: 1px solid #ff0000 !important;
27
+ }
28
+
29
+ .tab-nav button.selected {
30
+ background-color: #ff0000 !important;
31
+ color: #ffffff !important;
32
+ }
33
+
34
+ button {
35
+ background-color: #ff0000 !important;
36
+ color: #ffffff !important;
37
+ border: none !important;
38
+ font-weight: bold !important;
39
+ }
40
+
41
+ button:hover {
42
+ background-color: #cc0000 !important;
43
+ }
44
+
45
+ .block {
46
+ background-color: #1a1a1a !important;
47
+ border: 1px solid #333333 !important;
48
+ }
49
+
50
+ label {
51
+ color: #ffffff !important;
52
+ }
53
+
54
+ input, select, textarea {
55
+ background-color: #2a2a2a !important;
56
+ color: #ffffff !important;
57
+ border: 1px solid #ff0000 !important;
58
+ }
59
+ """
60
+
61
+ # Attractive color palettes
62
+ COLOR_PALETTES = {
63
+ 'vibrant': ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2'],
64
+ 'neon': ['#FF006E', '#FFBE0B', '#FB5607', '#8338EC', '#3A86FF', '#06FFA5', '#FF1744', '#00E676'],
65
+ 'sunset': ['#FF6B35', '#F7931E', '#FDC830', '#F37335', '#FF512F', '#DD2476', '#F7971E', '#FFD200'],
66
+ 'ocean': ['#00D9FF', '#0099FF', '#0066FF', '#00FFCC', '#00CC99', '#0099CC', '#33CCFF', '#66CCFF'],
67
+ 'electric': ['#00F5FF', '#00E5FF', '#00D4FF', '#7B68EE', '#9370DB', '#BA55D3', '#DA70D6', '#EE82EE'],
68
+ 'fire': ['#FF4500', '#FF6347', '#FF7F50', '#FF8C00', '#FFA500', '#FFB347', '#FFC04D', '#FFD700']
69
+ }
70
+
71
+ # Load data
72
+ def load_data(file_path):
73
+ df = pd.read_csv(file_path)
74
+
75
+ df['MIN'] = df['MIN'].apply(convert_minutes_to_float)
76
+
77
+ # Force numeric conversion
78
+ numeric_cols = [
79
+ 'PTS','MIN','FGM','FGA','FG3M','FTM','AST','STL','BLK','REB',
80
+ 'DREB','PF','TO','PLUS_MINUS','FG_PCT','FG3_PCT','FT_PCT'
81
+ ]
82
+
83
+ for col in numeric_cols:
84
+ if col in df.columns:
85
+ df[col] = pd.to_numeric(df[col], errors='coerce')
86
+
87
+ df[numeric_cols] = df[numeric_cols].fillna(0)
88
+
89
+ df['SEASON'] = pd.to_numeric(df['SEASON'], errors='coerce').fillna(0).astype(int)
90
+
91
+ return df
92
+
93
+
94
+ def create_empty_figure(message):
95
+ """Create an empty figure with a message"""
96
+ fig = go.Figure()
97
+ fig.add_annotation(
98
+ text=message,
99
+ xref="paper", yref="paper",
100
+ x=0.5, y=0.5, showarrow=False,
101
+ font=dict(size=20, color="white")
102
+ )
103
+ fig.update_layout(
104
+ plot_bgcolor='#1a1a1a',
105
+ paper_bgcolor='#000000',
106
+ font=dict(color='#ffffff', family='JetBrains Mono'),
107
+ xaxis=dict(showgrid=False, showticklabels=False, zeroline=False),
108
+ yaxis=dict(showgrid=False, showticklabels=False, zeroline=False)
109
+ )
110
+ return fig
111
+
112
+
113
+ def convert_minutes_to_float(x):
114
+ if isinstance(x, str) and ':' in x:
115
+ m, s = x.split(':')
116
+ return float(m) + float(s)/60
117
+ return float(x) if pd.notnull(x) else 0
118
+
119
+
120
+
121
+ # Dashboard 1: Top 10 Players by Season
122
+ def dash1_top_players_season(df, season):
123
+ try:
124
+ season_data = df[df['SEASON'] == season].copy()
125
+ if len(season_data) == 0:
126
+ return create_empty_figure(f"No data found for season {season}")
127
+
128
+ player_stats = season_data.groupby('PLAYER_NAME').agg({
129
+ 'PTS': 'sum',
130
+ 'MIN': 'sum'
131
+ }).reset_index()
132
+ top_10 = player_stats.nlargest(10, 'PTS')
133
+
134
+ colors = COLOR_PALETTES['vibrant']
135
+
136
+ fig = go.Figure(data=[
137
+ go.Bar(x=top_10['PLAYER_NAME'], y=top_10['PTS'],
138
+ marker_color=colors,
139
+ text=top_10['PTS'].astype(int),
140
+ textposition='auto',
141
+ textfont=dict(size=12, color='white'))
142
+ ])
143
+ fig.update_layout(
144
+ title=f'Top 10 Players by Total Points - Season {season}',
145
+ xaxis_title='Player',
146
+ yaxis_title='Total Points',
147
+ plot_bgcolor='#1a1a1a',
148
+ paper_bgcolor='#000000',
149
+ font=dict(color='#ffffff', family='JetBrains Mono'),
150
+ xaxis=dict(tickangle=45)
151
+ )
152
+ return fig
153
+ except Exception as e:
154
+ return create_empty_figure(f"Error: {str(e)}")
155
+
156
+ # Dashboard 2: Top 10 Players by Season and Team
157
+ def dash2_top_players_team(df, season, team):
158
+ try:
159
+ filtered = df[(df['SEASON'] == season) & (df['TEAM_ABBREVIATION'] == team)].copy()
160
+ if len(filtered) == 0:
161
+ return create_empty_figure(f"No data found for {team} in season {season}")
162
+
163
+ player_stats = filtered.groupby('PLAYER_NAME')['PTS'].sum().reset_index()
164
+ top_10 = player_stats.nlargest(10, 'PTS')
165
+
166
+ colors = COLOR_PALETTES['ocean']
167
+
168
+ fig = go.Figure(data=[
169
+ go.Bar(x=top_10['PLAYER_NAME'], y=top_10['PTS'],
170
+ marker_color=colors,
171
+ text=top_10['PTS'].astype(int),
172
+ textposition='auto',
173
+ textfont=dict(size=12, color='white'))
174
+ ])
175
+ fig.update_layout(
176
+ title=f'Top 10 Players - {team} - Season {season}',
177
+ xaxis_title='Player',
178
+ yaxis_title='Total Points',
179
+ plot_bgcolor='#1a1a1a',
180
+ paper_bgcolor='#000000',
181
+ font=dict(color='#ffffff', family='JetBrains Mono'),
182
+ xaxis=dict(tickangle=45)
183
+ )
184
+ return fig
185
+ except Exception as e:
186
+ return create_empty_figure(f"Error: {str(e)}")
187
+
188
+ # Dashboard 3: Multi-Player Season-wise Performance Forecast
189
+ def dash3_player_forecast(df, team, players):
190
+ try:
191
+ if not players or len(players) == 0:
192
+ return create_empty_figure("Please select at least one player")
193
+
194
+ filtered = df[df['TEAM_ABBREVIATION'] == team].copy()
195
+ filtered = filtered[filtered['PLAYER_NAME'].isin(players)]
196
+
197
+ if len(filtered) == 0:
198
+ return create_empty_figure("No data found for selected players")
199
+
200
+ metrics = ['PTS', 'MIN', 'FGM', 'FGA', 'FG3M', 'FG3_PCT', 'AST', 'STL', 'BLK']
201
+ metric_names = ['Points', 'Minutes', 'FGM', 'FGA', 'FG3M', 'FG3%', 'Assists', 'Steals', 'Blocks']
202
+
203
+ fig = make_subplots(rows=3, cols=3, subplot_titles=metric_names)
204
+
205
+ colors = COLOR_PALETTES['neon']
206
+
207
+ for idx, metric in enumerate(metrics):
208
+ row = idx // 3 + 1
209
+ col = idx % 3 + 1
210
+
211
+ for p_idx, player in enumerate(players):
212
+ player_data = filtered[filtered['PLAYER_NAME'] == player].copy()
213
+
214
+ if len(player_data) == 0:
215
+ continue
216
+
217
+ player_data[metric] = pd.to_numeric(player_data[metric], errors='coerce')
218
+
219
+ season_stats = player_data.groupby('SEASON')[metric].mean().reset_index()
220
+ season_stats = season_stats.sort_values('SEASON')
221
+ season_stats = season_stats.dropna()
222
+
223
+ if len(season_stats) > 1:
224
+ X = season_stats['SEASON'].values.reshape(-1, 1)
225
+ y = season_stats[metric].values
226
+
227
+ try:
228
+ model = LinearRegression()
229
+ model.fit(X, y)
230
+
231
+ max_season = int(season_stats['SEASON'].max())
232
+
233
+
234
+ fig.add_trace(
235
+ go.Scatter(x=season_stats['SEASON'], y=season_stats[metric],
236
+ mode='lines+markers', name=player,
237
+ line=dict(color=colors[p_idx % len(colors)], width=3),
238
+ marker=dict(size=8),
239
+ showlegend=(idx == 0)),
240
+ row=row, col=col
241
+ )
242
+
243
+
244
+ except:
245
+ continue
246
+
247
+ fig.update_layout(
248
+ height=900,
249
+ title_text=f"Multi-Player Performance Forecast - {team}",
250
+ plot_bgcolor='#1a1a1a',
251
+ paper_bgcolor='#000000',
252
+ font=dict(color='#ffffff', family='JetBrains Mono')
253
+ )
254
+ fig.update_xaxes(showgrid=True, gridcolor='#333333')
255
+ fig.update_yaxes(showgrid=True, gridcolor='#333333')
256
+ return fig
257
+ except Exception as e:
258
+ return create_empty_figure(f"Error: {str(e)}")
259
+
260
+ # Dashboard 4: League-wise Scoring Breakdown (Pie Chart)
261
+ def dash4_scoring_breakdown(df, season, players):
262
+ try:
263
+ if not players or len(players) == 0:
264
+ return create_empty_figure("Please select at least one player")
265
+
266
+ season_data = df[df['SEASON'] == season].copy()
267
+ season_data = season_data[season_data['PLAYER_NAME'].isin(players)]
268
+
269
+ if len(season_data) == 0:
270
+ return create_empty_figure("No data found for selected players in this season")
271
+
272
+ n_players = len(players)
273
+ cols = 2
274
+ rows = int(np.ceil(n_players / cols))
275
+
276
+ # Build subplot grid safely
277
+ specs = []
278
+ for r in range(rows):
279
+ row_specs = []
280
+ for c in range(cols):
281
+ idx = r * cols + c
282
+ if idx < n_players:
283
+ row_specs.append({'type': 'pie'})
284
+ else:
285
+ row_specs.append(None)
286
+ specs.append(row_specs)
287
+
288
+ fig = make_subplots(
289
+ rows=rows,
290
+ cols=cols,
291
+ subplot_titles=players,
292
+ specs=specs
293
+ )
294
+
295
+ pie_colors = COLOR_PALETTES['sunset']
296
+
297
+ for idx, player in enumerate(players):
298
+ row = idx // cols + 1
299
+ col = idx % cols + 1
300
+
301
+ player_data = season_data[season_data['PLAYER_NAME'] == player]
302
+
303
+ # -------- SHOW NO DATA MESSAGE --------
304
+ if len(player_data) == 0:
305
+ continue
306
+
307
+ player_data[['FGM','FG3M','FTM']] = player_data[['FGM','FG3M','FTM']].astype(float)
308
+
309
+ fg2_made = (player_data['FGM'].sum() - player_data['FG3M'].sum())
310
+ fg2_pts = max(0, fg2_made * 2)
311
+ fg3_pts = max(0, player_data['FG3M'].sum() * 3)
312
+ ft_pts = max(0, player_data['FTM'].sum())
313
+
314
+ values = [fg2_pts, fg3_pts, ft_pts]
315
+
316
+ # force pie even when values are zero
317
+ if sum(values) == 0:
318
+ values = [1, 1, 1]
319
+
320
+ fig.add_trace(
321
+ go.Pie(
322
+ labels=['2-Point FG', '3-Point FG', 'Free Throws'],
323
+ values=values,
324
+ marker=dict(colors=pie_colors[:3]),
325
+ textfont=dict(size=14, color='white'),
326
+ hoverinfo='label+percent'
327
+ ),
328
+ row=row,
329
+ col=col
330
+ )
331
+
332
+ fig.update_layout(
333
+ height=400 * rows,
334
+ title_text=f"Scoring Breakdown - Season {season}",
335
+ plot_bgcolor='#1a1a1a',
336
+ paper_bgcolor='#000000',
337
+ font=dict(color='#ffffff', family='JetBrains Mono')
338
+ )
339
+
340
+ return fig
341
+
342
+ except Exception as e:
343
+ return create_empty_figure(f"Error: {str(e)}")
344
+
345
+ # Dashboard 5: Plus-Minus Forecast by Game
346
+ def dash5_plus_minus_forecast(df, season, player):
347
+ try:
348
+ if not player:
349
+ return create_empty_figure("Please select a player")
350
+
351
+ player_data = df[(df['SEASON'] == season) & (df['PLAYER_NAME'] == player)].copy()
352
+
353
+ if len(player_data) < 5:
354
+ return create_empty_figure(f"Not enough data for {player} in season {season}")
355
+
356
+ player_data = player_data.sort_values('GAME_ID').reset_index(drop=True)
357
+ player_data['GAME_NUM'] = range(1, len(player_data) + 1)
358
+ player_data['PLUS_MINUS'] = pd.to_numeric(player_data['PLUS_MINUS'], errors='coerce').fillna(0)
359
+
360
+
361
+ X = player_data['GAME_NUM'].values.reshape(-1, 1)
362
+ y = player_data['PLUS_MINUS'].values
363
+
364
+ model = LinearRegression()
365
+ model.fit(X, y)
366
+
367
+ future_games = np.array(range(len(player_data) + 1, len(player_data) + 6)).reshape(-1, 1)
368
+ predictions = model.predict(future_games)
369
+
370
+ fig = go.Figure()
371
+ fig.add_trace(go.Scatter(
372
+ x=player_data['GAME_NUM'],
373
+ y=player_data['PLUS_MINUS'],
374
+ mode='lines+markers',
375
+ name='Actual',
376
+ line=dict(color='#00D9FF', width=3),
377
+ marker=dict(size=8)
378
+ ))
379
+ fig.add_trace(go.Scatter(
380
+ x=future_games.flatten(),
381
+ y=predictions,
382
+ mode='lines+markers',
383
+ name='Forecast',
384
+ line=dict(color='#FFD700', dash='dash', width=3),
385
+ marker=dict(size=10, symbol='diamond')
386
+ ))
387
+
388
+ fig.update_layout(
389
+ title=f'Plus-Minus Forecast - {player} - Season {season}',
390
+ xaxis_title='Game Number',
391
+ yaxis_title='Plus-Minus',
392
+ plot_bgcolor='#1a1a1a',
393
+ paper_bgcolor='#000000',
394
+ font=dict(color='#ffffff', family='JetBrains Mono'),
395
+ xaxis=dict(showgrid=True, gridcolor='#333333'),
396
+ yaxis=dict(showgrid=True, gridcolor='#333333')
397
+ )
398
+ return fig
399
+ except Exception as e:
400
+ return create_empty_figure("Player has insufficient game history for forecasting")
401
+
402
+
403
+ # Dashboard 6: Team-wise Average Points
404
+ def dash6_team_avg_points(df, season):
405
+ try:
406
+ season_data = df[df['SEASON'] == season].copy()
407
+ if len(season_data) == 0:
408
+ return create_empty_figure(f"No data found for season {season}")
409
+
410
+ team_stats = season_data.groupby('TEAM_ABBREVIATION')['PTS'].mean().reset_index()
411
+ team_stats = team_stats.sort_values('PTS', ascending=False)
412
+
413
+ colors = COLOR_PALETTES['electric']
414
+
415
+ fig = go.Figure(data=[
416
+ go.Bar(x=team_stats['TEAM_ABBREVIATION'], y=team_stats['PTS'],
417
+ marker_color=colors * (len(team_stats) // len(colors) + 1),
418
+ text=team_stats['PTS'].round(1),
419
+ textposition='auto',
420
+ textfont=dict(size=11, color='white'))
421
+ ])
422
+ fig.update_layout(
423
+ title=f'Team-wise Average Points - Season {season}',
424
+ xaxis_title='Team',
425
+ yaxis_title='Average Points',
426
+ plot_bgcolor='#1a1a1a',
427
+ paper_bgcolor='#000000',
428
+ font=dict(color='#ffffff', family='JetBrains Mono'),
429
+ xaxis=dict(tickangle=45)
430
+ )
431
+ return fig
432
+ except Exception as e:
433
+ return create_empty_figure(f"Error: {str(e)}")
434
+
435
+ # Dashboard 7: Team-wise Scoring Breakdown
436
+ def dash7_team_scoring_breakdown(df, season):
437
+ try:
438
+ season_data = df[df['SEASON'] == season].copy()
439
+ if len(season_data) == 0:
440
+ return create_empty_figure(f"No data found for season {season}")
441
+
442
+ teams = sorted(season_data['TEAM_ABBREVIATION'].unique())
443
+
444
+ n_teams = len(teams)
445
+ cols = 4
446
+ rows = (n_teams + 3) // 4
447
+
448
+ fig = make_subplots(rows=rows, cols=cols, subplot_titles=teams,
449
+ specs=[[{'type': 'pie'}] * cols for _ in range(rows)])
450
+
451
+ pie_colors = COLOR_PALETTES['fire']
452
+
453
+ for idx, team in enumerate(teams):
454
+ row = idx // cols + 1
455
+ col = idx % cols + 1
456
+
457
+ team_data = season_data[season_data['TEAM_ABBREVIATION'] == team]
458
+ fg2_made = (team_data['FGM'].sum() - team_data['FG3M'].sum())
459
+ fg2_pts = max(0, fg2_made * 2)
460
+ fg3_pts = max(0, team_data['FG3M'].sum() * 3)
461
+ ft_pts = max(0, team_data['FTM'].sum())
462
+
463
+ fig.add_trace(
464
+ go.Pie(labels=['2-PT', '3-PT', 'FT'],
465
+ values=[fg2_pts, fg3_pts, ft_pts],
466
+ marker=dict(colors=pie_colors[:3]),
467
+ textfont=dict(size=10, color='white'),
468
+ showlegend=(idx == 0)),
469
+ row=row, col=col
470
+ )
471
+
472
+ fig.update_layout(
473
+ height=250 * rows,
474
+ title_text=f"Team-wise Scoring Breakdown - Season {season}",
475
+ plot_bgcolor='#1a1a1a',
476
+ paper_bgcolor='#000000',
477
+ font=dict(color='#ffffff', family='JetBrains Mono')
478
+ )
479
+ return fig
480
+ except Exception as e:
481
+ return create_empty_figure(f"Error: {str(e)}")
482
+
483
+ # Dashboard 8: Team Rebounding Strength
484
+ def dash8_team_rebounds(df, season):
485
+ try:
486
+ season_data = df[df['SEASON'] == season].copy()
487
+ if len(season_data) == 0:
488
+ return create_empty_figure(f"No data found for season {season}")
489
+
490
+ team_stats = season_data.groupby('TEAM_ABBREVIATION')['REB'].sum().reset_index()
491
+ team_stats = team_stats.sort_values('REB', ascending=False)
492
+
493
+ colors = COLOR_PALETTES['ocean']
494
+
495
+ fig = go.Figure(data=[
496
+ go.Bar(x=team_stats['TEAM_ABBREVIATION'], y=team_stats['REB'],
497
+ marker_color=colors * (len(team_stats) // len(colors) + 1),
498
+ text=team_stats['REB'].astype(int),
499
+ textposition='auto',
500
+ textfont=dict(size=11, color='white'))
501
+ ])
502
+ fig.update_layout(
503
+ title=f'Team Rebounding Strength - Season {season}',
504
+ xaxis_title='Team',
505
+ yaxis_title='Total Rebounds',
506
+ plot_bgcolor='#1a1a1a',
507
+ paper_bgcolor='#000000',
508
+ font=dict(color='#ffffff', family='JetBrains Mono'),
509
+ xaxis=dict(tickangle=45)
510
+ )
511
+ return fig
512
+ except Exception as e:
513
+ return create_empty_figure(f"Error: {str(e)}")
514
+
515
+ # Dashboard 9: Team Fouls and Turnovers
516
+ def dash9_fouls_turnovers(df, season):
517
+ try:
518
+ season_data = df[df['SEASON'] == season].copy()
519
+ if len(season_data) == 0:
520
+ return create_empty_figure(f"No data found for season {season}")
521
+
522
+ team_stats = season_data.groupby('TEAM_ABBREVIATION').agg({
523
+ 'PF': 'mean',
524
+ 'TO': 'mean'
525
+ }).reset_index()
526
+ team_stats = team_stats.sort_values('PF', ascending=False)
527
+
528
+ fig = go.Figure()
529
+ fig.add_trace(go.Bar(
530
+ x=team_stats['TEAM_ABBREVIATION'],
531
+ y=team_stats['PF'],
532
+ name='Avg Fouls',
533
+ marker_color='#FF6B6B',
534
+ text=team_stats['PF'].round(1),
535
+ textposition='auto'
536
+ ))
537
+ fig.add_trace(go.Bar(
538
+ x=team_stats['TEAM_ABBREVIATION'],
539
+ y=team_stats['TO'],
540
+ name='Avg Turnovers',
541
+ marker_color='#4ECDC4',
542
+ text=team_stats['TO'].round(1),
543
+ textposition='auto'
544
+ ))
545
+
546
+ fig.update_layout(
547
+ title=f'Team Fouls and Turnovers - Season {season}',
548
+ xaxis_title='Team',
549
+ yaxis_title='Average Count',
550
+ barmode='group',
551
+ plot_bgcolor='#1a1a1a',
552
+ paper_bgcolor='#000000',
553
+ font=dict(color='#ffffff', family='JetBrains Mono'),
554
+ xaxis=dict(tickangle=45)
555
+ )
556
+ return fig
557
+ except Exception as e:
558
+ return create_empty_figure(f"Error: {str(e)}")
559
+
560
+ # Dashboard 10: Top Players by Role (League-wide)
561
+ def dash10_top_players_role(df, season):
562
+ try:
563
+ season_data = df[df['SEASON'] == season].copy()
564
+ if len(season_data) == 0:
565
+ return create_empty_figure(f"No data found for season {season}")
566
+
567
+ scoring = season_data.groupby('PLAYER_NAME')['PTS'].sum().nlargest(10).reset_index()
568
+ playmaking = season_data.groupby('PLAYER_NAME')['AST'].sum().nlargest(10).reset_index()
569
+ rebounding = season_data.groupby('PLAYER_NAME')['REB'].sum().nlargest(10).reset_index()
570
+
571
+ fig = make_subplots(rows=1, cols=3, subplot_titles=['Scoring Leaders', 'Playmaking Leaders', 'Rebounding Leaders'])
572
+
573
+ fig.add_trace(go.Bar(
574
+ x=scoring['PLAYER_NAME'],
575
+ y=scoring['PTS'],
576
+ marker_color=COLOR_PALETTES['vibrant'][0],
577
+ text=scoring['PTS'].astype(int),
578
+ textposition='auto',
579
+ showlegend=False
580
+ ), row=1, col=1)
581
+
582
+ fig.add_trace(go.Bar(
583
+ x=playmaking['PLAYER_NAME'],
584
+ y=playmaking['AST'],
585
+ marker_color=COLOR_PALETTES['vibrant'][1],
586
+ text=playmaking['AST'].astype(int),
587
+ textposition='auto',
588
+ showlegend=False
589
+ ), row=1, col=2)
590
+
591
+ fig.add_trace(go.Bar(
592
+ x=rebounding['PLAYER_NAME'],
593
+ y=rebounding['REB'],
594
+ marker_color=COLOR_PALETTES['vibrant'][2],
595
+ text=rebounding['REB'].astype(int),
596
+ textposition='auto',
597
+ showlegend=False
598
+ ), row=1, col=3)
599
+
600
+ fig.update_xaxes(tickangle=45)
601
+ fig.update_layout(
602
+ height=500,
603
+ title_text=f"Top Players by Role - Season {season}",
604
+ plot_bgcolor='#1a1a1a',
605
+ paper_bgcolor='#000000',
606
+ font=dict(color='#ffffff', family='JetBrains Mono')
607
+ )
608
+ return fig
609
+ except Exception as e:
610
+ return create_empty_figure(f"Error: {str(e)}")
611
+
612
+ # Dashboard 11: Top Players by Role (Team-specific)
613
+ def dash11_top_players_team_role(df, season, team):
614
+ try:
615
+ season_data = df[(df['SEASON'] == season) & (df['TEAM_ABBREVIATION'] == team)].copy()
616
+ if len(season_data) == 0:
617
+ return create_empty_figure(f"No data found for {team} in season {season}")
618
+
619
+ scoring = season_data.groupby('PLAYER_NAME')['PTS'].sum().nlargest(5).reset_index()
620
+ playmaking = season_data.groupby('PLAYER_NAME')['AST'].sum().nlargest(5).reset_index()
621
+ rebounding = season_data.groupby('PLAYER_NAME')['REB'].sum().nlargest(5).reset_index()
622
+
623
+ fig = make_subplots(rows=1, cols=3, subplot_titles=['Scoring', 'Playmaking', 'Rebounding'])
624
+
625
+ fig.add_trace(go.Bar(
626
+ x=scoring['PLAYER_NAME'],
627
+ y=scoring['PTS'],
628
+ marker_color=COLOR_PALETTES['neon'][0],
629
+ text=scoring['PTS'].astype(int),
630
+ textposition='auto',
631
+ showlegend=False
632
+ ), row=1, col=1)
633
+
634
+ fig.add_trace(go.Bar(
635
+ x=playmaking['PLAYER_NAME'],
636
+ y=playmaking['AST'],
637
+ marker_color=COLOR_PALETTES['neon'][1],
638
+ text=playmaking['AST'].astype(int),
639
+ textposition='auto',
640
+ showlegend=False
641
+ ), row=1, col=2)
642
+
643
+ fig.add_trace(go.Bar(
644
+ x=rebounding['PLAYER_NAME'],
645
+ y=rebounding['REB'],
646
+ marker_color=COLOR_PALETTES['neon'][2],
647
+ text=rebounding['REB'].astype(int),
648
+ textposition='auto',
649
+ showlegend=False
650
+ ), row=1, col=3)
651
+
652
+ fig.update_xaxes(tickangle=45)
653
+ fig.update_layout(
654
+ height=500,
655
+ title_text=f"Top Players by Role - {team} - Season {season}",
656
+ plot_bgcolor='#1a1a1a',
657
+ paper_bgcolor='#000000',
658
+ font=dict(color='#ffffff', family='JetBrains Mono')
659
+ )
660
+ return fig
661
+ except Exception as e:
662
+ return create_empty_figure(f"Error: {str(e)}")
663
+
664
+ # Dashboard 12: Team Shot Profile
665
+ def dash12_team_shot_profile(df, season):
666
+ try:
667
+ season_data = df[df['SEASON'] == season].copy()
668
+ if len(season_data) == 0:
669
+ return create_empty_figure(f"No data found for season {season}")
670
+
671
+ team_stats = season_data.groupby('TEAM_ABBREVIATION').agg({
672
+ 'FG_PCT': 'mean',
673
+ 'FG3_PCT': 'mean',
674
+ 'FT_PCT': 'mean'
675
+ }).reset_index()
676
+
677
+ fig = go.Figure()
678
+ fig.add_trace(go.Bar(
679
+ x=team_stats['TEAM_ABBREVIATION'],
680
+ y=team_stats['FG_PCT'],
681
+ name='FG%',
682
+ marker_color='#FF6B35',
683
+ text=(team_stats['FG_PCT'] * 100).round(1),
684
+ textposition='auto'
685
+ ))
686
+ fig.add_trace(go.Bar(
687
+ x=team_stats['TEAM_ABBREVIATION'],
688
+ y=team_stats['FG3_PCT'],
689
+ name='3P%',
690
+ marker_color='#F7931E',
691
+ text=(team_stats['FG3_PCT'] * 100).round(1),
692
+ textposition='auto'
693
+ ))
694
+ fig.add_trace(go.Bar(
695
+ x=team_stats['TEAM_ABBREVIATION'],
696
+ y=team_stats['FT_PCT'],
697
+ name='FT%',
698
+ marker_color='#FDC830',
699
+ text=(team_stats['FT_PCT'] * 100).round(1),
700
+ textposition='auto'
701
+ ))
702
+
703
+ fig.update_layout(
704
+ title=f'Team Shot Profile - Season {season}',
705
+ xaxis_title='Team',
706
+ yaxis_title='Percentage',
707
+ barmode='group',
708
+ plot_bgcolor='#1a1a1a',
709
+ paper_bgcolor='#000000',
710
+ font=dict(color='#ffffff', family='JetBrains Mono'),
711
+ xaxis=dict(tickangle=45)
712
+ )
713
+ return fig
714
+ except Exception as e:
715
+ return create_empty_figure(f"Error: {str(e)}")
716
+
717
+ # Dashboard 13: Dependency on Top Scorer
718
+ def dash13_top_scorer_dependency(df, season):
719
+ try:
720
+ season_data = df[df['SEASON'] == season].copy()
721
+ if len(season_data) == 0:
722
+ return create_empty_figure(f"No data found for season {season}")
723
+
724
+ team_total = season_data.groupby('TEAM_ABBREVIATION')['PTS'].sum()
725
+
726
+ dependencies = []
727
+ for team in team_total.index:
728
+ team_data = season_data[season_data['TEAM_ABBREVIATION'] == team]
729
+ top_scorer = team_data.groupby('PLAYER_NAME')['PTS'].sum().max()
730
+ dependency = (top_scorer / team_total[team]) * 100
731
+ dependencies.append({'Team': team, 'Dependency': dependency})
732
+
733
+ dep_df = pd.DataFrame(dependencies).sort_values('Dependency', ascending=False)
734
+
735
+ colors = COLOR_PALETTES['sunset']
736
+
737
+ fig = go.Figure(data=[
738
+ go.Bar(x=dep_df['Team'], y=dep_df['Dependency'],
739
+ marker_color=colors * (len(dep_df) // len(colors) + 1),
740
+ text=dep_df['Dependency'].round(1),
741
+ textposition='auto',
742
+ textfont=dict(size=11, color='white'))
743
+ ])
744
+ fig.update_layout(
745
+ title=f'Team Dependency on Top Scorer - Season {season}',
746
+ xaxis_title='Team',
747
+ yaxis_title='Dependency (%)',
748
+ plot_bgcolor='#1a1a1a',
749
+ paper_bgcolor='#000000',
750
+ font=dict(color='#ffffff', family='JetBrains Mono'),
751
+ xaxis=dict(tickangle=45)
752
+ )
753
+ return fig
754
+ except Exception as e:
755
+ return create_empty_figure(f"Error: {str(e)}")
756
+
757
+ # Dashboard 14: Most Efficient Low-Usage Players
758
+ def dash14_efficient_low_usage(df, season, team):
759
+ try:
760
+ season_data = df[(df['SEASON'] == season) & (df['TEAM_ABBREVIATION'] == team)].copy()
761
+
762
+ if len(season_data) == 0:
763
+ return create_empty_figure(f"No data available for {team} in season {season}")
764
+
765
+ player_stats = season_data.groupby('PLAYER_NAME').agg({
766
+ 'PTS': 'sum',
767
+ 'MIN': 'sum',
768
+ 'FGA': 'sum'
769
+ }).reset_index()
770
+
771
+ player_stats[['PTS','MIN','FGA']] = player_stats[['PTS','MIN','FGA']].astype(float)
772
+
773
+ player_stats = player_stats[player_stats['MIN'] > 300]
774
+
775
+ if len(player_stats) == 0:
776
+ return create_empty_figure("No players with sufficient minutes")
777
+
778
+ player_stats['PPM'] = player_stats['PTS'] / player_stats['MIN']
779
+ player_stats['Usage'] = player_stats['FGA']
780
+
781
+ median_usage = player_stats['Usage'].median()
782
+ low_usage = player_stats[player_stats['Usage'] <= median_usage]
783
+ low_usage = low_usage.sort_values('PPM', ascending=False).head(10)
784
+
785
+ colors = COLOR_PALETTES['electric']
786
+
787
+ fig = go.Figure(data=[
788
+ go.Bar(x=low_usage['PLAYER_NAME'], y=low_usage['PPM'],
789
+ marker_color=colors * (len(low_usage) // len(colors) + 1),
790
+ text=low_usage['PPM'].round(3),
791
+ textposition='auto',
792
+ textfont=dict(size=11, color='white'))
793
+ ])
794
+ fig.update_layout(
795
+ title=f'Most Efficient Low-Usage Players - {team} - Season {season}',
796
+ xaxis_title='Player',
797
+ yaxis_title='Points Per Minute',
798
+ plot_bgcolor='#1a1a1a',
799
+ paper_bgcolor='#000000',
800
+ font=dict(color='#ffffff', family='JetBrains Mono'),
801
+ xaxis=dict(tickangle=45)
802
+ )
803
+ return fig
804
+ except Exception as e:
805
+ return create_empty_figure(f"Error: {str(e)}")
806
+
807
+ # Dashboard 15: Top Defensive Impact Players
808
+ def dash15_defensive_impact(df, season, team):
809
+ try:
810
+ season_data = df[(df['SEASON'] == season) & (df['TEAM_ABBREVIATION'] == team)].copy()
811
+
812
+ if len(season_data) == 0:
813
+ return create_empty_figure(f"No data available for {team} in season {season}")
814
+
815
+ player_stats = season_data.groupby('PLAYER_NAME').agg({
816
+ 'STL': 'sum',
817
+ 'BLK': 'sum',
818
+ 'DREB': 'sum'
819
+ }).reset_index()
820
+
821
+ player_stats['DEF_IMPACT'] = player_stats['STL'] + player_stats['BLK'] + player_stats['DREB'] * 0.5
822
+ player_stats = player_stats.sort_values('DEF_IMPACT', ascending=False).head(10)
823
+
824
+ colors = COLOR_PALETTES['ocean']
825
+
826
+ fig = go.Figure(data=[
827
+ go.Bar(x=player_stats['PLAYER_NAME'], y=player_stats['DEF_IMPACT'],
828
+ marker_color=colors * (len(player_stats) // len(colors) + 1),
829
+ text=player_stats['DEF_IMPACT'].round(1),
830
+ textposition='auto',
831
+ textfont=dict(size=11, color='white'))
832
+ ])
833
+ fig.update_layout(
834
+ title=f'Top Defensive Impact Players - {team} - Season {season}',
835
+ xaxis_title='Player',
836
+ yaxis_title='Defensive Impact Score',
837
+ plot_bgcolor='#1a1a1a',
838
+ paper_bgcolor='#000000',
839
+ font=dict(color='#ffffff', family='JetBrains Mono'),
840
+ xaxis=dict(tickangle=45)
841
+ )
842
+ return fig
843
+ except Exception as e:
844
+ return create_empty_figure(f"Error: {str(e)}")
845
+
846
+ # Dashboard 16: Points per Minute Leaders
847
+ def dash16_points_per_minute(df, season, team):
848
+ try:
849
+ season_data = df[(df['SEASON'] == season) & (df['TEAM_ABBREVIATION'] == team)].copy()
850
+
851
+ if len(season_data) == 0:
852
+ return create_empty_figure(f"No data available for {team} in season {season}")
853
+
854
+ player_stats = season_data.groupby('PLAYER_NAME').agg({
855
+ 'PTS': 'sum',
856
+ 'MIN': 'sum'
857
+ }).reset_index()
858
+
859
+ player_stats = player_stats[player_stats['MIN'].astype(float) > 100]
860
+
861
+
862
+ if len(player_stats) == 0:
863
+ return create_empty_figure("No players with sufficient minutes")
864
+
865
+ player_stats['PPM'] = player_stats['PTS'] / player_stats['MIN']
866
+ player_stats = player_stats.sort_values('PPM', ascending=False)
867
+
868
+ colors = COLOR_PALETTES['vibrant']
869
+
870
+ fig = go.Figure(data=[
871
+ go.Bar(x=player_stats['PLAYER_NAME'], y=player_stats['PPM'],
872
+ marker_color=colors * (len(player_stats) // len(colors) + 1),
873
+ text=player_stats['PPM'].round(3),
874
+ textposition='auto',
875
+ textfont=dict(size=11, color='white'))
876
+ ])
877
+ fig.update_layout(
878
+ title=f'Points Per Minute Leaders - {team} - Season {season}',
879
+ xaxis_title='Player',
880
+ yaxis_title='Points Per Minute',
881
+ plot_bgcolor='#1a1a1a',
882
+ paper_bgcolor='#000000',
883
+ font=dict(color='#ffffff', family='JetBrains Mono'),
884
+ xaxis=dict(tickangle=45)
885
+ )
886
+ return fig
887
+ except Exception as e:
888
+ return create_empty_figure(f"Error: {str(e)}")
889
+
890
+ # Create Gradio Interface
891
+ def create_dashboard(csv_path):
892
+ df = load_data(csv_path)
893
+ seasons = sorted(df['SEASON'].unique().tolist())
894
+ teams = sorted(df['TEAM_ABBREVIATION'].unique().tolist())
895
+ all_players = sorted(df['PLAYER_NAME'].unique().tolist())
896
+
897
+ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
898
+ gr.Markdown("# πŸ€ NBA Advanced Analytics Dashboard")
899
+ gr.Markdown("### Comprehensive Player & Team Performance Analysis")
900
+
901
+ with gr.Tabs():
902
+ # Dashboard 1
903
+ with gr.Tab("πŸ“Š Top 10 Players by Season"):
904
+ with gr.Row():
905
+ d1_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
906
+ d1_btn = gr.Button("Generate Chart", variant="primary")
907
+ d1_plot = gr.Plot()
908
+ d1_btn.click(dash1_top_players_season, inputs=[gr.State(df), d1_season], outputs=d1_plot)
909
+
910
+ # Dashboard 2
911
+ with gr.Tab("πŸ† Top 10 Players by Team"):
912
+ with gr.Row():
913
+ d2_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
914
+ d2_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
915
+ d2_btn = gr.Button("Generate Chart", variant="primary")
916
+ d2_plot = gr.Plot()
917
+ d2_btn.click(dash2_top_players_team, inputs=[gr.State(df), d2_season, d2_team], outputs=d2_plot)
918
+
919
+ # Dashboard 3 - FIXED
920
+ with gr.Tab("πŸ“ˆ Multi-Player Forecast"):
921
+ with gr.Row():
922
+ d3_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
923
+
924
+ # Get initial player list for first team
925
+ initial_players = sorted(df[df['TEAM_ABBREVIATION'] == teams[0]]['PLAYER_NAME'].unique().tolist())
926
+
927
+ with gr.Row():
928
+ d3_players = gr.Dropdown(
929
+ choices=initial_players, label="Select Players (up to 5)", multiselect=True
930
+ )
931
+ d3_btn = gr.Button("Generate Forecast", variant="primary")
932
+ d3_plot = gr.Plot()
933
+
934
+ def update_player_list(team):
935
+ players = sorted(df[df['TEAM_ABBREVIATION'] == team]['PLAYER_NAME'].unique().tolist())
936
+ return gr.Dropdown(choices=players, value=[])
937
+
938
+ d3_team.change(update_player_list, inputs=d3_team, outputs=d3_players)
939
+ d3_btn.click(dash3_player_forecast, inputs=[gr.State(df), d3_team, d3_players], outputs=d3_plot)
940
+
941
+ # Dashboard 4
942
+ with gr.Tab("πŸ₯§ Scoring Breakdown"):
943
+ with gr.Row():
944
+ d4_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
945
+ with gr.Row():
946
+ d4_players = gr.Dropdown(
947
+ choices=all_players,
948
+ label="Select Players (1-6)",
949
+ multiselect=True
950
+ )
951
+ d4_btn = gr.Button("Generate Chart", variant="primary")
952
+ d4_plot = gr.Plot()
953
+ d4_btn.click(dash4_scoring_breakdown, inputs=[gr.State(df), d4_season, d4_players], outputs=d4_plot)
954
+
955
+ # Dashboard 5
956
+ with gr.Tab("βž•βž– Plus-Minus Forecast"):
957
+ with gr.Row():
958
+ d5_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
959
+ d5_player = gr.Dropdown(choices=all_players, label="Select Player", value=all_players[0])
960
+ d5_btn = gr.Button("Generate Forecast", variant="primary")
961
+ d5_plot = gr.Plot()
962
+ d5_btn.click(dash5_plus_minus_forecast, inputs=[gr.State(df), d5_season, d5_player], outputs=d5_plot)
963
+
964
+ # Dashboard 6
965
+ with gr.Tab("🎯 Team Average Points"):
966
+ with gr.Row():
967
+ d6_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
968
+ d6_btn = gr.Button("Generate Chart", variant="primary")
969
+ d6_plot = gr.Plot()
970
+ d6_btn.click(dash6_team_avg_points, inputs=[gr.State(df), d6_season], outputs=d6_plot)
971
+
972
+ # Dashboard 7
973
+ with gr.Tab("πŸ“Š Team Scoring Breakdown"):
974
+ with gr.Row():
975
+ d7_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
976
+ d7_btn = gr.Button("Generate Chart", variant="primary")
977
+ d7_plot = gr.Plot()
978
+ d7_btn.click(dash7_team_scoring_breakdown, inputs=[gr.State(df), d7_season], outputs=d7_plot)
979
+
980
+ # Dashboard 8
981
+ with gr.Tab("πŸ€ Team Rebounding"):
982
+ with gr.Row():
983
+ d8_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
984
+ d8_btn = gr.Button("Generate Chart", variant="primary")
985
+ d8_plot = gr.Plot()
986
+ d8_btn.click(dash8_team_rebounds, inputs=[gr.State(df), d8_season], outputs=d8_plot)
987
+
988
+ # Dashboard 9
989
+ with gr.Tab("⚠️ Fouls & Turnovers"):
990
+ with gr.Row():
991
+ d9_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
992
+ d9_btn = gr.Button("Generate Chart", variant="primary")
993
+ d9_plot = gr.Plot()
994
+ d9_btn.click(dash9_fouls_turnovers, inputs=[gr.State(df), d9_season], outputs=d9_plot)
995
+
996
+ # Dashboard 10
997
+ with gr.Tab("🌟 Top Players by Role"):
998
+ with gr.Row():
999
+ d10_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1000
+ d10_btn = gr.Button("Generate Chart", variant="primary")
1001
+ d10_plot = gr.Plot()
1002
+ d10_btn.click(dash10_top_players_role, inputs=[gr.State(df), d10_season], outputs=d10_plot)
1003
+
1004
+ # Dashboard 11
1005
+ with gr.Tab("πŸ‘₯ Team Role Leaders"):
1006
+ with gr.Row():
1007
+ d11_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1008
+ d11_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
1009
+ d11_btn = gr.Button("Generate Chart", variant="primary")
1010
+ d11_plot = gr.Plot()
1011
+ d11_btn.click(dash11_top_players_team_role, inputs=[gr.State(df), d11_season, d11_team], outputs=d11_plot)
1012
+
1013
+ # Dashboard 12
1014
+ with gr.Tab("🎯 Team Shot Profile"):
1015
+ with gr.Row():
1016
+ d12_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1017
+ d12_btn = gr.Button("Generate Chart", variant="primary")
1018
+ d12_plot = gr.Plot()
1019
+ d12_btn.click(dash12_team_shot_profile, inputs=[gr.State(df), d12_season], outputs=d12_plot)
1020
+
1021
+ # Dashboard 13
1022
+ with gr.Tab("πŸ“Œ Top Scorer Dependency"):
1023
+ with gr.Row():
1024
+ d13_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1025
+ d13_btn = gr.Button("Generate Chart", variant="primary")
1026
+ d13_plot = gr.Plot()
1027
+ d13_btn.click(dash13_top_scorer_dependency, inputs=[gr.State(df), d13_season], outputs=d13_plot)
1028
+
1029
+ # Dashboard 14
1030
+ with gr.Tab("πŸ’‘ Efficient Low-Usage"):
1031
+ with gr.Row():
1032
+ d14_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1033
+ d14_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
1034
+ d14_btn = gr.Button("Generate Chart", variant="primary")
1035
+ d14_plot = gr.Plot()
1036
+ d14_btn.click(dash14_efficient_low_usage, inputs=[gr.State(df), d14_season, d14_team], outputs=d14_plot)
1037
+
1038
+ # Dashboard 15
1039
+ with gr.Tab("πŸ›‘οΈ Defensive Impact"):
1040
+ with gr.Row():
1041
+ d15_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1042
+ d15_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
1043
+ d15_btn = gr.Button("Generate Chart", variant="primary")
1044
+ d15_plot = gr.Plot()
1045
+ d15_btn.click(dash15_defensive_impact, inputs=[gr.State(df), d15_season, d15_team], outputs=d15_plot)
1046
+
1047
+ # Dashboard 16
1048
+ with gr.Tab("⚑ Points Per Minute"):
1049
+ with gr.Row():
1050
+ d16_season = gr.Dropdown(choices=seasons, label="Select Season", value=seasons[-1])
1051
+ d16_team = gr.Dropdown(choices=teams, label="Select Team", value=teams[0])
1052
+ d16_btn = gr.Button("Generate Chart", variant="primary")
1053
+ d16_plot = gr.Plot()
1054
+ d16_btn.click(dash16_points_per_minute, inputs=[gr.State(df), d16_season, d16_team], outputs=d16_plot)
1055
+
1056
+ return demo
1057
+
1058
+ # Main execution
1059
+ if __name__ == "__main__":
1060
+ # REPLACE THIS PATH WITH YOUR CSV FILE PATH
1061
+ CSV_PATH = "game_details_with_season-latest.csv"
1062
+
1063
+ print("πŸ€ Loading NBA Analytics Dashboard...")
1064
+ print(f"πŸ“‚ Reading data from: {CSV_PATH}")
1065
+
1066
+ demo = create_dashboard(CSV_PATH)
1067
+
1068
+ print("βœ… Dashboard ready!")
1069
+ print("🌐 Launching on http://localhost:7860")
1070
+
1071
+ demo.launch(share=False, server_name="0.0.0.0", server_port=7860)
game_details_with_season-latest.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd0b707720ce3a6f8c8dab89fb773009b5ac9f0aa980136e99a04057ecf8830e
3
+ size 81561946
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ plotly
4
+ scikit-learn
5
+ numpy