Commit
·
b91c8cc
1
Parent(s):
f5bb47c
fix bugs
Browse files- tabs/leaderboard_tab.py +36 -59
tabs/leaderboard_tab.py
CHANGED
@@ -7,11 +7,11 @@ from typing import Union
|
|
7 |
BASE_DIR = Path(__file__).resolve().parent.parent
|
8 |
DATA_PATH = BASE_DIR / "data" / "leaderboard.csv"
|
9 |
|
10 |
-
#
|
11 |
-
HIGHLIGHT_COLOR = "#E6D8FF"
|
12 |
CATEGORY_TO_HIGHLIGHT = "Deep Research Agent"
|
|
|
13 |
|
14 |
-
#
|
15 |
COLUMN_RENAME_MAP = {
|
16 |
'overall_score': 'overall',
|
17 |
'comprehensiveness': 'comp.',
|
@@ -71,6 +71,18 @@ def make_ranked(df: pd.DataFrame) -> pd.DataFrame:
|
|
71 |
# 重命名列名为简写形式
|
72 |
ranked = ranked.rename(columns=COLUMN_RENAME_MAP)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
return ranked
|
75 |
|
76 |
def filter_data(search_text: str, selected_categories: list):
|
@@ -84,51 +96,6 @@ def filter_data(search_text: str, selected_categories: list):
|
|
84 |
|
85 |
return make_ranked(df)
|
86 |
|
87 |
-
# 新增:辅助函数用于样式化DataFrame
|
88 |
-
def _style_specific_rows(row, category_column_name='category', target_category=CATEGORY_TO_HIGHLIGHT, color=HIGHLIGHT_COLOR):
|
89 |
-
"""
|
90 |
-
根据行的类别返回样式列表。如果类别匹配目标类别,则应用背景色。
|
91 |
-
"""
|
92 |
-
apply_color = color if row.get(category_column_name) == target_category else ''
|
93 |
-
return [f'background-color: {apply_color}' for _ in row]
|
94 |
-
|
95 |
-
def _apply_table_styling(df: pd.DataFrame):
|
96 |
-
"""
|
97 |
-
应用表格样式:
|
98 |
-
- 高亮显示 CATEGORY_TO_HIGHLIGHT 的行
|
99 |
-
- 保留 'category' 列显示
|
100 |
-
- 格式化数值为两位小数
|
101 |
-
返回 Pandas Styler 对象。
|
102 |
-
"""
|
103 |
-
if df.empty:
|
104 |
-
return df.style
|
105 |
-
|
106 |
-
styled_df = df.copy()
|
107 |
-
|
108 |
-
# 获取数值列(排除 Rank, model, category 列)
|
109 |
-
numeric_columns = []
|
110 |
-
for col in styled_df.columns:
|
111 |
-
if col not in ['Rank', 'model', 'category']:
|
112 |
-
# 检查是否为数值类型
|
113 |
-
if styled_df[col].dtype in ['float64', 'int64'] or pd.api.types.is_numeric_dtype(styled_df[col]):
|
114 |
-
numeric_columns.append(col)
|
115 |
-
|
116 |
-
# 应用行样式 - 高亮特定类别的行
|
117 |
-
styler = styled_df.style.apply(
|
118 |
-
_style_specific_rows,
|
119 |
-
axis=1,
|
120 |
-
category_column_name='category',
|
121 |
-
target_category=CATEGORY_TO_HIGHLIGHT,
|
122 |
-
color=HIGHLIGHT_COLOR
|
123 |
-
)
|
124 |
-
|
125 |
-
# 使用 Styler 的 format 方法格式化数值列为两位小数
|
126 |
-
if numeric_columns:
|
127 |
-
format_dict = {col: '{:.2f}' for col in numeric_columns}
|
128 |
-
styler = styler.format(format_dict)
|
129 |
-
|
130 |
-
return styler
|
131 |
-
|
132 |
def create_leaderboard_tab():
|
133 |
with gr.Tab("🏆Leaderboard"):
|
134 |
with gr.Row():
|
@@ -143,20 +110,21 @@ def create_leaderboard_tab():
|
|
143 |
value=list(MODEL_CATEGORIES.keys())
|
144 |
)
|
145 |
|
146 |
-
|
147 |
-
styled_initial_value = _apply_table_styling(initial_df_raw.copy())
|
148 |
|
|
|
149 |
table = gr.Dataframe(
|
150 |
-
interactive=False,
|
151 |
-
wrap=False,
|
152 |
-
value=
|
|
|
153 |
)
|
154 |
|
155 |
def update_display(search_text, selected_categories):
|
156 |
-
|
157 |
-
|
158 |
-
return styled_updated_value
|
159 |
|
|
|
160 |
search_box.change(
|
161 |
fn=update_display,
|
162 |
inputs=[search_box, category_checkboxes],
|
@@ -168,10 +136,19 @@ def create_leaderboard_tab():
|
|
168 |
outputs=table
|
169 |
)
|
170 |
|
171 |
-
#
|
172 |
-
gr.Markdown("""
|
173 |
### Column Abbreviations
|
174 |
-
The leaderboard uses abbreviated column names for compact display:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
""")
|
176 |
|
177 |
return search_box
|
|
|
7 |
BASE_DIR = Path(__file__).resolve().parent.parent
|
8 |
DATA_PATH = BASE_DIR / "data" / "leaderboard.csv"
|
9 |
|
10 |
+
# 用于标记的常量
|
|
|
11 |
CATEGORY_TO_HIGHLIGHT = "Deep Research Agent"
|
12 |
+
HIGHLIGHT_SYMBOL = "⭐"
|
13 |
|
14 |
+
# 列名重命名映射
|
15 |
COLUMN_RENAME_MAP = {
|
16 |
'overall_score': 'overall',
|
17 |
'comprehensiveness': 'comp.',
|
|
|
71 |
# 重命名列名为简写形式
|
72 |
ranked = ranked.rename(columns=COLUMN_RENAME_MAP)
|
73 |
|
74 |
+
# 为特殊类别添加星号标记
|
75 |
+
ranked['model'] = ranked.apply(
|
76 |
+
lambda row: f"{HIGHLIGHT_SYMBOL} {row['model']}" if row['category'] == CATEGORY_TO_HIGHLIGHT else row['model'],
|
77 |
+
axis=1
|
78 |
+
)
|
79 |
+
|
80 |
+
# 格式化数值列为两位小数
|
81 |
+
numeric_columns = ['overall', 'comp.', 'insight', 'inst.', 'read.', 'c.acc.', 'eff.c.']
|
82 |
+
for col in numeric_columns:
|
83 |
+
if col in ranked.columns:
|
84 |
+
ranked[col] = ranked[col].round(2)
|
85 |
+
|
86 |
return ranked
|
87 |
|
88 |
def filter_data(search_text: str, selected_categories: list):
|
|
|
96 |
|
97 |
return make_ranked(df)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
def create_leaderboard_tab():
|
100 |
with gr.Tab("🏆Leaderboard"):
|
101 |
with gr.Row():
|
|
|
110 |
value=list(MODEL_CATEGORIES.keys())
|
111 |
)
|
112 |
|
113 |
+
initial_df = make_ranked(load_leaderboard())
|
|
|
114 |
|
115 |
+
# 创建 Dataframe 组件,指定每列的数据类型
|
116 |
table = gr.Dataframe(
|
117 |
+
interactive=False,
|
118 |
+
wrap=False,
|
119 |
+
value=initial_df,
|
120 |
+
datatype=["number", "str", "number", "number", "number", "number", "number", "number", "number", "str"]
|
121 |
)
|
122 |
|
123 |
def update_display(search_text, selected_categories):
|
124 |
+
filtered_df = filter_data(search_text, selected_categories)
|
125 |
+
return filtered_df
|
|
|
126 |
|
127 |
+
# 绑定搜索框和复选框的变化事件
|
128 |
search_box.change(
|
129 |
fn=update_display,
|
130 |
inputs=[search_box, category_checkboxes],
|
|
|
136 |
outputs=table
|
137 |
)
|
138 |
|
139 |
+
# 在底部添加列名说明和星号说明
|
140 |
+
gr.Markdown(f"""
|
141 |
### Column Abbreviations
|
142 |
+
The leaderboard uses abbreviated column names for compact display:
|
143 |
+
- **overall** - Overall Score
|
144 |
+
- **comp.** - Comprehensiveness
|
145 |
+
- **insight** - Insight quality
|
146 |
+
- **inst.** - Instruction Following
|
147 |
+
- **read.** - Readability
|
148 |
+
- **c.acc.** - Citation Accuracy
|
149 |
+
- **eff.c.** - Effective Citations
|
150 |
+
|
151 |
+
{HIGHLIGHT_SYMBOL} indicates **{CATEGORY_TO_HIGHLIGHT}** models
|
152 |
""")
|
153 |
|
154 |
return search_box
|