Commit
·
141f575
1
Parent(s):
25d5766
fix bugs
Browse files- tabs/leaderboard_tab.py +39 -17
tabs/leaderboard_tab.py
CHANGED
@@ -7,9 +7,9 @@ from typing import Union
|
|
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 = {
|
@@ -71,12 +71,6 @@ def make_ranked(df: pd.DataFrame) -> pd.DataFrame:
|
|
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:
|
@@ -85,6 +79,31 @@ def make_ranked(df: pd.DataFrame) -> pd.DataFrame:
|
|
85 |
|
86 |
return ranked
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def filter_data(search_text: str, selected_categories: list):
|
89 |
df = load_leaderboard()
|
90 |
|
@@ -94,7 +113,8 @@ def filter_data(search_text: str, selected_categories: list):
|
|
94 |
if selected_categories:
|
95 |
df = df[df['category'].isin(selected_categories)]
|
96 |
|
97 |
-
|
|
|
98 |
|
99 |
def create_leaderboard_tab():
|
100 |
with gr.Tab("🏆Leaderboard"):
|
@@ -110,19 +130,21 @@ def create_leaderboard_tab():
|
|
110 |
value=list(MODEL_CATEGORIES.keys())
|
111 |
)
|
112 |
|
|
|
113 |
initial_df = make_ranked(load_leaderboard())
|
|
|
114 |
|
115 |
-
# 创建 Dataframe
|
116 |
table = gr.Dataframe(
|
117 |
-
|
|
|
118 |
wrap=False,
|
119 |
-
|
120 |
-
datatype=["number", "str", "number", "number", "number", "number", "number", "number", "number", "str"]
|
121 |
)
|
122 |
|
123 |
def update_display(search_text, selected_categories):
|
124 |
-
|
125 |
-
return
|
126 |
|
127 |
# 绑定搜索框和复选框的变化事件
|
128 |
search_box.change(
|
@@ -136,7 +158,7 @@ def create_leaderboard_tab():
|
|
136 |
outputs=table
|
137 |
)
|
138 |
|
139 |
-
#
|
140 |
gr.Markdown(f"""
|
141 |
### Column Abbreviations
|
142 |
The leaderboard uses abbreviated column names for compact display:
|
@@ -148,7 +170,7 @@ def create_leaderboard_tab():
|
|
148 |
- **c.acc.** - Citation Accuracy
|
149 |
- **eff.c.** - Effective Citations
|
150 |
|
151 |
-
|
152 |
""")
|
153 |
|
154 |
return search_box
|
|
|
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 = {
|
|
|
71 |
# 重命名列名为简写形式
|
72 |
ranked = ranked.rename(columns=COLUMN_RENAME_MAP)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# 格式化数值列为两位小数
|
75 |
numeric_columns = ['overall', 'comp.', 'insight', 'inst.', 'read.', 'c.acc.', 'eff.c.']
|
76 |
for col in numeric_columns:
|
|
|
79 |
|
80 |
return ranked
|
81 |
|
82 |
+
def apply_styling(df: pd.DataFrame) -> pd.io.formats.style.Styler:
|
83 |
+
"""
|
84 |
+
应用样式到 DataFrame,高亮显示 Deep Research Agent 类别的行
|
85 |
+
"""
|
86 |
+
def highlight_row(row):
|
87 |
+
if row['category'] == CATEGORY_TO_HIGHLIGHT:
|
88 |
+
return [f'background-color: {HIGHLIGHT_COLOR}'] * len(row)
|
89 |
+
else:
|
90 |
+
return [''] * len(row)
|
91 |
+
|
92 |
+
# 创建 styler 对象
|
93 |
+
styler = df.style.apply(highlight_row, axis=1)
|
94 |
+
|
95 |
+
# 格式化数值列显示
|
96 |
+
numeric_columns = ['overall', 'comp.', 'insight', 'inst.', 'read.', 'c.acc.', 'eff.c.']
|
97 |
+
format_dict = {}
|
98 |
+
for col in numeric_columns:
|
99 |
+
if col in df.columns:
|
100 |
+
format_dict[col] = '{:.2f}'
|
101 |
+
|
102 |
+
if format_dict:
|
103 |
+
styler = styler.format(format_dict)
|
104 |
+
|
105 |
+
return styler
|
106 |
+
|
107 |
def filter_data(search_text: str, selected_categories: list):
|
108 |
df = load_leaderboard()
|
109 |
|
|
|
113 |
if selected_categories:
|
114 |
df = df[df['category'].isin(selected_categories)]
|
115 |
|
116 |
+
ranked_df = make_ranked(df)
|
117 |
+
return apply_styling(ranked_df)
|
118 |
|
119 |
def create_leaderboard_tab():
|
120 |
with gr.Tab("🏆Leaderboard"):
|
|
|
130 |
value=list(MODEL_CATEGORIES.keys())
|
131 |
)
|
132 |
|
133 |
+
# 初始化数据并应用样式
|
134 |
initial_df = make_ranked(load_leaderboard())
|
135 |
+
styled_initial_df = apply_styling(initial_df)
|
136 |
|
137 |
+
# 创建 Dataframe 组件,使用 interactive=False 以支持样式
|
138 |
table = gr.Dataframe(
|
139 |
+
value=styled_initial_df,
|
140 |
+
interactive=False, # 关键:必须为 False 才能显示样式
|
141 |
wrap=False,
|
142 |
+
show_search="search" # 添加搜索框功能
|
|
|
143 |
)
|
144 |
|
145 |
def update_display(search_text, selected_categories):
|
146 |
+
styled_df = filter_data(search_text, selected_categories)
|
147 |
+
return styled_df
|
148 |
|
149 |
# 绑定搜索框和复选框的变化事件
|
150 |
search_box.change(
|
|
|
158 |
outputs=table
|
159 |
)
|
160 |
|
161 |
+
# 在底部添加列名说明
|
162 |
gr.Markdown(f"""
|
163 |
### Column Abbreviations
|
164 |
The leaderboard uses abbreviated column names for compact display:
|
|
|
170 |
- **c.acc.** - Citation Accuracy
|
171 |
- **eff.c.** - Effective Citations
|
172 |
|
173 |
+
Rows highlighted in purple indicate **{CATEGORY_TO_HIGHLIGHT}** models.
|
174 |
""")
|
175 |
|
176 |
return search_box
|