Spaces:
Configuration error
Configuration error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ def load_data_and_model():
|
|
| 23 |
if col in df.columns:
|
| 24 |
df.rename(columns={col: 'market_value_in_eur'}, inplace=True)
|
| 25 |
|
| 26 |
-
# CRITICAL: Drop any duplicate columns created by renaming
|
| 27 |
df = df.loc[:, ~df.columns.duplicated()].copy()
|
| 28 |
|
| 29 |
# Load model
|
|
@@ -68,6 +68,7 @@ if input_mode == "Select Existing Player":
|
|
| 68 |
if name_col:
|
| 69 |
player_list = sorted(df[name_col].unique().tolist())
|
| 70 |
selected_name = st.sidebar.selectbox("Target Database Player", player_list)
|
|
|
|
| 71 |
player_data = df[df[name_col] == selected_name].iloc[0:1].copy()
|
| 72 |
else:
|
| 73 |
st.sidebar.error("Player names column not found in CSV.")
|
|
@@ -76,10 +77,12 @@ if input_mode == "Select Existing Player":
|
|
| 76 |
st.sidebar.markdown("---")
|
| 77 |
st.sidebar.markdown("**Simulation Parameters** (Overrides)")
|
| 78 |
|
|
|
|
| 79 |
contract_default = max(0.5, min(6.0, float(player_data['Contract_Years_Left'].iloc[0])))
|
| 80 |
age_default = max(16, min(40, int(player_data['Age'].iloc[0])))
|
|
|
|
| 81 |
injury_col = next((c for c in ['Injury_Days_Total_24m', 'Injury_Days'] if c in player_data.columns), None)
|
| 82 |
-
injury_default =
|
| 83 |
if injury_col:
|
| 84 |
injury_default = max(0, min(500, int(player_data[injury_col].iloc[0])))
|
| 85 |
|
|
|
|
| 23 |
if col in df.columns:
|
| 24 |
df.rename(columns={col: 'market_value_in_eur'}, inplace=True)
|
| 25 |
|
| 26 |
+
# CRITICAL: Drop any duplicate columns created by renaming
|
| 27 |
df = df.loc[:, ~df.columns.duplicated()].copy()
|
| 28 |
|
| 29 |
# Load model
|
|
|
|
| 68 |
if name_col:
|
| 69 |
player_list = sorted(df[name_col].unique().tolist())
|
| 70 |
selected_name = st.sidebar.selectbox("Target Database Player", player_list)
|
| 71 |
+
# Using [0:1] to keep it as a DataFrame
|
| 72 |
player_data = df[df[name_col] == selected_name].iloc[0:1].copy()
|
| 73 |
else:
|
| 74 |
st.sidebar.error("Player names column not found in CSV.")
|
|
|
|
| 77 |
st.sidebar.markdown("---")
|
| 78 |
st.sidebar.markdown("**Simulation Parameters** (Overrides)")
|
| 79 |
|
| 80 |
+
# Use .iloc[0] to avoid KeyError: 0 when the original index is preserved
|
| 81 |
contract_default = max(0.5, min(6.0, float(player_data['Contract_Years_Left'].iloc[0])))
|
| 82 |
age_default = max(16, min(40, int(player_data['Age'].iloc[0])))
|
| 83 |
+
|
| 84 |
injury_col = next((c for c in ['Injury_Days_Total_24m', 'Injury_Days'] if c in player_data.columns), None)
|
| 85 |
+
injury_default = 10
|
| 86 |
if injury_col:
|
| 87 |
injury_default = max(0, min(500, int(player_data[injury_col].iloc[0])))
|
| 88 |
|