File size: 5,595 Bytes
42f14e1 b28a580 42f14e1 b28a580 0c1fd76 b28a580 0474b44 0c1fd76 0474b44 b28a580 0474b44 42f14e1 0474b44 0c1fd76 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0c1fd76 42f14e1 0474b44 b28a580 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0474b44 42f14e1 0c1fd76 42f14e1 0474b44 42f14e1 0474b44 b28a580 0474b44 b28a580 0474b44 |
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 |
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) |