Jay-Rajput commited on
Commit
1356e88
·
1 Parent(s): 82f926c

Updated leads repo

Browse files
Files changed (1) hide show
  1. app.py +17 -39
app.py CHANGED
@@ -269,53 +269,31 @@ def display_predictions():
269
  def display_leaderboard():
270
  if st.button("Show Leaderboard"):
271
  try:
272
- users = load_users(USERS_JSON)
 
273
  # Convert the dataset to a pandas DataFrame
274
- df_users = pd.DataFrame([{'User': key, 'Points': value} for key, value in users.items()])
 
 
 
 
 
 
275
 
 
 
276
  # Sort DataFrame by points in descending order
277
- leaderboard = df_users.sort_values(by='Points', ascending=False).reset_index(drop=True)
278
 
279
  # Add a 'Rank' column starting from 1
280
- leaderboard['Rank'] = leaderboard.index + 1
281
 
282
- # Reorder DataFrame columns so 'Rank' is first
283
- df_leaderboard = leaderboard[['Rank', 'User', 'Points']]
284
 
285
  st.dataframe(df_leaderboard, hide_index=True)
286
- except FileNotFoundError:
287
- st.write("Leaderboard data not available.")
288
-
289
-
290
- # def display_leaderboard():
291
- # if st.button("Show Leaderboard"):
292
- # try:
293
- # # Load the 'leaders' configuration or split from your dataset
294
- # dataset = load_dataset("Jay-Rajput/DIS_IPL_Leads", split='train')
295
- # # Convert the dataset to a pandas DataFrame
296
- # df_users = pd.DataFrame(dataset)
297
-
298
- # # Transform the DataFrame to have 'user_name' and 'points' columns
299
- # # Since your JSON structure is quite unique, this step may need adjustment based on how the DataFrame is loaded
300
- # users_data = []
301
- # for column in df_users.columns:
302
- # points = df_users[column].iloc[0] # Assuming the first (and only) row contains the points for each user
303
- # users_data.append({'User': column, 'Points': points})
304
-
305
- # df_leaderboard = pd.DataFrame(users_data)
306
-
307
- # # Sort DataFrame by points in descending order
308
- # df_leaderboard = df_leaderboard.sort_values(by='Points', ascending=False)
309
-
310
- # # Add a 'Rank' column starting from 1
311
- # df_leaderboard['Rank'] = range(1, len(df_leaderboard) + 1)
312
-
313
- # # Select and order the columns for display
314
- # df_leaderboard = df_leaderboard[['Rank', 'User', 'Points']]
315
-
316
- # st.dataframe(df_leaderboard, hide_index=True)
317
- # except Exception as e:
318
- # st.write("Failed to load leaderboard data: ", str(e))
319
 
320
 
321
  # Streamlit UI
 
269
  def display_leaderboard():
270
  if st.button("Show Leaderboard"):
271
  try:
272
+ # Load the 'leaders' configuration or split from your dataset
273
+ dataset = load_dataset("Jay-Rajput/DIS_IPL_Leads", split='train')
274
  # Convert the dataset to a pandas DataFrame
275
+ df_users = pd.DataFrame(dataset)
276
+
277
+ # Transform the DataFrame to have 'user_name' and 'points' columns
278
+ users_data = []
279
+ for column in df_users.columns:
280
+ points = df_users[column].iloc[0] # Assuming the first (and only) row contains the points for each user
281
+ users_data.append({'User': column, 'Points': points})
282
 
283
+ df_leaderboard = pd.DataFrame(users_data)
284
+
285
  # Sort DataFrame by points in descending order
286
+ df_leaderboard = df_leaderboard.sort_values(by='Points', ascending=False)
287
 
288
  # Add a 'Rank' column starting from 1
289
+ df_leaderboard['Rank'] = range(1, len(df_leaderboard) + 1)
290
 
291
+ # Select and order the columns for display
292
+ df_leaderboard = df_leaderboard[['Rank', 'User', 'Points']]
293
 
294
  st.dataframe(df_leaderboard, hide_index=True)
295
+ except Exception as e:
296
+ st.write("Failed to load leaderboard data: ", str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
 
299
  # Streamlit UI