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