import pandas as pd MODEL_SIZE = ['<4B', '4B-10B', '10B-20B', '20B-40B', '>40B', 'Unknown'] MODEL_TYPE = ['API', 'Open Source'] search_default_val = 'Model name search (fuzzy, case insensitive)' data_filepath = 'leaderboard_data.csv' def build_df(): raw_df = pd.read_csv(data_filepath) df = pd.DataFrame() df['_name'] = raw_df['name'] names_html = [] for _, row in raw_df.iterrows(): name = row['name'] if row['clickable']: hfp = row['hf_path'] names_html.append(f'{name}') else: names_html.append(name) df['Name'] = names_html df['Eval Date'] = raw_df['eval_date'] df['Params (B)'] = [round(params / 1e9, 1) for params in raw_df['num_params']] df['_parameters'] = raw_df['num_params'] type_map = { 'Rank': 'number', 'Name': 'html', 'Eval Date': 'html', 'Params (B)': 'number', } for coln in raw_df.columns: if coln.startswith('SCORE '): newc = coln[6:] if newc == 'overall': newc = '⭐ Overall' df[newc] = raw_df[coln].round(2) type_map[newc] = 'number' df.sort_values('⭐ Overall', ascending=False, inplace=True) df.reset_index(drop=True, inplace=True) df.insert(0, 'Rank', list(range(1, len(df)+1))) return df, type_map def model_size_flag(sz, FIELDS): if pd.isna(sz) and 'Unknown' in FIELDS: return True if pd.isna(sz): return False if '<4B' in FIELDS and sz < 4e9: return True if '4B-10B' in FIELDS and sz >= 4e9 and sz < 1e10: return True if '10B-20B' in FIELDS and sz >= 1e10 and sz < 2e10: return True if '20B-40B' in FIELDS and sz >= 2e10 and sz < 4e10: return True if '>40B' in FIELDS and sz >= 4e10: return True return False def model_type_flag(line, FIELDS): if 'Open Source' in FIELDS and not pd.isna(line['_parameters']): return True if 'API' in FIELDS and pd.isna(line['_parameters']): return True return False