Spaces:
Sleeping
Sleeping
Commit
·
743b8c4
1
Parent(s):
51f2947
updated the location and hopefully now grabbing all info:
Browse files
app.py
CHANGED
|
@@ -22,13 +22,14 @@ def load_model():
|
|
| 22 |
|
| 23 |
MODEL = ort.InferenceSession(str(model_path))
|
| 24 |
|
| 25 |
-
# Load feature columns from
|
| 26 |
try:
|
| 27 |
-
FEATURE_COLUMNS = pd.read_csv("
|
| 28 |
except:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
return "Model loaded successfully"
|
| 34 |
except Exception as e:
|
|
@@ -52,11 +53,28 @@ def process_player_data(player_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
| 52 |
"p5": int(comf_5)
|
| 53 |
}
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Get hero statistics using OpenDota API
|
| 56 |
try:
|
| 57 |
hero_stats = hero_information(player_id)
|
| 58 |
-
# Merge hero stats with player data
|
| 59 |
player_data.update(hero_stats.to_dict())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
print(f"Warning - Error fetching hero data: {str(e)}")
|
| 62 |
# If hero stats fail, add placeholder values
|
|
@@ -68,7 +86,20 @@ def process_player_data(player_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
| 68 |
# Convert to DataFrame for consistency with training
|
| 69 |
df = pd.DataFrame([player_data])
|
| 70 |
|
| 71 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
if FEATURE_COLUMNS:
|
| 73 |
for col in FEATURE_COLUMNS:
|
| 74 |
if col not in df.columns:
|
|
@@ -76,6 +107,9 @@ def process_player_data(player_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
| 76 |
# Reorder columns to match model input
|
| 77 |
df = df[FEATURE_COLUMNS]
|
| 78 |
|
|
|
|
|
|
|
|
|
|
| 79 |
return df
|
| 80 |
except Exception as e:
|
| 81 |
return f"Error processing player data: {str(e)}"
|
|
|
|
| 22 |
|
| 23 |
MODEL = ort.InferenceSession(str(model_path))
|
| 24 |
|
| 25 |
+
# Load feature columns from prediction data
|
| 26 |
try:
|
| 27 |
+
FEATURE_COLUMNS = pd.read_csv("result_prediction_data_prepped.csv").columns.tolist()
|
| 28 |
except:
|
| 29 |
+
try:
|
| 30 |
+
FEATURE_COLUMNS = pd.read_csv("prediction_data_prepped.csv").columns.tolist()
|
| 31 |
+
except:
|
| 32 |
+
return "Error: Could not find prediction data files to determine feature structure"
|
| 33 |
|
| 34 |
return "Model loaded successfully"
|
| 35 |
except Exception as e:
|
|
|
|
| 53 |
"p5": int(comf_5)
|
| 54 |
}
|
| 55 |
|
| 56 |
+
# Read the example row from prediction_data_prepped.csv to get the expected structure
|
| 57 |
+
try:
|
| 58 |
+
pred_data = pd.read_csv("prediction_data_prepped.csv")
|
| 59 |
+
if not pred_data.empty:
|
| 60 |
+
# Get column structure from the first row
|
| 61 |
+
for col in pred_data.columns:
|
| 62 |
+
if col not in player_data:
|
| 63 |
+
player_data[col] = 0
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"Warning - Error reading prediction data template: {str(e)}")
|
| 66 |
+
|
| 67 |
# Get hero statistics using OpenDota API
|
| 68 |
try:
|
| 69 |
hero_stats = hero_information(player_id)
|
|
|
|
| 70 |
player_data.update(hero_stats.to_dict())
|
| 71 |
+
|
| 72 |
+
# Add season identifier to match training data format
|
| 73 |
+
player_season = f"{player_id}_S34" # Assuming current season is 34
|
| 74 |
+
temp_dict = {}
|
| 75 |
+
temp_dict[player_season] = 1.0 # Set current season flag to 1.0
|
| 76 |
+
player_data.update(temp_dict)
|
| 77 |
+
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Warning - Error fetching hero data: {str(e)}")
|
| 80 |
# If hero stats fail, add placeholder values
|
|
|
|
| 86 |
# Convert to DataFrame for consistency with training
|
| 87 |
df = pd.DataFrame([player_data])
|
| 88 |
|
| 89 |
+
# Load reference data structure if available
|
| 90 |
+
try:
|
| 91 |
+
ref_data = pd.read_csv("result_prediction_data_prepped.csv")
|
| 92 |
+
if not ref_data.empty:
|
| 93 |
+
# Get all columns from reference data
|
| 94 |
+
for col in ref_data.columns:
|
| 95 |
+
if col not in df.columns:
|
| 96 |
+
df[col] = 0
|
| 97 |
+
# Reorder columns to match reference data
|
| 98 |
+
df = df[ref_data.columns]
|
| 99 |
+
except Exception as e:
|
| 100 |
+
print(f"Warning - Error matching reference data structure: {str(e)}")
|
| 101 |
+
|
| 102 |
+
# Final check for required columns
|
| 103 |
if FEATURE_COLUMNS:
|
| 104 |
for col in FEATURE_COLUMNS:
|
| 105 |
if col not in df.columns:
|
|
|
|
| 107 |
# Reorder columns to match model input
|
| 108 |
df = df[FEATURE_COLUMNS]
|
| 109 |
|
| 110 |
+
print(f"Processed data columns: {df.columns.tolist()}")
|
| 111 |
+
print(f"Number of features: {len(df.columns)}")
|
| 112 |
+
|
| 113 |
return df
|
| 114 |
except Exception as e:
|
| 115 |
return f"Error processing player data: {str(e)}"
|