Spaces:
Running
Running
import pandas as pd | |
from pathlib import Path | |
abs_path = Path(__file__).parent.parent.parent | |
def replace_models_names(model_name): | |
replaces = {'meta-llama': 'meta_llama', | |
'epfl-llm':'epfl_llm', | |
'01-ai':'01_ai'} | |
new_name = model_name.replace('model-', '') | |
for k, v in replaces.items(): | |
if new_name.startswith(k): | |
new_name = new_name.replace(k, v) | |
new_name = new_name.replace('-','/',1) | |
new_name = new_name.replace('_','-',1) | |
new_name = f"[{new_name}](https://huggingface.co/{new_name})" | |
return new_name | |
def generate_ORDER_LIST_LEK_and_data_types(json_data): | |
ORDER_LIST_LEK = ["model_name", "overall_accuracy"] | |
data_types = ["markdown", "number"] | |
for key in json_data.keys(): | |
if key not in ["model_name", "overall_accuracy"]: | |
ORDER_LIST_LEK.append(key) | |
data_types.append("number") | |
ORDER_LIST_LEK[2:] = sorted(ORDER_LIST_LEK[2:]) | |
return ORDER_LIST_LEK, data_types | |
def filter_columns_lek(column_choices): | |
selected_columns = [col for col in ORDER_LIST_LEK if col in column_choices] | |
return LEK_ACCS[selected_columns] | |
def load_json_data(file_path, ORDER_LIST_LEK): | |
LEK_ACCS = pd.read_json(file_path) | |
for column in LEK_ACCS.columns: | |
if LEK_ACCS[column].apply(type).eq(dict).any(): | |
LEK_ACCS[column] = LEK_ACCS[column].apply(str) | |
LEK_ACCS["model_name"] = LEK_ACCS["model_name"].apply( | |
lambda name: replace_models_names(name) | |
) | |
for column in LEK_ACCS.select_dtypes(include='number').columns: | |
LEK_ACCS[column] = LEK_ACCS[column].round(2) | |
ordered_columns = [col for col in ORDER_LIST_LEK if col in LEK_ACCS.columns] | |
LEK_ACCS = LEK_ACCS[ordered_columns] | |
if "Score" in LEK_ACCS.columns: | |
LEK_ACCS = LEK_ACCS.sort_values(by="Score", ascending=False) | |
return LEK_ACCS | |
file_path = str(abs_path / "leaderboards/r_lek_report_scores.json") | |
with open(file_path, 'r', encoding='utf-8') as file: | |
sample_data = pd.read_json(file_path).iloc[0].to_dict() # Load the first row as a dict | |
ORDER_LIST_LEK, DATA_TYPES_LEK = generate_ORDER_LIST_LEK_and_data_types(sample_data) | |
LEK_ACCS = load_json_data(file_path, ORDER_LIST_LEK) | |
# LEK_ACCS = LEK_ACCS.reindex(sorted(LEK_ACCS.columns), axis=1) | |
COLUMN_HEADERS_LEK = ORDER_LIST_LEK | |
print(ORDER_LIST_LEK) | |