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