File size: 10,398 Bytes
03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc e2eea98 03b1dbc e2eea98 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc 4224b43 03b1dbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
import gradio as gr
import json
import pandas as pd
from collections import defaultdict
import copy as cp
from urllib.request import urlopen, URLError
import re
from datetime import datetime
import time
# Constants
CITATION_BUTTON_TEXT = r"""@misc{2023opencompass,
title={OpenCompass: A Universal Evaluation Platform for Foundation Models},
author={OpenCompass Contributors},
howpublished = {\url{https://github.com/open-compass/opencompass}},
year={2023}
},
}"""
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
OPENCOMPASS_README = (
'https://raw.githubusercontent.com/open-compass/opencompass/main/README.md'
)
GITHUB_REPO = 'https://github.com/open-compass/opencompass'
GITHUB_RAW = 'https://raw.githubusercontent.com/open-compass/opencompass'
GITHUB_BLOB = 'https://github.com/open-compass/opencompass/blob'
# Base URL for the JSON data
DATA_URL_BASE = "http://opencompass.oss-cn-shanghai.aliyuncs.com/assets/research-rank/research-data.REALTIME."
def find_latest_data_url():
"""Find the latest available data URL by trying different dates."""
today = datetime.now()
# Try last 365 days
for i in range(365):
date = today.replace(day=today.day - i)
date_str = date.strftime("%Y%m%d")
url = f"{DATA_URL_BASE}{date_str}.json"
try:
urlopen(url)
return url, date_str
except URLError:
continue
# If no valid URL found, return None
return None, None
def get_latest_data():
"""Get latest data URL and update time"""
data_url, update_time = find_latest_data_url()
if not data_url:
raise Exception("Could not find valid data URL")
formatted_update_time = datetime.strptime(update_time, "%Y%m%d").strftime("%Y-%m-%d")
return data_url, formatted_update_time
# Markdown content
def get_leaderboard_title(update_time):
return f"# CompassAcademic Leaderboard (Last Updated: {update_time})"
MAIN_LEADERBOARD_DESCRIPTION = """## Main Evaluation Results
The CompassAcademic currently focuses on the comprehensive reasoning abilities of LLMs.
- The datasets selected so far include General Knowledge Reasoning (MMLU-Pro/GPQA-Diamond), Logical Reasoning (BBH), Mathematical Reasoning (MATH-500, AIME), Code Completion (LiveCodeBench, HumanEval), and Instruction Following (IFEval).
- Currently, the evaluation primarily targets chat models, with updates featuring the latest community models at irregular intervals.
- Prompts and reproduction scripts can be found in [**OpenCompass**: A Toolkit for Evaluation of LLMs](https://github.com/open-compass/opencompass)π.
"""
def fix_image_urls(content):
"""Fix image URLs in markdown content."""
# Handle the specific logo.svg path
content = content.replace(
'docs/en/_static/image/logo.svg',
'https://raw.githubusercontent.com/open-compass/opencompass/main/docs/en/_static/image/logo.svg',
)
# Replace other relative image paths with absolute GitHub URLs
content = re.sub(
r'!\[[^\]]*\]\((?!http)([^)]+)\)',
lambda m: f'![{m.group(0)}](https://raw.githubusercontent.com/open-compass/opencompass/main/{m.group(1)})',
content,
)
return content
MODEL_SIZE = ['<10B', '10B-70B', '>70B', 'Unknown']
MODEL_TYPE = ['API', 'OpenSource']
def load_data(data_url):
response = urlopen(data_url)
data = json.loads(response.read().decode('utf-8'))
return data
def build_main_table(data):
df = pd.DataFrame(data['globalData']['OverallTable'])
# Add OpenSource column based on models data
models_data = data['models']
df['OpenSource'] = df['model'].apply(
lambda x: 'Yes' if models_data[x]['release'] == 'OpenSource' else 'No'
)
# Add Rank column based on Average Score
df['Rank'] = df['Average'].rank(ascending=False, method='min').astype(int)
columns = {
'Rank': 'Rank',
'model': 'Model',
'org': 'Organization',
'num': 'Parameters',
'OpenSource': 'OpenSource',
'Average': 'Average Score',
'BBH': 'BBH',
'Math-500': 'Math-500',
'AIME': 'AIME',
'MMLU-Pro': 'MMLU-Pro',
'LiveCodeBench': 'LiveCodeBench',
'HumanEval': 'HumanEval',
'GQPA-Diamond': 'GQPA-Diamond',
'IFEval': 'IFEval',
}
df = df[list(columns.keys())].rename(columns=columns)
return df
def filter_table(df, size_ranges, model_types):
filtered_df = df.copy()
# Filter by size
if size_ranges:
def get_size_in_B(param):
if param == 'N/A':
return None
try:
return float(param.replace('B', ''))
except:
return None
filtered_df['size_in_B'] = filtered_df['Parameters'].apply(
get_size_in_B
)
mask = pd.Series(False, index=filtered_df.index)
for size_range in size_ranges:
if size_range == '<10B':
mask |= (filtered_df['size_in_B'] < 10) & (
filtered_df['size_in_B'].notna()
)
elif size_range == '10B-70B':
mask |= (filtered_df['size_in_B'] >= 10) & (
filtered_df['size_in_B'] < 70
)
elif size_range == '>70B':
mask |= filtered_df['size_in_B'] >= 70
elif size_range == 'Unknown':
mask |= filtered_df['size_in_B'].isna()
filtered_df = filtered_df[mask]
filtered_df.drop('size_in_B', axis=1, inplace=True)
# Filter by model type
if model_types:
type_mask = pd.Series(False, index=filtered_df.index)
for model_type in model_types:
if model_type == 'API':
type_mask |= filtered_df['OpenSource'] == 'No'
elif model_type == 'OpenSource':
type_mask |= filtered_df['OpenSource'] == 'Yes'
filtered_df = filtered_df[type_mask]
return filtered_df
def calculate_column_widths(df):
"""Dynamically calculate column widths based on content length."""
column_widths = []
for column in df.columns:
# Get max length of column name and values
header_length = len(str(column))
max_content_length = df[column].astype(str).map(len).max()
# Use the larger of header or content length
# Multiply by average character width (approximately 8 pixels)
# Add padding (20 pixels)
# Increase the multiplier for header length to ensure it fits
width = max(header_length * 10, max_content_length * 8) + 20
# Set minimum width (200 pixels)
width = max(160, width)
# Set maximum width (400 pixels) to prevent extremely wide columns
width = min(400, width)
column_widths.append(width)
return column_widths
def create_interface():
data_url, update_time = get_latest_data()
data = load_data(data_url)
df = build_main_table(data)
title = gr.Markdown(get_leaderboard_title(update_time))
with gr.Blocks() as demo:
title_comp = gr.Markdown(get_leaderboard_title(update_time))
with gr.Tabs() as tabs:
with gr.TabItem("π
Main Leaderboard", elem_id='main'):
gr.Markdown(MAIN_LEADERBOARD_DESCRIPTION)
with gr.Row():
with gr.Column():
size_filter = gr.CheckboxGroup(
choices=MODEL_SIZE,
value=MODEL_SIZE,
label='Model Size',
interactive=True,
)
with gr.Column():
type_filter = gr.CheckboxGroup(
choices=MODEL_TYPE,
value=MODEL_TYPE,
label='Model Type',
interactive=True,
)
with gr.Column():
table = gr.DataFrame(
value=df.sort_values("Average Score", ascending=False),
interactive=False,
wrap=False, # η¦η¨θͺε¨ζ’θ‘
column_widths=calculate_column_widths(df),
)
def update_data():
"""Periodically check for new data and update the interface"""
while True:
time.sleep(300) # Check every 5 minutes
try:
new_data_url, new_update_time = get_latest_data()
if new_data_url != data_url:
new_data = load_data(new_data_url)
new_df = build_main_table(new_data)
filtered_df = filter_table(new_df, size_filter.value, type_filter.value)
title_comp.value = get_leaderboard_title(new_update_time)
table.value = filtered_df.sort_values("Average Score", ascending=False)
except Exception as e:
print(f"Error updating data: {e}")
continue
def update_table(size_ranges, model_types):
filtered_df = filter_table(df, size_ranges, model_types)
return filtered_df.sort_values(
"Average Score", ascending=False
)
size_filter.change(
fn=update_table,
inputs=[size_filter, type_filter],
outputs=table,
)
type_filter.change(
fn=update_table,
inputs=[size_filter, type_filter],
outputs=table,
)
# Set up periodic data update
demo.load(update_data)
with gr.Row():
with gr.Accordion("Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
elem_id='citation-button',
)
return demo
if __name__ == '__main__':
demo = create_interface()
demo.launch(server_name='0.0.0.0')
|