michal
Add more models and sort years tables by model name
e88ceea
Raw
History Blame Contribute Delete
2.02 kB
import pandas as pd
from pathlib import Path
from ..styles import highlight_color
# Define the absolute path to the file
abs_path = Path(__file__).parent.parent.parent
def load_json_data(file_path):
# Load the JSON data
GIM_SCORES = pd.read_json(file_path)
# Reset index so model names become a column and transpose for (year, name) pairs as rows
GIM_SCORES = GIM_SCORES.T.reset_index()
# Rename the first column as 'Model' to keep model names visible
GIM_SCORES.rename(columns={'index': 'Model'}, inplace=True)
# Filter columns that contain 'Egzaminy Gimnazjalne' in the name
filtered_columns = ['Model'] + [col for col in GIM_SCORES.columns if "Egzaminy Gimnazjalne" in col]
GIM_SCORES = GIM_SCORES[filtered_columns]
GIM_SCORES["Model"] = GIM_SCORES["Model"].apply(
lambda name: f"[{name.replace('__','/')}](https://huggingface.co/{name.replace('__','/')})"
)
# Round numeric values to 2 decimal places
numeric_columns = GIM_SCORES.columns[1:] # Get all year columns
GIM_SCORES[numeric_columns] = GIM_SCORES[numeric_columns].apply(pd.to_numeric, errors='coerce') * 100
GIM_SCORES[numeric_columns] = GIM_SCORES[numeric_columns].round(2)
# Convert year part in column names to strings for Gradio compatibility
GIM_SCORES.columns = [col.split(',')[0][1:] if col != 'Model' else col for col in GIM_SCORES.columns]
year_columns = GIM_SCORES.columns[1:]
sorted_year_columns = sorted(year_columns.astype(str).tolist()) # Sort the year columns as strings
sorted_columns = ['Model'] + sorted_year_columns
GIM_SCORES = GIM_SCORES[sorted_columns]
# Sort alphabetically by model name
GIM_SCORES = GIM_SCORES.sort_values(by='Model')
return GIM_SCORES
# Define file path
file_path = str(abs_path / "leaderboards/all_types_years.json")
GIM_SCORES = load_json_data(file_path)
GIM_SCORES = GIM_SCORES.style.highlight_max(
color = highlight_color,
subset=GIM_SCORES.columns[-18:]).format(precision=2)