mehran commited on
Commit
2f6c110
·
1 Parent(s): 297c9b6

edit showing models ranking: show medals and line under second best model

Browse files
leaderboard/__pycache__/leaderboard.cpython-310.pyc CHANGED
Binary files a/leaderboard/__pycache__/leaderboard.cpython-310.pyc and b/leaderboard/__pycache__/leaderboard.cpython-310.pyc differ
 
leaderboard/leaderboard.py CHANGED
@@ -307,23 +307,190 @@ class LeaderboardApp:
307
  numeric_series_for_max = formatted_df[col_name_original].apply(to_numeric_for_max)
308
 
309
  if not numeric_series_for_max.empty and numeric_series_for_max.notna().any() and \
310
- pd.api.types.is_numeric_dtype(numeric_series_for_max) and not numeric_series_for_max.eq(-np.inf).all():
311
- max_val_numeric = numeric_series_for_max.max(skipna=True)
 
 
 
 
 
 
 
 
312
  if pd.notna(max_val_numeric) and max_val_numeric != -np.inf:
313
  for i in numeric_series_for_max.index:
314
  current_numeric_val = numeric_series_for_max.loc[i]
315
- if pd.notna(current_numeric_val) and current_numeric_val == max_val_numeric:
316
- display_val_to_bold = formatted_df.loc[i, col_name_original]
317
- if not (isinstance(display_val_to_bold, str) and display_val_to_bold.startswith("**") and display_val_to_bold.endswith("**")):
318
- formatted_df.loc[i, col_name_original] = f"**{display_val_to_bold}**"
 
 
 
 
 
 
319
  elif pd.isna(current_numeric_val) or current_numeric_val == -np.inf:
320
  cell_content = formatted_df.loc[i, col_name_original]
321
  if cell_content is None or \
322
- (isinstance(cell_content, str) and \
323
- cell_content.strip().lower() in ["n/a", "", "unknown", "nan"]): # Standardize NA display
324
  formatted_df.loc[i, col_name_original] = ""
325
  return formatted_df
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  @staticmethod
328
  def _get_gr_datatypes(df_with_original_cols: pd.DataFrame, model_id_col_original_name: str, score_cols_original_names: List[str]) -> List[str]:
329
  datatypes = []
@@ -342,6 +509,54 @@ class LeaderboardApp:
342
  datatypes.append("str")
343
  return datatypes
344
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  def get_prepared_dataframe(self, task_key: str, source_filter: str = "All", name_filter_query: str = "") -> pd.DataFrame:
346
  original_df_for_task = self.raw_dataframes.get(task_key)
347
  if original_df_for_task is None or original_df_for_task.empty:
@@ -380,13 +595,28 @@ class LeaderboardApp:
380
  processed_df = processed_df.drop(columns=columns_to_drop_existing, errors='ignore')
381
 
382
  if "Rank" in processed_df.columns:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  cols_order = ["Rank"] + [col for col in processed_df.columns if col != "Rank"]
384
  processed_df = processed_df[cols_order]
385
 
386
- if "Rank" in processed_df.columns:
387
- processed_df["Rank"] = processed_df["Rank"].apply(lambda x: str(int(x)) if pd.notna(x) and isinstance(x, (float,int)) and x == int(x) else (str(x) if pd.notna(x) else ""))
388
-
389
-
390
  processed_df = processed_df.fillna("")
391
  return processed_df
392
 
 
307
  numeric_series_for_max = formatted_df[col_name_original].apply(to_numeric_for_max)
308
 
309
  if not numeric_series_for_max.empty and numeric_series_for_max.notna().any() and \
310
+ pd.api.types.is_numeric_dtype(numeric_series_for_max) and not numeric_series_for_max.eq(-np.inf).all():
311
+
312
+ # Get unique scores and sort them in descending order to find the top 3
313
+ unique_sorted_scores = numeric_series_for_max.dropna().unique()
314
+ unique_sorted_scores = np.sort(unique_sorted_scores)[::-1]
315
+
316
+ max_val_numeric = unique_sorted_scores[0] if len(unique_sorted_scores) > 0 else -np.inf
317
+ second_max_numeric = unique_sorted_scores[1] if len(unique_sorted_scores) > 1 else -np.inf
318
+ third_max_numeric = unique_sorted_scores[2] if len(unique_sorted_scores) > 2 else -np.inf
319
+
320
  if pd.notna(max_val_numeric) and max_val_numeric != -np.inf:
321
  for i in numeric_series_for_max.index:
322
  current_numeric_val = numeric_series_for_max.loc[i]
323
+ if pd.notna(current_numeric_val) and current_numeric_val >= -np.inf:
324
+ display_val = formatted_df.loc[i, col_name_original]
325
+
326
+ # Check for the top 3 values and apply the corresponding formatting
327
+ if current_numeric_val == max_val_numeric:
328
+ formatted_df.loc[i, col_name_original] = f"**{display_val}**"
329
+ elif current_numeric_val == second_max_numeric:
330
+ formatted_df.loc[i, col_name_original] = f"<ins>{display_val}</ins>"
331
+ # No formatting for third place, so no elif statement is needed
332
+
333
  elif pd.isna(current_numeric_val) or current_numeric_val == -np.inf:
334
  cell_content = formatted_df.loc[i, col_name_original]
335
  if cell_content is None or \
336
+ (isinstance(cell_content, str) and \
337
+ cell_content.strip().lower() in ["n/a", "", "unknown", "nan"]):
338
  formatted_df.loc[i, col_name_original] = ""
339
  return formatted_df
340
 
341
+ # def _apply_markdown_and_bolding(self, df_with_general_formats: pd.DataFrame) -> pd.DataFrame:
342
+ # if df_with_general_formats.empty: return df_with_general_formats
343
+ # formatted_df = df_with_general_formats.copy()
344
+
345
+ # model_id_col_original = self.model_identifier_column
346
+
347
+ # if model_id_col_original in formatted_df.columns and 'model_url' in formatted_df.columns:
348
+ # def create_markdown_link(row):
349
+ # model_id_val = row[model_id_col_original]
350
+ # url = row['model_url']
351
+
352
+ # display_conf = self.model_display_configs.get(str(model_id_val), {})
353
+ # display_name = display_conf.get('display_name', str(model_id_val))
354
+ # url_for_link = display_conf.get('url', url if pd.notna(url) else 'https://google.com')
355
+ # if not url_for_link or pd.isna(url_for_link): url_for_link = 'https://google.com'
356
+ # return f"[{display_name}]({url_for_link})"
357
+ # formatted_df[model_id_col_original] = formatted_df.apply(create_markdown_link, axis=1)
358
+
359
+ # for col_name_original in self.numeric_score_columns_for_bolding:
360
+ # if col_name_original in formatted_df.columns:
361
+ # def to_numeric_for_max(val):
362
+ # if isinstance(val, str):
363
+ # try: return float(val) # Handles "88.00", "75.50", "100", "0"
364
+ # except ValueError: return -np.inf
365
+ # return val if pd.notna(val) else -np.inf
366
+
367
+ # numeric_series_for_max = formatted_df[col_name_original].apply(to_numeric_for_max)
368
+
369
+ # if not numeric_series_for_max.empty and numeric_series_for_max.notna().any() and \
370
+ # pd.api.types.is_numeric_dtype(numeric_series_for_max) and not numeric_series_for_max.eq(-np.inf).all():
371
+
372
+ # # Get unique scores and sort them in descending order to find the top 3
373
+ # unique_sorted_scores = numeric_series_for_max.dropna().unique()
374
+ # unique_sorted_scores = np.sort(unique_sorted_scores)[::-1]
375
+
376
+ # max_val_numeric = unique_sorted_scores[0] if len(unique_sorted_scores) > 0 else -np.inf
377
+ # second_max_numeric = unique_sorted_scores[1] if len(unique_sorted_scores) > 1 else -np.inf
378
+ # third_max_numeric = unique_sorted_scores[2] if len(unique_sorted_scores) > 2 else -np.inf
379
+
380
+ # if pd.notna(max_val_numeric) and max_val_numeric != -np.inf:
381
+ # for i in numeric_series_for_max.index:
382
+ # current_numeric_val = numeric_series_for_max.loc[i]
383
+ # if pd.notna(current_numeric_val) and current_numeric_val >= -np.inf:
384
+ # display_val = formatted_df.loc[i, col_name_original]
385
+
386
+ # # Check for the top 3 values and apply the corresponding color
387
+ # if current_numeric_val == max_val_numeric:
388
+ # formatted_df.loc[i, col_name_original] = f"<span style='color: gold;'>{display_val}</span>"
389
+ # elif current_numeric_val == second_max_numeric:
390
+ # formatted_df.loc[i, col_name_original] = f"<span style='color: #C0C0C0;'>{display_val}</span>"
391
+ # elif current_numeric_val == third_max_numeric:
392
+ # formatted_df.loc[i, col_name_original] = f"<span style='color: #CD7F32;'>{display_val}</span>" # Bronze hex code
393
+
394
+ # elif pd.isna(current_numeric_val) or current_numeric_val == -np.inf:
395
+ # cell_content = formatted_df.loc[i, col_name_original]
396
+ # if cell_content is None or \
397
+ # (isinstance(cell_content, str) and \
398
+ # cell_content.strip().lower() in ["n/a", "", "unknown", "nan"]):
399
+ # formatted_df.loc[i, col_name_original] = ""
400
+ # return formatted_df
401
+ # def _apply_markdown_and_bolding(self, df_with_general_formats: pd.DataFrame) -> pd.DataFrame:
402
+ # if df_with_general_formats.empty: return df_with_general_formats
403
+ # formatted_df = df_with_general_formats.copy()
404
+
405
+ # model_id_col_original = self.model_identifier_column
406
+
407
+ # if model_id_col_original in formatted_df.columns and 'model_url' in formatted_df.columns:
408
+ # def create_markdown_link(row):
409
+ # model_id_val = row[model_id_col_original]
410
+ # url = row['model_url']
411
+
412
+ # display_conf = self.model_display_configs.get(str(model_id_val), {})
413
+ # display_name = display_conf.get('display_name', str(model_id_val))
414
+ # url_for_link = display_conf.get('url', url if pd.notna(url) else 'https://google.com')
415
+ # if not url_for_link or pd.isna(url_for_link): url_for_link = 'https://google.com'
416
+ # return f"[{display_name}]({url_for_link})"
417
+ # formatted_df[model_id_col_original] = formatted_df.apply(create_markdown_link, axis=1)
418
+
419
+ # for col_name_original in self.numeric_score_columns_for_bolding:
420
+ # if col_name_original in formatted_df.columns:
421
+ # def to_numeric_for_max(val):
422
+ # if isinstance(val, str):
423
+ # try: return float(val) # Handles "88.00", "75.50", "100", "0"
424
+ # except ValueError: return -np.inf
425
+ # return val if pd.notna(val) else -np.inf
426
+
427
+ # numeric_series_for_max = formatted_df[col_name_original].apply(to_numeric_for_max)
428
+
429
+ # if not numeric_series_for_max.empty and numeric_series_for_max.notna().any() and \
430
+ # pd.api.types.is_numeric_dtype(numeric_series_for_max) and not numeric_series_for_max.eq(-np.inf).all():
431
+ # max_val_numeric = numeric_series_for_max.max(skipna=True)
432
+ # if pd.notna(max_val_numeric) and max_val_numeric != -np.inf:
433
+ # for i in numeric_series_for_max.index:
434
+ # current_numeric_val = numeric_series_for_max.loc[i]
435
+ # if pd.notna(current_numeric_val) and current_numeric_val == max_val_numeric:
436
+ # display_val_to_bold = formatted_df.loc[i, col_name_original]
437
+ # if not (isinstance(display_val_to_bold, str) and display_val_to_bold.startswith("<span style='color: gold;'>") and display_val_to_bold.endswith("</span>")):
438
+ # # Changed from bolding to coloring
439
+ # formatted_df.loc[i, col_name_original] = f"<span style='color: gold;'>{display_val_to_bold}</span>"
440
+ # elif pd.isna(current_numeric_val) or current_numeric_val == -np.inf:
441
+ # cell_content = formatted_df.loc[i, col_name_original]
442
+ # if cell_content is None or \
443
+ # (isinstance(cell_content, str) and \
444
+ # cell_content.strip().lower() in ["n/a", "", "unknown", "nan"]): # Standardize NA display
445
+ # formatted_df.loc[i, col_name_original] = ""
446
+ # return formatted_df
447
+
448
+ # def _apply_markdown_and_bolding(self, df_with_general_formats: pd.DataFrame) -> pd.DataFrame:
449
+ # if df_with_general_formats.empty: return df_with_general_formats
450
+ # formatted_df = df_with_general_formats.copy()
451
+
452
+ # model_id_col_original = self.model_identifier_column
453
+
454
+ # if model_id_col_original in formatted_df.columns and 'model_url' in formatted_df.columns:
455
+ # def create_markdown_link(row):
456
+ # model_id_val = row[model_id_col_original]
457
+ # url = row['model_url']
458
+
459
+ # display_conf = self.model_display_configs.get(str(model_id_val), {})
460
+ # display_name = display_conf.get('display_name', str(model_id_val))
461
+ # url_for_link = display_conf.get('url', url if pd.notna(url) else 'https://google.com')
462
+ # if not url_for_link or pd.isna(url_for_link): url_for_link = 'https://google.com'
463
+ # return f"[{display_name}]({url_for_link})"
464
+ # formatted_df[model_id_col_original] = formatted_df.apply(create_markdown_link, axis=1)
465
+
466
+ # for col_name_original in self.numeric_score_columns_for_bolding:
467
+ # if col_name_original in formatted_df.columns:
468
+ # def to_numeric_for_max(val):
469
+ # if isinstance(val, str):
470
+ # try: return float(val) # Handles "88.00", "75.50", "100", "0"
471
+ # except ValueError: return -np.inf
472
+ # return val if pd.notna(val) else -np.inf
473
+
474
+ # numeric_series_for_max = formatted_df[col_name_original].apply(to_numeric_for_max)
475
+
476
+ # if not numeric_series_for_max.empty and numeric_series_for_max.notna().any() and \
477
+ # pd.api.types.is_numeric_dtype(numeric_series_for_max) and not numeric_series_for_max.eq(-np.inf).all():
478
+ # max_val_numeric = numeric_series_for_max.max(skipna=True)
479
+ # if pd.notna(max_val_numeric) and max_val_numeric != -np.inf:
480
+ # for i in numeric_series_for_max.index:
481
+ # current_numeric_val = numeric_series_for_max.loc[i]
482
+ # if pd.notna(current_numeric_val) and current_numeric_val == max_val_numeric:
483
+ # display_val_to_bold = formatted_df.loc[i, col_name_original]
484
+ # if not (isinstance(display_val_to_bold, str) and display_val_to_bold.startswith("**") and display_val_to_bold.endswith("**")):
485
+ # formatted_df.loc[i, col_name_original] = f"**{display_val_to_bold}**"
486
+ # elif pd.isna(current_numeric_val) or current_numeric_val == -np.inf:
487
+ # cell_content = formatted_df.loc[i, col_name_original]
488
+ # if cell_content is None or \
489
+ # (isinstance(cell_content, str) and \
490
+ # cell_content.strip().lower() in ["n/a", "", "unknown", "nan"]): # Standardize NA display
491
+ # formatted_df.loc[i, col_name_original] = ""
492
+ # return formatted_df
493
+
494
  @staticmethod
495
  def _get_gr_datatypes(df_with_original_cols: pd.DataFrame, model_id_col_original_name: str, score_cols_original_names: List[str]) -> List[str]:
496
  datatypes = []
 
509
  datatypes.append("str")
510
  return datatypes
511
 
512
+ # def get_prepared_dataframe(self, task_key: str, source_filter: str = "All", name_filter_query: str = "") -> pd.DataFrame:
513
+ # original_df_for_task = self.raw_dataframes.get(task_key)
514
+ # if original_df_for_task is None or original_df_for_task.empty:
515
+ # return pd.DataFrame()
516
+
517
+ # processed_df = original_df_for_task.copy()
518
+
519
+ # parent_nlu_nlg_task_keys = ["persian_nlg", "persian_nlu"]
520
+ # if task_key in parent_nlu_nlg_task_keys:
521
+ # cols_to_drop_due_to_object = []
522
+ # for col_name in processed_df.columns:
523
+ # if processed_df[col_name].apply(lambda x: isinstance(x, dict)).any():
524
+ # cols_to_drop_due_to_object.append(col_name)
525
+ # if cols_to_drop_due_to_object:
526
+ # logger.info(f"For overview task '{task_key}', dropping object columns: {cols_to_drop_due_to_object}")
527
+ # processed_df = processed_df.drop(columns=cols_to_drop_due_to_object, errors='ignore')
528
+
529
+ # if 'source_type' in processed_df.columns and source_filter != "All":
530
+ # processed_df = processed_df[processed_df['source_type'] == source_filter]
531
+ # if processed_df.empty: return pd.DataFrame()
532
+
533
+ # if name_filter_query and self.model_identifier_column in processed_df.columns:
534
+ # try:
535
+ # processed_df = processed_df[processed_df[self.model_identifier_column].astype(str).str.contains(name_filter_query, case=False, na=False)]
536
+ # except Exception as e: logger.error(f"Name filter error: {e}")
537
+ # if processed_df.empty: return pd.DataFrame()
538
+
539
+ # if processed_df.empty: return pd.DataFrame()
540
+
541
+ # processed_df = self._apply_general_formatting_to_cells(processed_df, task_key)
542
+ # processed_df = self._apply_markdown_and_bolding(processed_df)
543
+
544
+ # if self.columns_to_hide:
545
+ # columns_to_drop_existing = [col for col in self.columns_to_hide if col in processed_df.columns]
546
+ # if columns_to_drop_existing:
547
+ # processed_df = processed_df.drop(columns=columns_to_drop_existing, errors='ignore')
548
+
549
+ # if "Rank" in processed_df.columns:
550
+ # cols_order = ["Rank"] + [col for col in processed_df.columns if col != "Rank"]
551
+ # processed_df = processed_df[cols_order]
552
+
553
+ # if "Rank" in processed_df.columns:
554
+ # processed_df["Rank"] = processed_df["Rank"].apply(lambda x: str(int(x)) if pd.notna(x) and isinstance(x, (float,int)) and x == int(x) else (str(x) if pd.notna(x) else ""))
555
+
556
+
557
+ # processed_df = processed_df.fillna("")
558
+ # return processed_df
559
+
560
  def get_prepared_dataframe(self, task_key: str, source_filter: str = "All", name_filter_query: str = "") -> pd.DataFrame:
561
  original_df_for_task = self.raw_dataframes.get(task_key)
562
  if original_df_for_task is None or original_df_for_task.empty:
 
595
  processed_df = processed_df.drop(columns=columns_to_drop_existing, errors='ignore')
596
 
597
  if "Rank" in processed_df.columns:
598
+ # Define the function to replace ranks with medal emojis
599
+ def format_rank_with_medals(rank_value):
600
+ try:
601
+ rank_int = int(rank_value)
602
+ if rank_int == 1:
603
+ return "🥇"
604
+ elif rank_int == 2:
605
+ return "🥈"
606
+ elif rank_int == 3:
607
+ return "🥉"
608
+ else:
609
+ return str(rank_int)
610
+ except (ValueError, TypeError):
611
+ # Return original value for non-numeric or missing ranks
612
+ return str(rank_value) if pd.notna(rank_value) else ""
613
+
614
+ # Apply the new formatting function to the "Rank" column
615
+ processed_df["Rank"] = processed_df["Rank"].apply(format_rank_with_medals)
616
+
617
  cols_order = ["Rank"] + [col for col in processed_df.columns if col != "Rank"]
618
  processed_df = processed_df[cols_order]
619
 
 
 
 
 
620
  processed_df = processed_df.fillna("")
621
  return processed_df
622