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