sh1gechan commited on
Commit
da97add
·
verified ·
1 Parent(s): 4ff08a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -13
app.py CHANGED
@@ -118,15 +118,22 @@ def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
118
 
119
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
120
  always_here_cols = [
121
- AutoEvalColumn.model_type_symbol.name,
122
- AutoEvalColumn.model.name,
123
  ]
124
- # always_here_cols が既に columns に含まれている場合は除外
125
  columns = [c for c in columns if c not in always_here_cols]
126
- # COLS の順序を維持しつつ、重複を避けてカラムを選択
127
- filtered_df = df[
128
- always_here_cols + [c for c in COLS if c in df.columns and c in columns]
129
- ]
 
 
 
 
 
 
 
130
  return filtered_df
131
 
132
  def filter_queries(query: str, filtered_df: pd.DataFrame):
@@ -288,19 +295,30 @@ with demo:
288
  initial_columns = [c.name for c in fields(AutoEvalColumn) if c.never_hidden or c.displayed_by_default]
289
  leaderboard_df_filtered = select_columns(leaderboard_df, initial_columns)
290
 
291
- print("Columns in leaderboard_df_filtered:", leaderboard_df_filtered.columns)
292
- # データ型を定義するための辞書
 
 
 
 
 
 
 
 
 
293
  datatype_dict = {}
294
  for col in leaderboard_df_filtered.columns:
295
- if col == 'Model':
296
  datatype_dict[col] = "markdown"
297
  elif col in TYPES:
298
  datatype_dict[col] = TYPES[col]
299
  else:
300
- datatype_dict[col] = "str"
301
-
 
 
302
 
303
- # leaderboard_tableの初期化
304
  leaderboard_table = gr.components.Dataframe(
305
  value=leaderboard_df_filtered.to_dict('records'),
306
  headers=list(leaderboard_df_filtered.columns),
 
118
 
119
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
120
  always_here_cols = [
121
+ AutoEvalColumn.model_type_symbol.name, # 'T'
122
+ AutoEvalColumn.model.name, # 'Model'
123
  ]
124
+ # 'always_here_cols' 'columns' から除外して重複を避ける
125
  columns = [c for c in columns if c not in always_here_cols]
126
+ # 'always_here_cols' を先頭に追加し、その他のカラムを COLS の順序で追加
127
+ new_columns = always_here_cols + [c for c in COLS if c in df.columns and c in columns]
128
+ # 重複を排除しつつ順序を維持
129
+ seen = set()
130
+ unique_columns = []
131
+ for c in new_columns:
132
+ if c not in seen:
133
+ unique_columns.append(c)
134
+ seen.add(c)
135
+ # フィルタリングされたカラムでデータフレームを作成
136
+ filtered_df = df[unique_columns]
137
  return filtered_df
138
 
139
  def filter_queries(query: str, filtered_df: pd.DataFrame):
 
295
  initial_columns = [c.name for c in fields(AutoEvalColumn) if c.never_hidden or c.displayed_by_default]
296
  leaderboard_df_filtered = select_columns(leaderboard_df, initial_columns)
297
 
298
+ # 重複カラムの確認と削除
299
+ duplicate_columns = leaderboard_df_filtered.columns[leaderboard_df_filtered.columns.duplicated()]
300
+ if len(duplicate_columns) > 0:
301
+ print(f"Duplicate columns found: {duplicate_columns.tolist()}")
302
+ # 重複カラムを削除(最初の出現を保持)
303
+ leaderboard_df_filtered = leaderboard_df_filtered.loc[:, ~leaderboard_df_filtered.columns.duplicated()]
304
+ print("Duplicate columns have been removed.")
305
+ else:
306
+ print("No duplicate columns found.")
307
+
308
+ # データ型を定義
309
  datatype_dict = {}
310
  for col in leaderboard_df_filtered.columns:
311
+ if col == AutoEvalColumn.model.name: # 'Model'
312
  datatype_dict[col] = "markdown"
313
  elif col in TYPES:
314
  datatype_dict[col] = TYPES[col]
315
  else:
316
+ datatype_dict[col] = "str" # デフォルトのデータ型
317
+
318
+ # デバッグ用出力
319
+ print("Datatype dictionary:", datatype_dict)
320
 
321
+ # Gradio Dataframe コンポーネントの初期化
322
  leaderboard_table = gr.components.Dataframe(
323
  value=leaderboard_df_filtered.to_dict('records'),
324
  headers=list(leaderboard_df_filtered.columns),