lrschuman17 commited on
Commit
c52059f
·
verified ·
1 Parent(s): 653a2a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -5
app.py CHANGED
@@ -15,6 +15,82 @@ st.set_page_config(
15
  layout="centered"
16
  )
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  team_logo_paths = {
20
  "Cleveland Cavaliers": "Clevelan-Cavaliers-logo-2022.png",
@@ -142,8 +218,16 @@ def main():
142
  player_data = load_player_data()
143
  rf_model = load_rf_model()
144
 
145
- # Sidebar inputs
146
- st.sidebar.header("Player and Injury Input")
 
 
 
 
 
 
 
 
147
 
148
  # Dropdown for player selection
149
  player_list = sorted(player_data['player_name'].dropna().unique())
@@ -206,12 +290,36 @@ def main():
206
  input_data = input_data.reindex(columns=rf_model.feature_names_in_, fill_value=0)
207
 
208
  # Predict and display results
209
- if st.sidebar.button("Predict"):
 
210
  predictions = rf_model.predict(input_data)
211
- prediction_columns = ["Predicted Change in PTS", "Predicted Change in REB", "Predicted Change inAST"]
212
  st.subheader("Predicted Post-Injury Performance")
213
  st.write("Based on the inputs, here are the predicted metrics:")
214
- st.table(pd.DataFrame(predictions, columns=prediction_columns))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  except FileNotFoundError:
216
  st.error("Model file not found.")
217
  except ValueError as e:
 
15
  layout="centered"
16
  )
17
 
18
+ # Custom CSS for vibrant NBA sidebar styling
19
+ st.markdown(
20
+ """
21
+ <style>
22
+ body {
23
+ background: linear-gradient(to bottom, #0033a0, #ed174c); /* NBA team colors gradient */
24
+ font-family: 'Trebuchet MS', sans-serif;
25
+ margin: 0;
26
+ padding: 0;
27
+ color: white; /* Set text color to white */
28
+ }
29
+ .sidebar .sidebar-content {
30
+ background: linear-gradient(to bottom, #4B0082, #1E90FF); /* Purple to blue gradient */
31
+ border-radius: 10px;
32
+ padding: 10px;
33
+ color: #ffffff; /* Set sidebar text color to white */
34
+ }
35
+ .stSidebar h2 {
36
+ color: #ffffff;
37
+ text-align: center;
38
+ font-size: 20px;
39
+ font-weight: bold;
40
+ text-shadow: 2px 2px #000000;
41
+ }
42
+ .stButton > button {
43
+ background-color: #ffcc00; /* Bold yellow */
44
+ color: #0033a0; /* Button text color */
45
+ border: none;
46
+ border-radius: 5px;
47
+ padding: 10px 15px;
48
+ font-size: 16px;
49
+ transition: background-color 0.3s ease;
50
+ }
51
+ .stButton > button:hover {
52
+ background-color: #ffc107; /* Brighter yellow */
53
+ box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.2);
54
+ }
55
+ .stMarkdown h1, .stMarkdown h2, .stMarkdown h3 {
56
+ color: #ffffff; /* Set headings color to white */
57
+ text-shadow: 2px 2px #000000; /* Add shadow for better visibility */
58
+ }
59
+ .block-container {
60
+ border-radius: 10px;
61
+ padding: 20px;
62
+ background-color: rgba(0, 0, 0, 0.8); /* Dark semi-transparent background */
63
+ color: #ffffff; /* Ensure text inside the container is white */
64
+ }
65
+ .dataframe {
66
+ background-color: rgba(255, 255, 255, 0.1); /* Transparent table background */
67
+ color: #ffffff; /* Table text color */
68
+ border-radius: 10px;
69
+ }
70
+ .stPlotlyChart {
71
+ background-color: rgba(0, 0, 0, 0.8); /* Match dark theme */
72
+ padding: 10px;
73
+ border-radius: 10px;
74
+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
75
+ }
76
+ .styled-table {
77
+ width: 100%;
78
+ border-collapse: collapse;
79
+ margin: 25px 0;
80
+ font-size: 18px;
81
+ text-align: left;
82
+ border-radius: 5px 5px 0 0;
83
+ overflow: hidden;
84
+ color: #ffffff; /* Table text color */
85
+ }
86
+ .styled-table th, .styled-table td {
87
+ padding: 12px 15px;
88
+ }
89
+ </style>
90
+ """,
91
+ unsafe_allow_html=True
92
+ )
93
+
94
 
95
  team_logo_paths = {
96
  "Cleveland Cavaliers": "Clevelan-Cavaliers-logo-2022.png",
 
218
  player_data = load_player_data()
219
  rf_model = load_rf_model()
220
 
221
+
222
+ st.sidebar.markdown(
223
+ """
224
+ <div style="padding: 10px; background: linear-gradient(to right, #6a11cb, #2575fc); color: white; border-radius: 10px;">
225
+ <h3>Player Details</h3>
226
+ </div>
227
+ """,
228
+ unsafe_allow_html=True
229
+ )
230
+
231
 
232
  # Dropdown for player selection
233
  player_list = sorted(player_data['player_name'].dropna().unique())
 
290
  input_data = input_data.reindex(columns=rf_model.feature_names_in_, fill_value=0)
291
 
292
  # Predict and display results
293
+ # Predict and display results
294
+ if st.sidebar.button("Predict 🔮"):
295
  predictions = rf_model.predict(input_data)
296
+ prediction_columns = ["Predicted Change in PTS", "Predicted Change in REB", "Predicted Change in AST"]
297
  st.subheader("Predicted Post-Injury Performance")
298
  st.write("Based on the inputs, here are the predicted metrics:")
299
+ styled_table = pd.DataFrame(predictions, columns=prediction_columns).style.set_table_attributes('class="styled-table"')
300
+ st.write(styled_table.to_html(), unsafe_allow_html=True)
301
+
302
+ # Plot predictions
303
+ prediction_df = pd.DataFrame(predictions, columns=prediction_columns)
304
+ fig = go.Figure()
305
+
306
+ for col in prediction_columns:
307
+ fig.add_trace(go.Bar(
308
+ x=[col],
309
+ y=prediction_df[col],
310
+ name=col,
311
+ marker=dict(color=px.colors.qualitative.Plotly[prediction_columns.index(col)])
312
+ ))
313
+
314
+ fig.update_layout(
315
+ title="Predicted Performance Changes",
316
+ xaxis_title="Metrics",
317
+ yaxis_title="Change Value",
318
+ template="plotly_dark",
319
+ showlegend=True
320
+ )
321
+
322
+ st.plotly_chart(fig)
323
  except FileNotFoundError:
324
  st.error("Model file not found.")
325
  except ValueError as e: