XuyaoWang's picture
wip
0c1fd76
import os
import json
import gradio as gr
import pandas as pd
import numpy as np
from pathlib import Path
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import snapshot_download
from src.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
EVALUATION_QUEUE_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
ABOUT_TEXT,
SUBMISSION_TEXT
)
from src.display.css_html_js import custom_css
from src.display.formatting import has_no_nan_values, make_clickable_model, model_hyperlink
# 定义列组
COLUMN_GROUPS = {
"ALL": ["Model", "Perception", "Reasoning", "IF", "Safety", "AMU Score",
"Modality Selection", "Instruction Following", "Modality Synergy",
"AMG Score", "Overall", "Verified"],
"AMU": ["Model", "Perception", "Reasoning", "IF", "Safety", "AMU Score", "Verified"],
"AMG": ["Model", "Modality Selection", "Instruction Following", "Modality Synergy", "AMG Score", "Verified"]
}
def format_table(df):
"""Format the dataframe for display"""
# 设置列的显示格式
float_cols = df.select_dtypes(include=['float64']).columns
for col in float_cols:
df[col] = df[col].apply(lambda x: f"{x:.2f}") # 修改为保留2位小数
bold_columns = ['AMU Score', 'AMG Score', 'Overall']
for col in bold_columns:
if col in df.columns:
df[col] = df[col].apply(lambda x: f'**{x}**')
# 添加模型链接
model_links = dict(zip(df['Model'], df['Model Link']))
# df['Model'] = df['Model'].apply(lambda x: f'<a href="{model_links[x]}" target="_blank">{x}</a>')
df['Model'] = df['Model'].apply(lambda x: f'[{x}]({model_links[x]})')
# df['Model'] = df.apply(lambda x: model_hyperlink(model_links[x['Model']], x['Model']), axis=1)
return df
def regex_table(dataframe, regex, filter_button, column_group="ALL"):
"""Takes a model name as a regex, then returns only the rows that has that in it."""
# 深拷贝确保不修改原始数据
df = dataframe.copy()
# 选择要显示的列
columns_to_show = COLUMN_GROUPS.get(column_group, COLUMN_GROUPS["ALL"])
df = df[columns_to_show]
# Split regex statement by comma and trim whitespace around regexes
if regex:
regex_list = [x.strip() for x in regex.split(",")]
# Join the list into a single regex pattern with '|' acting as OR
combined_regex = '|'.join(regex_list)
# Filter based on model name regex
df = df[df["Model"].str.contains(combined_regex, case=False, na=False)]
df = df.sort_values(by='Overall' if 'Overall' in columns_to_show else columns_to_show[-1], ascending=False)
df.reset_index(drop=True, inplace=True)
# Add index column
df.insert(0, '', range(1, 1 + len(df)))
return df
df = pd.read_csv("data/eval_board.csv").sort_values(by='Overall', ascending=False)
total_models = len(df)
# Format numbers and add links
df = format_table(df)
with gr.Blocks(css=custom_css) as app:
gr.HTML(TITLE)
with gr.Row():
with gr.Column(scale=6):
gr.Markdown(INTRODUCTION_TEXT.format(str(total_models)))
with gr.Tabs(elem_classes="tab-buttons") as tabs:
with gr.TabItem("🏆 Model Performance Leaderboard"):
with gr.Row():
search_overall = gr.Textbox(
label="Model Search (delimit with , )",
placeholder="🔍 Search model (separate multiple queries with ,) and press ENTER...",
show_label=False
)
column_group = gr.Radio(
choices=list(COLUMN_GROUPS.keys()),
value="ALL",
label="Select columns to show"
)
with gr.Row():
performance_table_hidden = gr.Dataframe(
df,
headers=df.columns.tolist(),
elem_id="performance_table_hidden",
wrap=True,
visible=False,
datatype='markdown',
)
performance_table = gr.Dataframe(
regex_table(df.copy(), "", []),
headers=df.columns.tolist(),
elem_id="performance_table",
wrap=True,
show_label=False,
datatype='markdown',
)
with gr.TabItem("About"):
gr.Markdown(ABOUT_TEXT)
with gr.TabItem("Submit results 🚀", id=3):
gr.Markdown(SUBMISSION_TEXT)
with gr.Accordion("📚 Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
lines=7,
label="Copy the following to cite these results.",
elem_id="citation-button",
show_copy_button=True,
)
# Set up event handlers
def update_table(search_text, selected_group):
return regex_table(df, search_text, [], selected_group)
search_overall.change(
update_table,
inputs=[search_overall, column_group],
outputs=performance_table
)
column_group.change(
update_table,
inputs=[search_overall, column_group],
outputs=performance_table
)
# Set up scheduler
scheduler = BackgroundScheduler()
scheduler.add_job(lambda: None, "interval", seconds=18000) # every 5 hours
scheduler.start()
# Launch the app
app.launch(share=True)