Spaces:
Running
Running
File size: 2,982 Bytes
21b6db8 30b8f34 21b6db8 30b8f34 e6a31da 21b6db8 30b8f34 21b6db8 30b8f34 21b6db8 30b8f34 21b6db8 30b8f34 21b6db8 e6a31da 54bda52 e6a31da 21b6db8 54bda52 21b6db8 30b8f34 21b6db8 30b8f34 21b6db8 e679095 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | from __future__ import annotations
import pandas as pd
from src.display.i18n import t
from src.display.utils import AutoEvalColumn, COLS, fields
INTERNAL_MODEL_COL = AutoEvalColumn.model.name
INTERNAL_TEAM_COL = AutoEvalColumn.team.name
INTERNAL_DATASET_MODEL_COL = "model"
INTERNAL_DATASET_TEAM_COL = "team"
MODEL_COL = t("col_model")
TEAM_COL = t("col_team")
_NUMBER_COLS = {
AutoEvalColumn.average.name,
AutoEvalColumn.params.name,
AutoEvalColumn.likes.name,
}
_BOOL_COLS = {
AutoEvalColumn.still_on_hub.name,
}
def _rename_model_team_columns(
df: pd.DataFrame,
model_key: str,
team_key: str,
) -> pd.DataFrame:
rename: dict[str, str] = {}
for source, target in (
(model_key, MODEL_COL),
(team_key, TEAM_COL),
(INTERNAL_MODEL_COL, MODEL_COL),
(INTERNAL_TEAM_COL, TEAM_COL),
("Model", MODEL_COL),
("Team", TEAM_COL),
):
if source in df.columns and source != target:
rename[source] = target
if not rename:
return df
return df.rename(columns=rename)
def localize_main_leaderboard_df(df: pd.DataFrame) -> pd.DataFrame:
return _rename_model_team_columns(df, INTERNAL_MODEL_COL, INTERNAL_TEAM_COL)
def localize_dataset_leaderboard_df(df: pd.DataFrame) -> pd.DataFrame:
return _rename_model_team_columns(
df, INTERNAL_DATASET_MODEL_COL, INTERNAL_DATASET_TEAM_COL
)
def main_board_datatype_for_df(df: pd.DataFrame) -> list[str]:
"""Build Leaderboard datatypes aligned to the actual dataframe columns."""
from src.about import Tasks
number_cols = set(_NUMBER_COLS) | {task.value.col_name for task in Tasks}
result: list[str] = []
for col in df.columns:
if col in number_cols:
result.append("number")
elif col in _BOOL_COLS:
result.append("bool")
else:
result.append("str")
return result
def main_board_datatype() -> list[str]:
col_types = {c.name: c.type for c in fields(AutoEvalColumn)}
return [col_types[name] for name in COLS]
def main_board_default_cols() -> list[str]:
from src.about import Tasks
return [
MODEL_COL,
TEAM_COL,
AutoEvalColumn.average.name,
*[task.value.col_name for task in Tasks],
]
def main_board_hidden_columns() -> list[str]:
"""Metadata columns hidden from the table and the column picker."""
from src.about import Tasks
keep_visible = {
AutoEvalColumn.model_type_symbol.name,
MODEL_COL,
TEAM_COL,
AutoEvalColumn.average.name,
*[task.value.col_name for task in Tasks],
}
localized_cols = []
for col in COLS:
if col == INTERNAL_MODEL_COL:
localized_cols.append(MODEL_COL)
elif col == INTERNAL_TEAM_COL:
localized_cols.append(TEAM_COL)
else:
localized_cols.append(col)
return [col for col in localized_cols if col not in keep_visible]
|