Ayanami0730 commited on
Commit
71d9111
·
1 Parent(s): 141f575
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- gradio==4.44.1
2
- pandas
3
  numpy
4
  plotly
5
  pathlib
 
1
+ gradio>=5.31.0
2
+ pandas>=1.5
3
  numpy
4
  plotly
5
  pathlib
tabs/__pycache__/leaderboard_tab.cpython-39.pyc CHANGED
Binary files a/tabs/__pycache__/leaderboard_tab.cpython-39.pyc and b/tabs/__pycache__/leaderboard_tab.cpython-39.pyc differ
 
tabs/leaderboard_tab.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import pandas as pd
3
  from pathlib import Path
@@ -7,9 +8,9 @@ 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 = {
@@ -59,7 +60,7 @@ def load_leaderboard() -> pd.DataFrame:
59
  for category, models in MODEL_CATEGORIES.items():
60
  if model_name in models:
61
  return category
62
- return "Others" # 为不在预定义类别中的模型提供默认类别
63
 
64
  df['category'] = df['model'].apply(get_category)
65
  return df
@@ -77,32 +78,15 @@ def make_ranked(df: pd.DataFrame) -> pd.DataFrame:
77
  if col in ranked.columns:
78
  ranked[col] = ranked[col].round(2)
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()
@@ -114,37 +98,47 @@ def filter_data(search_text: str, selected_categories: list):
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"):
121
  with gr.Row():
122
- search_box = gr.Textbox(
123
- label="Model Search",
124
- placeholder="Entering model name to search...",
125
- value=""
126
- )
127
- category_checkboxes = gr.CheckboxGroup(
128
- label="Model Categories",
129
- choices=list(MODEL_CATEGORIES.keys()),
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,19 +152,20 @@ def create_leaderboard_tab():
158
  outputs=table
159
  )
160
 
161
- # 在底部添加列名说明
162
- gr.Markdown(f"""
163
- ### Column Abbreviations
164
- The leaderboard uses abbreviated column names for compact display:
165
- - **overall** - Overall Score
166
- - **comp.** - Comprehensiveness
167
- - **insight** - Insight quality
168
- - **inst.** - Instruction Following
169
- - **read.** - Readability
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
 
1
+ from __future__ import annotations
2
  import gradio as gr
3
  import pandas as pd
4
  from pathlib import Path
 
8
  BASE_DIR = Path(__file__).resolve().parent.parent
9
  DATA_PATH = BASE_DIR / "data" / "leaderboard.csv"
10
 
11
+ # 用于标注的常量
 
12
  CATEGORY_TO_HIGHLIGHT = "Deep Research Agent"
13
+ HIGHLIGHT_EMOJI = "🚀"
14
 
15
  # 列名重命名映射
16
  COLUMN_RENAME_MAP = {
 
60
  for category, models in MODEL_CATEGORIES.items():
61
  if model_name in models:
62
  return category
63
+ return "Others"
64
 
65
  df['category'] = df['model'].apply(get_category)
66
  return df
 
78
  if col in ranked.columns:
79
  ranked[col] = ranked[col].round(2)
80
 
81
+ # 为 Deep Research Agent 添加 HTML 格式(加粗 + 颜色)
82
+ ranked['model'] = ranked.apply(
83
+ lambda row: f'<span style="color: #823AFF;">{HIGHLIGHT_EMOJI} {row["model"]}</span>'
84
+ if row['category'] == CATEGORY_TO_HIGHLIGHT
85
+ else row['model'],
86
+ axis=1
87
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
+ return ranked
 
 
 
90
 
91
  def filter_data(search_text: str, selected_categories: list):
92
  df = load_leaderboard()
 
98
  df = df[df['category'].isin(selected_categories)]
99
 
100
  ranked_df = make_ranked(df)
101
+ return ranked_df
102
 
103
  def create_leaderboard_tab():
104
  with gr.Tab("🏆Leaderboard"):
105
  with gr.Row():
106
+ with gr.Column(scale=1):
107
+ search_box = gr.Textbox(
108
+ label="Model Search",
109
+ placeholder="Entering model name to search...",
110
+ value=""
111
+ )
112
+ with gr.Column(scale=2):
113
+ category_checkboxes = gr.CheckboxGroup(
114
+ label="Model Categories",
115
+ choices=list(MODEL_CATEGORIES.keys()),
116
+ value=list(MODEL_CATEGORIES.keys())
117
+ )
118
 
119
+ # 初始化数据(不使用样式)
120
  initial_df = make_ranked(load_leaderboard())
 
121
 
122
+ # 获取列数据类型,将 model 列设置为 html
123
+ column_count = len(initial_df.columns)
124
+ datatypes = ["str"] * column_count
125
+ model_col_index = initial_df.columns.get_loc('model')
126
+ datatypes[model_col_index] = "html"
127
+
128
+ # 创建 Dataframe 组件
129
  table = gr.Dataframe(
130
+ value=initial_df,
131
+ datatype=datatypes, # 设置数据类型,model 列为 html
132
+ wrap=False, # 防止文本换行
133
+ line_breaks=False, # 单元格内不换行
134
+ max_height=600, # 设置表格最大高度
135
+ show_label=False, # 不显示标签
136
+ elem_id="leaderboard_table" # 添加元素ID
137
  )
138
 
139
  def update_display(search_text, selected_categories):
140
+ df = filter_data(search_text, selected_categories)
141
+ return df
142
 
143
  # 绑定搜索框和复选框的变化事件
144
  search_box.change(
 
152
  outputs=table
153
  )
154
 
155
+ # 在底部添加说明
156
+ with gr.Row():
157
+ gr.Markdown(f"""
158
+ ### 📊 Column Descriptions
159
+ - **Rank**: Model ranking based on overall score
160
+ - **model**: Model name (<span style="color: #823AFF;">{HIGHLIGHT_EMOJI} = {CATEGORY_TO_HIGHLIGHT}</span>)
161
+ - **overall**: Overall Score (weighted average of all metrics)
162
+ - **comp.**: Comprehensiveness - How thorough and complete the research is
163
+ - **insight**: Insight Quality - Depth and value of analysis
164
+ - **inst.**: Instruction Following - Adherence to user instructions
165
+ - **read.**: Readability - Clarity and organization of content
166
+ - **c.acc.**: Citation Accuracy - Correctness of references
167
+ - **eff.c.**: Effective Citations - Relevance and quality of sources
168
+ - **category**: Model category
169
+ """)
170
 
171
  return search_box