Blisky-li commited on
Commit
e700d6d
·
verified ·
1 Parent(s): d4ebcd4

Upload 131 files

Browse files
app.py CHANGED
@@ -1,332 +1,394 @@
1
- import os
2
- import gradio as gr
3
- import pandas as pd
4
- from src.populate import get_leaderboard_df, get_filtered_leaderboard
5
- from src.display.filters import get_model_type_choices, get_strategy_choices, get_metric_categories
6
-
7
- # 配置路径
8
- RESULTS_PATH = os.path.join(os.path.dirname(__file__), "results")
9
-
10
- # 确保结果目录存在
11
- os.makedirs(RESULTS_PATH, exist_ok=True)
12
-
13
-
14
- def get_category_columns(df, category):
15
- """获取特定类别的指标列,根据类别应用不同的命名规则"""
16
- if df.empty:
17
- return [], {}
18
-
19
- category_name = category["name"]
20
- prefixes = category["prefix"]
21
- if not isinstance(prefixes, list):
22
- prefixes = [prefixes]
23
-
24
- # 确保model_name和model_type在前面
25
- columns = []
26
- if 'model_name' in df.columns:
27
- columns.append('model_name')
28
- if 'model_type' in df.columns and 'model_type' not in columns:
29
- columns.append('model_type')
30
-
31
- # 收集并处理指标列
32
- metric_columns = []
33
- for col in df.columns:
34
- for p in prefixes:
35
- if col.startswith(f"MAE_{p}") or col.startswith(f"MSE_{p}"):
36
- # 不同类别使用不同的重命名规则
37
- if category_name == "平稳性/非平稳性":
38
- # 平稳性保留原始名称
39
- simplified_col = col
40
- elif category_name == "方差特性":
41
- # 方差特性:保留homo/hetero区分(小写简化)
42
- if "Homo-Scedasticity" in p:
43
- simplified_col = col.replace(p, "Homo_", 1)
44
- elif "Hetero-Scedasticity" in p:
45
- simplified_col = col.replace(p, "Hetero_", 1)
46
- else:
47
- simplified_col = col # 兜底
48
- elif category_name == "季节数":
49
-
50
- # 方差特性:保留homo/hetero区分(小写简化)
51
- if "Seasonality_Count" in p:
52
-
53
- simplified_col = col.replace(p, "Count", 1)
54
- else:
55
- simplified_col = col # 兜底
56
- else:
57
- # 其他类别(除平稳性和方差特性外)移除大类前缀
58
- simplified_col = col.replace(p, "", 1)
59
- metric_columns.append((col, simplified_col))
60
- break # 避免重复处理
61
-
62
- # 去重并保持顺序
63
- seen = set()
64
- unique_metrics = []
65
- for col, simplified in metric_columns:
66
- if col not in seen:
67
- seen.add(col)
68
- unique_metrics.append((col, simplified))
69
-
70
- # 过滤存在的列
71
- existing_columns = [col for col in columns + [col for col, _ in unique_metrics] if col in df.columns]
72
-
73
- # 创建重命名字典
74
- rename_dict = {col: simplified for col, simplified in unique_metrics if col in existing_columns}
75
-
76
- return existing_columns, rename_dict
77
-
78
-
79
- def refresh_leaderboard():
80
- """刷新排行榜数据,适配新的列处理逻辑"""
81
- if not os.path.exists(RESULTS_PATH):
82
- error_msg = f"❌ 结果目录不存在: {RESULTS_PATH}"
83
- outputs = []
84
- categories = get_metric_categories()
85
- for _ in categories:
86
- outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
87
- outputs.append(gr.Markdown(value=error_msg, visible=True))
88
- return outputs
89
-
90
- if not os.path.isdir(RESULTS_PATH):
91
- error_msg = f"❌ {RESULTS_PATH} 不是一个目录"
92
- outputs = []
93
- categories = get_metric_categories()
94
- for _ in categories:
95
- outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
96
- outputs.append(gr.Markdown(value=error_msg, visible=True))
97
- return outputs
98
-
99
- df = get_leaderboard_df(RESULTS_PATH)
100
- categories = get_metric_categories()
101
- outputs = []
102
-
103
- for category in categories:
104
- if df.empty:
105
- outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
106
- else:
107
- # 调用修改后的get_category_columns,获取列列表和重命名字典
108
- category_cols, rename_dict = get_category_columns(df, category)
109
- display_df = df[category_cols].copy()
110
-
111
- # 应用列重命名
112
- display_df = display_df.rename(columns=rename_dict)
113
-
114
- # 截断过长的模型名称
115
- if 'model_name' in display_df.columns:
116
- display_df['model_name'] = display_df['model_name'].str.slice(0, 25) + \
117
- (display_df['model_name'].str.len() > 25).map({True: '...', False: ''})
118
-
119
- outputs.append(gr.Dataframe(value=display_df, visible=True))
120
-
121
- if df.empty:
122
- model_folders = [f for f in os.listdir(RESULTS_PATH) if os.path.isdir(os.path.join(RESULTS_PATH, f))]
123
- error_msg = "⚠️ 找到模型文件夹,但无法加载数据" if model_folders else f"⚠️ 未在 {RESULTS_PATH} 中找到模型"
124
- outputs.append(gr.Markdown(value=error_msg, visible=True))
125
- else:
126
- outputs.append(gr.Markdown(value="", visible=False))
127
-
128
- return outputs
129
-
130
-
131
- def apply_filters(model_type, strategies, filter_mode):
132
- """应用筛选条件,适配新的列处理逻辑"""
133
- filtered_df = get_filtered_leaderboard(
134
- RESULTS_PATH,
135
- model_type=model_type,
136
- strategies=strategies,
137
- filter_mode=filter_mode
138
- )
139
- categories = get_metric_categories()
140
- outputs = []
141
-
142
- for category in categories:
143
- if filtered_df.empty:
144
- outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
145
- else:
146
- # 调用修改后的get_category_columns,获取列列表和重命名字典
147
- category_cols, rename_dict = get_category_columns(filtered_df, category)
148
- display_df = filtered_df[category_cols].copy()
149
-
150
- # 应用列重命名
151
- display_df = display_df.rename(columns=rename_dict)
152
-
153
- # 截断模型名称
154
- if 'model_name' in display_df.columns:
155
- display_df['model_name'] = display_df['model_name'].str.slice(0, 25) + \
156
- (display_df['model_name'].str.len() > 25).map({True: '...', False: ''})
157
-
158
- outputs.append(gr.Dataframe(value=display_df, visible=True))
159
-
160
- outputs.append(gr.Markdown(value="⚠️ 没有找到符合筛选条件的模型。", visible=filtered_df.empty))
161
- return outputs
162
-
163
-
164
- def create_interface():
165
- """创建Gradio界面,单表格固定model_name列(兼容旧版本Gradio)"""
166
- try:
167
- model_type_choices = get_model_type_choices()
168
- except Exception as e:
169
- model_type_choices = ["All"]
170
- print(f"获取模型类型选项时出错: {str(e)}")
171
-
172
- try:
173
- strategy_choices = get_strategy_choices(RESULTS_PATH)
174
- except Exception as e:
175
- strategy_choices = []
176
- print(f"获取策略选项时出错: {str(e)}")
177
-
178
- categories = get_metric_categories()
179
-
180
- with gr.Blocks(title="Aries 模型评估排行榜") as demo:
181
- # 添加CSS确保model_name列固定
182
- gr.HTML("""
183
- <style>
184
- /* 表格容器基础设置 */
185
- .fixed-column-table {
186
- overflow: visible !important; /* 原先是auto,改为visible禁用滚动条 */
187
- position: relative !important;
188
- max-height: 90vh !important;
189
- height: auto !important;
190
- }
191
-
192
- /* 单元格内边距优化 */
193
- .fixed-column-table td,
194
- .fixed-column-table th {
195
- padding: 0.2rem 0.3rem !important;
196
- }
197
-
198
- /* 基础模式(浅色)样式 */
199
- .fixed-column-table table th:first-child,
200
- .fixed-column-table table td:first-child {
201
- position: sticky !important;
202
- left: 0 !important;
203
- z-index: 2 !important;
204
- background-color: white !important;
205
- color: #333 !important; /* 文本色 */
206
- min-width: 150px !important;
207
- max-width: 150px !important;
208
- font-weight: bold !important;
209
- box-shadow: 1px 0 2px rgba(0,0,0,0.1) !important;
210
- }
211
-
212
- .fixed-column-table table thead th {
213
- position: sticky !important;
214
- top: 0 !important;
215
- z-index: 1 !important;
216
- background-color: white !important;
217
- color: #333 !important; /* 文本色 */
218
- }
219
-
220
- .fixed-column-table table thead th:first-child {
221
- z-index: 3 !important;
222
- }
223
-
224
- /* 第二列宽度设置 */
225
- .fixed-column-table table th:nth-child(2),
226
- .fixed-column-table table td:nth-child(2) {
227
- min-width: 215px !important;
228
- max-width: 215px !important;
229
- white-space: nowrap !important;
230
- overflow: hidden !important;
231
- text-overflow: ellipsis !important;
232
- }
233
-
234
- /* 禁用内部滚动 */
235
- .fixed-column-table .dataframe-container {
236
- overflow: visible !important;
237
- }
238
-
239
- /* 深色模式适配 */
240
- @media (prefers-color-scheme: dark) {
241
- .fixed-column-table table th:first-child,
242
- .fixed-column-table table td:first-child {
243
- background-color: #333 !important;
244
- color: #fff !important;
245
- box-shadow: 1px 0 2px rgba(0,0,0,0.3) !important;
246
- }
247
-
248
- .fixed-column-table table thead th {
249
- background-color: #333 !important;
250
- color: #fff !important;
251
- }
252
- }
253
- </style>
254
- """)
255
-
256
- gr.Markdown("# 🚀 Aries 模型评估排行榜")
257
-
258
- with gr.Tabs():
259
- with gr.Tab("模型排行榜"):
260
- with gr.Row():
261
- with gr.Column(scale=1):
262
- gr.Markdown("### 筛选条件")
263
-
264
- model_type = gr.Dropdown(
265
- choices=model_type_choices,
266
- label="模型类型",
267
- value="All"
268
- )
269
-
270
- strategies = gr.CheckboxGroup(
271
- choices=strategy_choices,
272
- label="选择策略(多选)",
273
- value=[]
274
- )
275
-
276
- filter_mode = gr.Radio(
277
- choices=["交集 (满足所有选中策略)", "并集 (满足任一选中策略)"],
278
- label="筛选模式",
279
- value="交集 (满足所有选中策略)"
280
- )
281
-
282
- filter_btn = gr.Button("应用筛选", variant="primary")
283
- refresh_btn = gr.Button("刷新数据")
284
-
285
- with gr.Column(scale=3):
286
- empty_state = gr.Markdown(visible=False)
287
-
288
- with gr.Tabs() as category_tabs:
289
- category_dataframes = []
290
- for category in categories:
291
- with gr.Tab(category["name"]):
292
- # 单表格组件,移除不支持的sortable参数
293
- df_component = gr.Dataframe(
294
- interactive=False,
295
- wrap=True,
296
- label=category["description"],
297
- elem_classes="fixed-column-table"
298
- )
299
- category_dataframes.append(df_component)
300
-
301
- with gr.Tab("关于"):
302
- gr.Markdown("""
303
- ## 关于 Aries 模型评估排行榜
304
- 该排行榜展示了各种模型在标准基准测试中的表现,包含所有评估指标。
305
- """)
306
-
307
- # 设置事件处理
308
- filter_btn.click(
309
- fn=apply_filters,
310
- inputs=[model_type, strategies, filter_mode],
311
- outputs=category_dataframes + [empty_state]
312
- )
313
-
314
- refresh_btn.click(
315
- fn=refresh_leaderboard,
316
- outputs=category_dataframes + [empty_state]
317
- )
318
-
319
- demo.load(
320
- fn=refresh_leaderboard,
321
- outputs=category_dataframes + [empty_state]
322
- )
323
-
324
- return demo
325
-
326
-
327
- if __name__ == "__main__":
328
- print(f"正在启动Aries模型评估排行榜,结果目录: {RESULTS_PATH}")
329
- demo = create_interface()
330
- demo.launch()
331
-
332
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import pandas as pd
4
+ from src.populate import get_leaderboard_df, get_filtered_leaderboard
5
+ from src.display.filters import get_model_type_choices, get_strategy_choices, get_metric_categories
6
+ from src.language import lang
7
+ import logging
8
+ import traceback
9
+
10
+ # 配置路径
11
+ RESULTS_PATH = os.path.join(os.path.dirname(__file__), "results")
12
+
13
+ # 确保结果目录存在
14
+ os.makedirs(RESULTS_PATH, exist_ok=True)
15
+
16
+ # 配置日志
17
+ logging.basicConfig(
18
+ level=logging.INFO,
19
+ format="%(asctime)s - %(levelname)s - %(message)s"
20
+ )
21
+ logger = logging.getLogger(__name__)
22
+
23
+ # 配置路径
24
+ RESULTS_PATH = os.path.join(os.path.dirname(__file__), "results")
25
+
26
+ # 确保结果目录存在
27
+ os.makedirs(RESULTS_PATH, exist_ok=True)
28
+
29
+
30
+
31
+ def get_category_columns(df, category):
32
+ """获取特定类别的指标列,根据类别应用不同的命名规则"""
33
+ if df.empty:
34
+ return [], {}
35
+
36
+ category_name = category["name"]
37
+ prefixes = category["prefix"]
38
+ if not isinstance(prefixes, list):
39
+ prefixes = [prefixes]
40
+
41
+ # 确保model_name和model_type在前面
42
+ columns = []
43
+ if 'model_name' in df.columns:
44
+ columns.append('model_name')
45
+ if 'model_type' in df.columns and 'model_type' not in columns:
46
+ columns.append('model_type')
47
+
48
+ # 收集并处理指标列
49
+ metric_columns = []
50
+ for col in df.columns:
51
+ for p in prefixes:
52
+ if col.startswith(f"MAE_{p}") or col.startswith(f"MSE_{p}"):
53
+ # 不同类别使用不同的重命名规则
54
+ if category_name == "平稳性/非平稳性":
55
+ # 平稳性保留原始名称
56
+ simplified_col = col
57
+ elif category_name == "方差特性":
58
+ # 方差特性:保留homo/hetero区分(小写简化)
59
+ if "Homo-Scedasticity" in p:
60
+ simplified_col = col.replace(p, "Homo_", 1)
61
+ elif "Hetero-Scedasticity" in p:
62
+ simplified_col = col.replace(p, "Hetero_", 1)
63
+ else:
64
+ simplified_col = col # 兜底
65
+ elif category_name == "季节数":
66
+
67
+ # 方差特性:保留homo/hetero区分(小写简化)
68
+ if "Seasonality_Count" in p:
69
+
70
+ simplified_col = col.replace(p, "Count", 1)
71
+ else:
72
+ simplified_col = col # 兜底
73
+ else:
74
+ # 其他类别(除平稳性和方差特性外)移除大类前缀
75
+ simplified_col = col.replace(p, "", 1)
76
+ metric_columns.append((col, simplified_col))
77
+ break # 避免重复处理
78
+
79
+ # 去重并保持顺序
80
+ seen = set()
81
+ unique_metrics = []
82
+ for col, simplified in metric_columns:
83
+ if col not in seen:
84
+ seen.add(col)
85
+ unique_metrics.append((col, simplified))
86
+
87
+ # 过滤存在的列
88
+ existing_columns = [col for col in columns + [col for col, _ in unique_metrics] if col in df.columns]
89
+
90
+ # 创建重命名字典
91
+ rename_dict = {col: simplified for col, simplified in unique_metrics if col in existing_columns}
92
+
93
+ return existing_columns, rename_dict
94
+
95
+
96
+ def refresh_leaderboard():
97
+ """刷新排行榜数据,添加详细日志和错误捕获"""
98
+ logger.info("开始刷新排行榜数据")
99
+ try:
100
+ if not os.path.exists(RESULTS_PATH):
101
+ error_msg = f"❌ 结果目录不存在: {RESULTS_PATH}"
102
+ logger.error(error_msg)
103
+ outputs = []
104
+ categories = get_metric_categories()
105
+ for _ in categories:
106
+ outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
107
+ outputs.append(gr.Markdown(value=error_msg, visible=True))
108
+ return outputs
109
+
110
+ if not os.path.isdir(RESULTS_PATH):
111
+ error_msg = f"❌ {RESULTS_PATH} 不是一个目录"
112
+ logger.error(error_msg)
113
+ outputs = []
114
+ categories = get_metric_categories()
115
+ for _ in categories:
116
+ outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
117
+ outputs.append(gr.Markdown(value=error_msg, visible=True))
118
+ return outputs
119
+
120
+ # 加载数据并打印日志
121
+ df = get_leaderboard_df(RESULTS_PATH)
122
+ logger.info(f"成功加载数据,共 {len(df)} 条记录")
123
+
124
+ categories = get_metric_categories()
125
+ outputs = []
126
+
127
+ for category in categories:
128
+ if df.empty:
129
+ outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
130
+ else:
131
+ category_cols, rename_dict = get_category_columns(df, category)
132
+ logger.info(f"类别 {category['name']} 的列: {category_cols}")
133
+
134
+ display_df = df[category_cols].copy()
135
+ display_df = display_df.rename(columns=rename_dict)
136
+
137
+ if 'model_name' in display_df.columns:
138
+ display_df['model_name'] = display_df['model_name'].str.slice(0, 25) + \
139
+ (display_df['model_name'].str.len() > 25).map({True: '...', False: ''})
140
+
141
+ outputs.append(gr.Dataframe(value=display_df, visible=True))
142
+
143
+ if df.empty:
144
+ model_folders = [f for f in os.listdir(RESULTS_PATH) if os.path.isdir(os.path.join(RESULTS_PATH, f))]
145
+ error_msg = "⚠️ 找到模型文件夹,但无法加载数据" if model_folders else f"⚠️ 未在 {RESULTS_PATH} 中找到模型"
146
+ logger.warning(error_msg)
147
+ outputs.append(gr.Markdown(value=error_msg, visible=True))
148
+ else:
149
+ outputs.append(gr.Markdown(value="", visible=False))
150
+
151
+ logger.info("刷新排行榜完成")
152
+ return outputs
153
+
154
+ except Exception as e:
155
+ error_msg = f"刷新数据失败: {str(e)}\n{traceback.format_exc()}"
156
+ logger.error(error_msg)
157
+ # 返回错误状态
158
+ categories = get_metric_categories()
159
+ outputs = [gr.Dataframe(value=pd.DataFrame(), visible=True) for _ in categories]
160
+ outputs.append(gr.Markdown(value=f" 刷新失败: {str(e)}", visible=True))
161
+ return outputs
162
+
163
+
164
+ def apply_filters(model_type, strategies, filter_mode):
165
+ """应用筛选条件,添加详细日志和错误捕获"""
166
+ logger.info(f"开始应用筛选: 模型类型={model_type}, 策略={strategies}, 模式={filter_mode}")
167
+ try:
168
+ filtered_df = get_filtered_leaderboard(
169
+ RESULTS_PATH,
170
+ model_type=model_type,
171
+ strategies=strategies,
172
+ filter_mode=filter_mode
173
+ )
174
+ logger.info(f"筛选完成,得到 {len(filtered_df)} 条记录")
175
+
176
+ categories = get_metric_categories()
177
+ outputs = []
178
+
179
+ for category in categories:
180
+ if filtered_df.empty:
181
+ outputs.append(gr.Dataframe(value=pd.DataFrame(), visible=True))
182
+ else:
183
+ category_cols, rename_dict = get_category_columns(filtered_df, category)
184
+ logger.info(f"筛选后类别 {category['name']} 的列: {category_cols}")
185
+
186
+ display_df = filtered_df[category_cols].copy()
187
+ display_df = display_df.rename(columns=rename_dict)
188
+
189
+ if 'model_name' in display_df.columns:
190
+ display_df['model_name'] = display_df['model_name'].str.slice(0, 25) + \
191
+ (display_df['model_name'].str.len() > 25).map({True: '...', False: ''})
192
+
193
+ outputs.append(gr.Dataframe(value=display_df, visible=True))
194
+
195
+ empty_msg = "⚠️ 没有找到符合筛选条件的模型。" if filtered_df.empty else ""
196
+ outputs.append(gr.Markdown(value=empty_msg, visible=filtered_df.empty))
197
+ logger.info("筛选应用完成")
198
+ return outputs
199
+
200
+ except Exception as e:
201
+ error_msg = f"筛选失败: {str(e)}\n{traceback.format_exc()}"
202
+ logger.error(error_msg)
203
+ # 返回错误状态
204
+ categories = get_metric_categories()
205
+ outputs = [gr.Dataframe(value=pd.DataFrame(), visible=True) for _ in categories]
206
+ outputs.append(gr.Markdown(value=f"❌ 筛选失败: {str(e)}", visible=True))
207
+ return outputs
208
+
209
+
210
+
211
+ def create_interface():
212
+ """创建Gradio界面,单表格固定model_name列(兼容旧版本Gradio)"""
213
+ try:
214
+ model_type_choices = get_model_type_choices()
215
+ except Exception as e:
216
+ model_type_choices = ["All"]
217
+ print(f"获取模型类型选项时出错: {str(e)}")
218
+
219
+ try:
220
+ strategy_choices = get_strategy_choices(RESULTS_PATH)
221
+ except Exception as e:
222
+ strategy_choices = []
223
+ print(f"获取策略选项时出错: {str(e)}")
224
+
225
+ categories = get_metric_categories()
226
+
227
+ with gr.Blocks(title="Aries 模型评估排行榜") as demo:
228
+ # 添加CSS确保model_name列固定
229
+ gr.HTML("""
230
+ <style>
231
+ /* 表格容器基础设置 */
232
+ .fixed-column-table {
233
+ overflow: visible !important; /* 原先是auto,改为visible禁用滚动条 */
234
+ position: relative !important;
235
+ max-height: 90vh !important;
236
+ height: auto !important;
237
+ }
238
+
239
+ /* 单元格内边距优化 */
240
+ .fixed-column-table td,
241
+ .fixed-column-table th {
242
+ padding: 0.2rem 0.3rem !important;
243
+ }
244
+
245
+ /* 基础模式(浅色)样式 */
246
+ .fixed-column-table table th:first-child,
247
+ .fixed-column-table table td:first-child {
248
+ position: sticky !important;
249
+ left: 0 !important;
250
+ z-index: 2 !important;
251
+ background-color: white !important;
252
+ color: #333 !important; /* 文本色 */
253
+ min-width: 150px !important;
254
+ max-width: 150px !important;
255
+ font-weight: bold !important;
256
+ box-shadow: 1px 0 2px rgba(0,0,0,0.1) !important;
257
+ }
258
+
259
+ .fixed-column-table table thead th {
260
+ position: sticky !important;
261
+ top: 0 !important;
262
+ z-index: 1 !important;
263
+ background-color: white !important;
264
+ color: #333 !important; /* 文本色 */
265
+ }
266
+
267
+ .fixed-column-table table thead th:first-child {
268
+ z-index: 3 !important;
269
+ }
270
+
271
+ /* 第二列宽度设置 */
272
+ .fixed-column-table table th:nth-child(2),
273
+ .fixed-column-table table td:nth-child(2) {
274
+ min-width: 215px !important;
275
+ max-width: 215px !important;
276
+ white-space: nowrap !important;
277
+ overflow: hidden !important;
278
+ text-overflow: ellipsis !important;
279
+ }
280
+
281
+ /* 禁用内部滚动 */
282
+ .fixed-column-table .dataframe-container {
283
+ overflow: visible !important;
284
+ }
285
+
286
+ /* 深色模式适配 */
287
+ @media (prefers-color-scheme: dark) {
288
+ .fixed-column-table table th:first-child,
289
+ .fixed-column-table table td:first-child {
290
+ background-color: #333 !important;
291
+ color: #fff !important;
292
+ box-shadow: 1px 0 2px rgba(0,0,0,0.3) !important;
293
+ }
294
+
295
+ .fixed-column-table table thead th {
296
+ background-color: #333 !important;
297
+ color: #fff !important;
298
+ }
299
+ }
300
+ </style>
301
+ """)
302
+
303
+ gr.Markdown(f"# {lang.get('title')}")
304
+ # 添加语言切换按钮
305
+ with gr.Row():
306
+ lang_btn = gr.Button(f"切换至英文" if lang.current_lang == "zh" else f"Switch to Chinese")
307
+
308
+ with gr.Tabs():
309
+ with gr.Tab(lang.get("model_leaderboard")):
310
+ with gr.Row():
311
+ with gr.Column(scale=1):
312
+ gr.Markdown(f"### {lang.get('filter_conditions')}")
313
+
314
+ model_type = gr.Dropdown(
315
+ choices=model_type_choices,
316
+ label=lang.get("model_type"),
317
+ value="All"
318
+ )
319
+
320
+ strategies = gr.CheckboxGroup(
321
+ choices=strategy_choices,
322
+ label=lang.get("strategies"),
323
+ value=[]
324
+ )
325
+
326
+ filter_mode = gr.Radio(
327
+ choices=[lang.get("intersection"), lang.get("union")],
328
+ label=lang.get("filter_mode"),
329
+ value=lang.get("intersection")
330
+ )
331
+
332
+ with gr.Row():
333
+ refresh_btn = gr.Button(lang.get("refresh"))
334
+ apply_btn = gr.Button(lang.get("apply_filters")) # 这个是正确的按钮变量名
335
+
336
+ with gr.Column(scale=3):
337
+ empty_state = gr.Markdown(visible=False) # 对应错误信息显示组件
338
+
339
+ with gr.Tabs() as category_tabs:
340
+ category_dataframes = [] # 保存所有数据表格组件
341
+ for category in categories:
342
+ with gr.Tab(category["name"]):
343
+ df_component = gr.Dataframe(
344
+ interactive=False,
345
+ wrap=True,
346
+ label=category["description"],
347
+ elem_classes="fixed-column-table"
348
+ )
349
+ category_dataframes.append(df_component)
350
+
351
+ with gr.Tab("关于"):
352
+ gr.Markdown("""
353
+ ## 关于 Aries 模型评估排行榜
354
+ 该排行榜展示了各种模型在标准基准测试中的表现,包含所有评估指标。
355
+ """)
356
+
357
+ # 设置事件处理 - 修正为正确的apply_btn
358
+ apply_btn.click( # 这里之前错写为filter_btn
359
+ fn=apply_filters,
360
+ inputs=[model_type, strategies, filter_mode],
361
+ outputs=category_dataframes + [empty_state]
362
+ )
363
+
364
+ refresh_btn.click(
365
+ fn=refresh_leaderboard,
366
+ outputs=category_dataframes + [empty_state]
367
+ )
368
+
369
+ demo.load(
370
+ fn=refresh_leaderboard,
371
+ outputs=category_dataframes + [empty_state]
372
+ )
373
+
374
+ def toggle_language():
375
+ new_lang = lang.switch_language()
376
+ btn_text = "切换至英文" if new_lang == "en" else "Switch to Chinese"
377
+ # 刷新界面 - 使用正确的组件列表
378
+ return [btn_text] + refresh_leaderboard()
379
+
380
+ lang_btn.click(
381
+ fn=toggle_language,
382
+ inputs=[],
383
+ outputs=[lang_btn] + category_dataframes + [empty_state] # 确保变量名一致
384
+ )
385
+
386
+ return demo
387
+
388
+
389
+ if __name__ == "__main__":
390
+ print(f"正在启动Aries模型评估排行榜,结果目录: {RESULTS_PATH}")
391
+ demo = create_interface()
392
+ demo.launch()
393
+
394
+
src/__pycache__/about.cpython-39.pyc CHANGED
Binary files a/src/__pycache__/about.cpython-39.pyc and b/src/__pycache__/about.cpython-39.pyc differ
 
src/__pycache__/language.cpython-39.pyc ADDED
Binary file (4.05 kB). View file
 
src/__pycache__/populate.cpython-39.pyc CHANGED
Binary files a/src/__pycache__/populate.cpython-39.pyc and b/src/__pycache__/populate.cpython-39.pyc differ
 
src/display/__pycache__/filters.cpython-39.pyc CHANGED
Binary files a/src/display/__pycache__/filters.cpython-39.pyc and b/src/display/__pycache__/filters.cpython-39.pyc differ
 
src/display/__pycache__/utils.cpython-39.pyc CHANGED
Binary files a/src/display/__pycache__/utils.cpython-39.pyc and b/src/display/__pycache__/utils.cpython-39.pyc differ
 
src/display/filters.py CHANGED
@@ -1,70 +1,70 @@
1
- from src.display.utils import ModelType
2
- from src.leaderboard.read_evals import get_all_strategies
3
-
4
- def get_model_type_choices():
5
- """获取模型类型筛选选项,与ModelType枚举兼容"""
6
- # 生成带符号的模型类型选项
7
- type_choices = [mt.to_str() for mt in ModelType if mt != ModelType.Unknown]
8
- # 在开头添加"All"选项
9
- return ["All"] + type_choices
10
-
11
- def get_strategy_choices(results_path):
12
- """获取策略筛选选项"""
13
- return get_all_strategies(results_path)
14
-
15
- def get_metric_categories():
16
- """
17
- 获取指标类别分组,按照要求调整:
18
- - 平稳性和非平稳性合并为一类
19
- - 同方差和异方差合并为一类
20
- - 季节特性拆分为季节强度和季节数
21
- """
22
- return [
23
- {
24
- "name": "常规指标",
25
- "prefix": "Regular_",
26
- "description": "基础评估指标,适用于所有类型的数据"
27
- },
28
- {
29
- "name": "平稳性/非平稳性",
30
- "prefix": ["Stationary_", "Non_Stationary_"],
31
- "description": "模型在平稳和非平稳序列上的表现"
32
- },
33
- {
34
- "name": "趋势强度",
35
- "prefix": "Trend_Strength_",
36
- "description": "模型在不同趋势强度数据上的表现"
37
- },
38
- # 拆分原"季节特性"为两个独立分组
39
- {
40
- "name": "季节强度",
41
- "prefix": "Seasonality_Strength_",
42
- "description": "模型在不同季节强度数据上的表现"
43
- },
44
- {
45
- "name": "季节数",
46
- "prefix": "Seasonality_Count_",
47
- "description": "模型在不同季节计数(周期数量)数据上的表现"
48
- },
49
- {
50
- "name": "波动性",
51
- "prefix": "Volatility_",
52
- "description": "模型在不同波动性特征数据上的表现"
53
- },
54
- {
55
- "name": "记忆性",
56
- "prefix": "Memory_",
57
- "description": "模型在不同记忆性特征数据上的表现"
58
- },
59
- {
60
- "name": "方差特性",
61
- "prefix": ["Homo-Scedasticity_", "Hetero-Scedasticity_"],
62
- "description": "模型在同方差和异方差数据上的表现"
63
- },
64
- {
65
- "name": "异常值",
66
- "prefix": "Anomaly_",
67
- "description": "模型在包含不同比例异常值数据上的表现"
68
- }
69
- ]
70
-
 
1
+ from src.display.utils import ModelType
2
+ from src.leaderboard.read_evals import get_all_strategies
3
+ from src.language import lang
4
+
5
+ def get_model_type_choices():
6
+ """获取模型类型筛选选项,与ModelType枚举兼容"""
7
+ # 生成带符号的模型类型选项
8
+ type_choices = [mt.to_str() for mt in ModelType if mt != ModelType.Unknown]
9
+ # 在开头添加"All"选项
10
+ return ["All"] + type_choices
11
+
12
+ def get_strategy_choices(results_path):
13
+ """获取策略筛选选项"""
14
+ return get_all_strategies(results_path)
15
+
16
+ def get_metric_categories():
17
+ """
18
+ 获取指标类别分组,按照要求调整:
19
+ - 平稳性和非平稳性合并为一类
20
+ - 同方差和异方差合并为一类
21
+ - 季节特性拆分为季节强度和季节数
22
+ """
23
+ return [
24
+ {
25
+ "name": lang.get("regular_metrics"),
26
+ "prefix": "Regular_",
27
+ "description": lang.get("regular_desc")
28
+ },
29
+ {
30
+ "name": lang.get("stationarity"),
31
+ "prefix": ["Stationary_", "Non_Stationary_"],
32
+ "description": lang.get("stationarity_desc")
33
+ },
34
+ {
35
+ "name": lang.get("trend_strength"),
36
+ "prefix": "Trend_Strength_",
37
+ "description": lang.get("trend_strength_desc")
38
+ },
39
+ {
40
+ "name": lang.get("seasonality_strength"),
41
+ "prefix": "Seasonality_Strength_",
42
+ "description": lang.get("seasonality_strength_desc")
43
+ },
44
+ {
45
+ "name": lang.get("seasonality_count"),
46
+ "prefix": "Seasonality_Count_",
47
+ "description": lang.get("seasonality_count_desc")
48
+ },
49
+ {
50
+ "name": lang.get("volatility"),
51
+ "prefix": "Volatility_",
52
+ "description": lang.get("volatility_desc")
53
+ },
54
+ {
55
+ "name": lang.get("memory"),
56
+ "prefix": "Memory_",
57
+ "description": lang.get("memory_desc")
58
+ },
59
+ {
60
+ "name": lang.get("variance_characteristics"),
61
+ "prefix": ["Homo-Scedasticity_", "Hetero-Scedasticity_"],
62
+ "description": lang.get("variance_characteristics_desc")
63
+ },
64
+ {
65
+ "name": lang.get("outliers"),
66
+ "prefix": "Anomaly_",
67
+ "description": lang.get("outliers_desc")
68
+ }
69
+ ]
70
+
src/language.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # src/language.py
2
+ class LanguageManager:
3
+ def __init__(self):
4
+ self.current_lang = "en" # 默认中文
5
+ self.translations = {
6
+ "zh": {
7
+ # app.py 中的文本
8
+ "title": "🚀 Aries 模型评估排行榜",
9
+ "model_leaderboard": "模型排行榜",
10
+ "filter_conditions": "筛选条件",
11
+ "model_type": "模型类型",
12
+ "strategies": "策略",
13
+ "filter_mode": "筛选模式",
14
+ "refresh": "刷新",
15
+ "apply_filters": "应用筛选",
16
+ "all": "All", # 保持英文
17
+ "intersection": "交集 (满足所有选中策略)",
18
+ "union": "并集 (满足任一选中策略)",
19
+ "no_results": "⚠️ 没有找到符合筛选条件的模型。",
20
+ "results_dir_not_exist": "❌ 结果目录不存在: {path}",
21
+ "not_a_directory": "❌ {path} 不是一个目录",
22
+ "no_model_data": "⚠️ 找到模型文件夹,但无法加载数据",
23
+ "no_model_folders": "⚠️ 未在 {path} 中找到模型",
24
+
25
+ # 指标类别 - src/display/filters.py
26
+ "regular_metrics": "常规指标",
27
+ "stationarity": "平稳性/非平稳性",
28
+ "trend_strength": "趋势强度",
29
+ "seasonality_strength": "季节强度",
30
+ "seasonality_count": "季节数",
31
+ "volatility": "波动性",
32
+ "memory": "记忆性",
33
+ "variance_characteristics": "方差特性",
34
+ "outliers": "异常值",
35
+
36
+ # 指标描述
37
+ "regular_desc": "基础评估指标,适用于所有类型的数据",
38
+ "stationarity_desc": "模型在平稳和非平稳序列上的表现",
39
+ "trend_strength_desc": "模型在不同趋势强度数据上的表现",
40
+ "seasonality_strength_desc": "模型在不同季节强度数据上的表现",
41
+ "seasonality_count_desc": "模型在不同季节计数(周期数量)数据上的表现",
42
+ "volatility_desc": "模型在不同波动性特征数据上的表现",
43
+ "memory_desc": "模型在不同记忆性特征数据上的表现",
44
+ "variance_characteristics_desc": "模型在同方差和异方差数据上的表现",
45
+ "outliers_desc": "模型在包含不同比例异常值数据上的表现"
46
+ },
47
+ "en": {
48
+ # app.py 中的文本
49
+ "title": "🚀 Aries Model Evaluation Leaderboard",
50
+ "model_leaderboard": "Model Leaderboard",
51
+ "filter_conditions": "Filter Conditions",
52
+ "model_type": "Model Type",
53
+ "strategies": "Strategies",
54
+ "filter_mode": "Filter Mode",
55
+ "refresh": "Refresh",
56
+ "apply_filters": "Apply Filters",
57
+ "all": "All",
58
+ "intersection": "Intersection (meet all selected strategies)",
59
+ "union": "Union (meet any selected strategy)",
60
+ "no_results": "⚠️ No models found matching the filter criteria.",
61
+ "results_dir_not_exist": "❌ Results directory does not exist: {path}",
62
+ "not_a_directory": "❌ {path} is not a directory",
63
+ "no_model_data": "⚠️ Model folders found, but unable to load data",
64
+ "no_model_folders": "⚠️ No models found in {path}",
65
+
66
+ # 指标类别
67
+ "regular_metrics": "Regular Metrics",
68
+ "stationarity": "Stationarity/Non-stationarity",
69
+ "trend_strength": "Trend Strength",
70
+ "seasonality_strength": "Seasonality Strength",
71
+ "seasonality_count": "Seasonality Count",
72
+ "volatility": "Volatility",
73
+ "memory": "Memory",
74
+ "variance_characteristics": "Variance Characteristics",
75
+ "outliers": "Anomalies",
76
+
77
+ # 指标描述
78
+ "regular_desc": "Basic evaluation metrics applicable to all data types",
79
+ "stationarity_desc": "Model performance on stationary and non-stationary sequences",
80
+ "trend_strength_desc": "Model performance on data with different trend strengths",
81
+ "seasonality_strength_desc": "Model performance on data with different seasonality strengths",
82
+ "seasonality_count_desc": "Model performance on data with different seasonality counts (number of cycles)",
83
+ "volatility_desc": "Model performance on data with different volatility characteristics",
84
+ "memory_desc": "Model performance on data with different memory characteristics",
85
+ "variance_characteristics_desc": "Model performance on homoscedastic and heteroscedastic data",
86
+ "outliers_desc": "Model performance on data containing different proportions of outliers"
87
+ }
88
+ }
89
+
90
+ def switch_language(self):
91
+ """切换语言"""
92
+ self.current_lang = "en" if self.current_lang == "zh" else "zh"
93
+ return self.current_lang
94
+
95
+ def get(self, key, **kwargs):
96
+ """获取翻译文本,支持格式化参数"""
97
+ text = self.translations[self.current_lang].get(key, key)
98
+ if kwargs:
99
+ return text.format(**kwargs)
100
+ return text
101
+
102
+
103
+ # 创建全局实例
104
+ lang = LanguageManager()
src/leaderboard/__pycache__/read_evals.cpython-39.pyc CHANGED
Binary files a/src/leaderboard/__pycache__/read_evals.cpython-39.pyc and b/src/leaderboard/__pycache__/read_evals.cpython-39.pyc differ