Spaces:
Sleeping
Sleeping
Commit
·
b172c75
1
Parent(s):
eacfaf7
Evaluation to current
Browse files
app.py
CHANGED
@@ -23,15 +23,21 @@ games_ids = list(range(1, 24)) + [25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36
|
|
23 |
EXPECTED_COLUMNS.extend([f'games_{i}' for i in games_ids])
|
24 |
EXPECTED_COLUMNS.extend([f'winrate_{i}' for i in games_ids])
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
27 |
"""Creates a DataFrame in the expected format for the model"""
|
28 |
try:
|
29 |
# Extract player_id from URL if needed
|
30 |
player_id = user_id.split("/")[-1] if "/" in user_id else user_id
|
31 |
|
32 |
-
# Get hero statistics using OpenDota API
|
33 |
-
hero_stats = hero_information(player_id)
|
34 |
-
|
35 |
# Create initial data dictionary with zeros for all columns
|
36 |
data = {col: 0 for col in EXPECTED_COLUMNS}
|
37 |
|
@@ -45,6 +51,9 @@ def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, com
|
|
45 |
'p5': int(comf_5),
|
46 |
})
|
47 |
|
|
|
|
|
|
|
48 |
# Add hero statistics
|
49 |
if hero_stats is not None:
|
50 |
data['total_games_played'] = hero_stats.get('total_games_played', 0)
|
@@ -61,6 +70,11 @@ def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, com
|
|
61 |
bucks_stats = captains_df["Buck's Bucks"].describe()
|
62 |
cents_stats = captains_df["Crub Cents"].describe()
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
# Combine stats from both currencies
|
65 |
combined_stats = {
|
66 |
'count': bucks_stats['count'] + cents_stats['count'],
|
@@ -70,10 +84,10 @@ def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, com
|
|
70 |
'max': max(bucks_stats['max'], cents_stats['max']),
|
71 |
'sum': bucks_stats['count'] * bucks_stats['mean'] + cents_stats['count'] * cents_stats['mean']
|
72 |
}
|
|
|
73 |
data.update(combined_stats)
|
74 |
except Exception as e:
|
75 |
print(f"Error reading captains data: {e}")
|
76 |
-
# Fallback to mock data if file read fails
|
77 |
stats = {
|
78 |
'count': 1,
|
79 |
'mean': mmr / 200,
|
@@ -93,6 +107,14 @@ def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, com
|
|
93 |
print(f"DataFrame shape: {df.shape}")
|
94 |
print("Missing columns:", set(EXPECTED_COLUMNS) - set(df.columns))
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
return df
|
97 |
|
98 |
except Exception as e:
|
@@ -102,6 +124,10 @@ def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, com
|
|
102 |
def predict_cost(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
103 |
"""Main prediction function for Gradio interface"""
|
104 |
try:
|
|
|
|
|
|
|
|
|
105 |
# Prepare the player data
|
106 |
processed_data = prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5)
|
107 |
|
@@ -113,8 +139,8 @@ def predict_cost(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
113 |
session = ort.InferenceSession(str(model_path))
|
114 |
|
115 |
# Debug information
|
|
|
116 |
print("Processed data shape:", processed_data.shape)
|
117 |
-
print("Processed data columns:", processed_data.columns.tolist())
|
118 |
|
119 |
# Make prediction
|
120 |
input_name = session.get_inputs()[0].name
|
@@ -125,7 +151,14 @@ def predict_cost(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
|
125 |
total_games = hero_stats.get('total_games_played', 'N/A')
|
126 |
total_winrate = hero_stats.get('total_winrate', 'N/A')
|
127 |
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
Player Details:
|
131 |
- MMR: {mmr}
|
|
|
23 |
EXPECTED_COLUMNS.extend([f'games_{i}' for i in games_ids])
|
24 |
EXPECTED_COLUMNS.extend([f'winrate_{i}' for i in games_ids])
|
25 |
|
26 |
+
def load_reference_data(player_id):
|
27 |
+
"""Load reference prediction data for comparison"""
|
28 |
+
try:
|
29 |
+
ref_df = pd.read_csv(f"{player_id}.csv")
|
30 |
+
return ref_df.iloc[-1][f"{player_id}_S34"]
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Could not load reference data: {e}")
|
33 |
+
return None
|
34 |
+
|
35 |
def prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
36 |
"""Creates a DataFrame in the expected format for the model"""
|
37 |
try:
|
38 |
# Extract player_id from URL if needed
|
39 |
player_id = user_id.split("/")[-1] if "/" in user_id else user_id
|
40 |
|
|
|
|
|
|
|
41 |
# Create initial data dictionary with zeros for all columns
|
42 |
data = {col: 0 for col in EXPECTED_COLUMNS}
|
43 |
|
|
|
51 |
'p5': int(comf_5),
|
52 |
})
|
53 |
|
54 |
+
# Get hero statistics using OpenDota API
|
55 |
+
hero_stats = hero_information(player_id)
|
56 |
+
|
57 |
# Add hero statistics
|
58 |
if hero_stats is not None:
|
59 |
data['total_games_played'] = hero_stats.get('total_games_played', 0)
|
|
|
70 |
bucks_stats = captains_df["Buck's Bucks"].describe()
|
71 |
cents_stats = captains_df["Crub Cents"].describe()
|
72 |
|
73 |
+
# Print stats for debugging
|
74 |
+
print("\nLeague Money Statistics:")
|
75 |
+
print("Buck's Bucks stats:", bucks_stats)
|
76 |
+
print("Crub Cents stats:", cents_stats)
|
77 |
+
|
78 |
# Combine stats from both currencies
|
79 |
combined_stats = {
|
80 |
'count': bucks_stats['count'] + cents_stats['count'],
|
|
|
84 |
'max': max(bucks_stats['max'], cents_stats['max']),
|
85 |
'sum': bucks_stats['count'] * bucks_stats['mean'] + cents_stats['count'] * cents_stats['mean']
|
86 |
}
|
87 |
+
print("Combined stats:", combined_stats)
|
88 |
data.update(combined_stats)
|
89 |
except Exception as e:
|
90 |
print(f"Error reading captains data: {e}")
|
|
|
91 |
stats = {
|
92 |
'count': 1,
|
93 |
'mean': mmr / 200,
|
|
|
107 |
print(f"DataFrame shape: {df.shape}")
|
108 |
print("Missing columns:", set(EXPECTED_COLUMNS) - set(df.columns))
|
109 |
|
110 |
+
# Print key feature values for debugging
|
111 |
+
print("\nKey feature values:")
|
112 |
+
print(f"MMR: {df['mmr'].iloc[0]}")
|
113 |
+
print(f"Position comfort: {df[['p1', 'p2', 'p3', 'p4', 'p5']].iloc[0].tolist()}")
|
114 |
+
print(f"Money stats: {df[['count', 'mean', 'std', 'min', 'max', 'sum']].iloc[0].tolist()}")
|
115 |
+
print(f"Total games: {df['total_games_played'].iloc[0]}")
|
116 |
+
print(f"Total winrate: {df['total_winrate'].iloc[0]}")
|
117 |
+
|
118 |
return df
|
119 |
|
120 |
except Exception as e:
|
|
|
124 |
def predict_cost(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5):
|
125 |
"""Main prediction function for Gradio interface"""
|
126 |
try:
|
127 |
+
# Extract player_id for reference data
|
128 |
+
player_id = user_id.split("/")[-1] if "/" in user_id else user_id
|
129 |
+
reference_cost = load_reference_data(player_id)
|
130 |
+
|
131 |
# Prepare the player data
|
132 |
processed_data = prepare_single_player_data(user_id, mmr, comf_1, comf_2, comf_3, comf_4, comf_5)
|
133 |
|
|
|
139 |
session = ort.InferenceSession(str(model_path))
|
140 |
|
141 |
# Debug information
|
142 |
+
print("\nModel Input Information:")
|
143 |
print("Processed data shape:", processed_data.shape)
|
|
|
144 |
|
145 |
# Make prediction
|
146 |
input_name = session.get_inputs()[0].name
|
|
|
151 |
total_games = hero_stats.get('total_games_played', 'N/A')
|
152 |
total_winrate = hero_stats.get('total_winrate', 'N/A')
|
153 |
|
154 |
+
comparison = ""
|
155 |
+
if reference_cost is not None:
|
156 |
+
diff = abs(predicted_cost - reference_cost)
|
157 |
+
comparison = f"""
|
158 |
+
Reference Cost: {reference_cost}
|
159 |
+
Difference: {diff:.2f} ({(diff/reference_cost*100):.1f}% {'higher' if predicted_cost > reference_cost else 'lower'})"""
|
160 |
+
|
161 |
+
return f"""Predicted Cost: {predicted_cost}{comparison}
|
162 |
|
163 |
Player Details:
|
164 |
- MMR: {mmr}
|