Update app.py
Browse files
app.py
CHANGED
@@ -164,7 +164,6 @@ def update_leaderboard_pro(results):
|
|
164 |
|
165 |
def load_leaderboard():
|
166 |
if not os.path.exists(LEADERBOARD_FILE) or os.stat(LEADERBOARD_FILE).st_size == 0:
|
167 |
-
# Create an empty DataFrame with all expected columns
|
168 |
return pd.DataFrame({
|
169 |
"Model Name": [],
|
170 |
"Overall Accuracy": [],
|
@@ -177,7 +176,28 @@ def load_leaderboard():
|
|
177 |
# Read the CSV file
|
178 |
df = pd.read_csv(LEADERBOARD_FILE)
|
179 |
|
180 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
expected_columns = [
|
182 |
"Model Name",
|
183 |
"Overall Accuracy",
|
@@ -187,21 +207,9 @@ def load_leaderboard():
|
|
187 |
"Team Name"
|
188 |
]
|
189 |
|
190 |
-
#
|
191 |
-
for col in expected_columns:
|
192 |
-
if col not in df.columns:
|
193 |
-
if col == "Timestamp":
|
194 |
-
df[col] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
195 |
-
elif col == "Team Name":
|
196 |
-
df[col] = "Unknown Team"
|
197 |
-
else:
|
198 |
-
df[col] = None
|
199 |
-
|
200 |
-
# Remove duplicate entries based on Model Name
|
201 |
-
df = df.drop_duplicates(subset="Model Name", keep='last')
|
202 |
-
|
203 |
-
# Reorder columns to match expected structure
|
204 |
df = df[expected_columns]
|
|
|
205 |
|
206 |
return df
|
207 |
|
|
|
164 |
|
165 |
def load_leaderboard():
|
166 |
if not os.path.exists(LEADERBOARD_FILE) or os.stat(LEADERBOARD_FILE).st_size == 0:
|
|
|
167 |
return pd.DataFrame({
|
168 |
"Model Name": [],
|
169 |
"Overall Accuracy": [],
|
|
|
176 |
# Read the CSV file
|
177 |
df = pd.read_csv(LEADERBOARD_FILE)
|
178 |
|
179 |
+
# Fill empty Team Name
|
180 |
+
df['Team Name'] = df['Team Name'].fillna('Unknown Team')
|
181 |
+
|
182 |
+
# Fill empty Timestamp
|
183 |
+
df['Timestamp'] = df['Timestamp'].fillna(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
184 |
+
|
185 |
+
# If Timestamp is an empty string, replace with current timestamp
|
186 |
+
df.loc[df['Timestamp'] == '', 'Timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
187 |
+
|
188 |
+
# Fill Correct Predictions based on Accuracy and Total Questions if possible
|
189 |
+
# Assuming Total Questions is typically 16186 and Accuracy is a percentage
|
190 |
+
df['Correct Predictions'] = df.apply(
|
191 |
+
lambda row: round(16186 * (row['Overall Accuracy'] / 100))
|
192 |
+
if pd.isna(row['Correct Predictions']) or row['Correct Predictions'] == ''
|
193 |
+
else row['Correct Predictions'],
|
194 |
+
axis=1
|
195 |
+
)
|
196 |
+
|
197 |
+
# Remove duplicate entries, keeping the last occurrence
|
198 |
+
df = df.drop_duplicates(subset='Model Name', keep='last')
|
199 |
+
|
200 |
+
# Ensure all expected columns are present
|
201 |
expected_columns = [
|
202 |
"Model Name",
|
203 |
"Overall Accuracy",
|
|
|
207 |
"Team Name"
|
208 |
]
|
209 |
|
210 |
+
# Reorder columns and save
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
df = df[expected_columns]
|
212 |
+
df.to_csv(LEADERBOARD_FILE, index=False)
|
213 |
|
214 |
return df
|
215 |
|