Spaces:
Running
Running
File size: 2,832 Bytes
54f0e5a 498bbe0 54f0e5a 2051b0b 54f0e5a 0a2697b a023ed3 54f0e5a 9020582 54f0e5a 92395fa 54f0e5a 30168ed 2f9a19f 54f0e5a |
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 |
import pandas as pd
from pathlib import Path
from ..styles import highlight_color
abs_path = Path(__file__).parent.parent.parent
def replace_models_names(model_name):
if "gpt" in model_name:
return 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_and_data_types(json_data):
order_list = ["model_name", "overall_accuracy"]
data_types = ["markdown", "number"]
for key in json_data.keys():
if key not in ["model_name", "overall_accuracy"]:
order_list.append(key)
data_types.append("number")
order_list[2:] = sorted(order_list[2:])
return order_list, data_types
def filter_data(selected_columns, search_query):
df = PES_ACCS[selected_columns]
if search_query:
df = df[df['model_name'].str.contains(search_query, case=False, na=False)]
return df
def filter_columns(column_choices):
selected_columns = [col for col in ORDER_LIST if col in column_choices]
filtered_df = PES_ACCS[selected_columns]
return filtered_df.style.highlight_max(color=highlight_color, subset=filtered_df.columns[1:]).format(precision=2)
def load_json_data(file_path, order_list):
PES_ACCS = pd.read_json(file_path)
for column in PES_ACCS.columns:
if PES_ACCS[column].apply(type).eq(dict).any():
PES_ACCS[column] = PES_ACCS[column].apply(str)
PES_ACCS["model_name"] = PES_ACCS["model_name"].apply(
lambda name: replace_models_names(name)
)
for column in PES_ACCS.select_dtypes(include='number').columns:
PES_ACCS[column] = PES_ACCS[column].round(2)
ordered_columns = [col for col in order_list if col in PES_ACCS.columns]
PES_ACCS = PES_ACCS[ordered_columns]
if "overall_accuracy" in PES_ACCS.columns:
PES_ACCS = PES_ACCS.sort_values(by="overall_accuracy", ascending=False)
return PES_ACCS
# file_path = str(abs_path / "leaderboards/pes_accuracy.json")
file_path = str(abs_path / "leaderboards/pes_accs.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, DATA_TYPES = generate_order_list_and_data_types(sample_data)
PES_ACCS = load_json_data(file_path, ORDER_LIST)
STYLED_PES_ACCS = PES_ACCS.style.highlight_max(
color = highlight_color,
subset=PES_ACCS.columns[1:]).format(precision=2)
COLUMN_HEADERS = ORDER_LIST
print('test')
|