sh1gechan commited on
Commit
c141727
·
verified ·
1 Parent(s): a616b6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -54
app.py CHANGED
@@ -136,8 +136,7 @@ def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
136
 
137
  # 'Model' カラムにリンクを含む形式で再構築
138
  if 'Model' in df.columns:
139
- df['Model'] = df['Model'].apply(lambda x: f'<a href="{x.split("href=")[1].split(" ")[0].strip()}">{x.split(">")[1].split("</a")[0]}</a>' if isinstance(x, str) and '<a' in x else x)
140
-
141
  # フィルタリングされたカラムでデータフレームを作成
142
  filtered_df = df[unique_columns]
143
  return filtered_df
@@ -318,15 +317,6 @@ with demo:
318
  print("Duplicate columns have been removed.")
319
  else:
320
  print("No duplicate columns found.")
321
-
322
- # 'T' カラムの欠損値を確認
323
- missing_T = leaderboard_df_filtered['T'].isna().sum()
324
- print(f"Number of rows with missing 'T': {missing_T}")
325
-
326
- # 'T' カラムが欠損している場合、埋める(ここでは空文字)
327
- if missing_T > 0:
328
- print("Filling missing 'T' values with empty strings.")
329
- leaderboard_df_filtered['T'] = leaderboard_df_filtered['T'].fillna('')
330
 
331
  # データ型を定義
332
  datatype_dict = {}
@@ -337,47 +327,6 @@ with demo:
337
  datatype_dict[col] = TYPES[col]
338
  else:
339
  datatype_dict[col] = "str" # デフォルトのデータ型
340
-
341
- # 'T' カラムがすべてのレコードに存在するか確認
342
- records = leaderboard_df_filtered.to_dict('records')
343
- missing_T_in_records = [i for i, record in enumerate(records) if 'T' not in record]
344
- print(f"Number of records missing 'T' key: {len(missing_T_in_records)}")
345
-
346
- if len(missing_T_in_records) > 0:
347
- print("Records missing 'T' key:")
348
- for i in missing_T_in_records[:5]: # 最初の5件のみ表示
349
- print(f"Record {i}: {records[i]}")
350
- # 欠損している場合、'T' キーを追加して空文字で埋める
351
- for i in missing_T_in_records:
352
- records[i]['T'] = ''
353
- # データフレームを更新
354
- leaderboard_df_filtered = pd.DataFrame(records)
355
-
356
-
357
- leaderboard_df_filtered = leaderboard_df_filtered.rename(columns={'T': 'Type_'})
358
-
359
- # 'Type_' カラムのデータ型と内容を確認
360
- print(f"'Type_' カラムのデータ型: {leaderboard_df_filtered['Type_'].dtype}")
361
- print(f"'Type_' カラムのユニーク値: {leaderboard_df_filtered['Type_'].unique()}")
362
-
363
- # 'Type_' カラムを文字列型に変換
364
- leaderboard_df_filtered['Type_'] = leaderboard_df_filtered['Type_'].astype(str)
365
-
366
- # 'COLS' リストから 'T' と 'Model' を除外
367
- if 'T' in COLS:
368
- COLS.remove('T')
369
- if 'Model' in COLS:
370
- COLS.remove('Model')
371
-
372
- # 'datatype_dict' を再定義
373
- datatype_dict = {}
374
- for col in leaderboard_df_filtered.columns:
375
- if col == 'Model':
376
- datatype_dict[col] = "markdown"
377
- elif col in TYPES:
378
- datatype_dict[col] = TYPES[col]
379
- else:
380
- datatype_dict[col] = "str" # デフォルトのデータ型
381
 
382
  # 'Type_' が 'datatype_dict' に含まれているか確認
383
  if 'Type_' not in datatype_dict:
@@ -402,14 +351,13 @@ with demo:
402
  datatype[type_column] = "str"
403
 
404
  leaderboard_table = gr.components.Dataframe(
405
- value=leaderboard_df_filtered,
406
  headers=list(leaderboard_df_filtered.columns),
407
  datatype=datatype,
408
  elem_id="leaderboard-table",
409
  interactive=False,
410
  visible=True,
411
  )
412
-
413
 
414
  # Dummy leaderboard for handling the case when the user uses backspace key
415
  hidden_leaderboard_table_for_search = gr.components.Dataframe(
 
136
 
137
  # 'Model' カラムにリンクを含む形式で再構築
138
  if 'Model' in df.columns:
139
+ df['Model'] = df['Model'].apply(lambda x: f'[{x.split(">")[-2].split("<")[0]}]({x.split("href=")[1].split('"')[1]})' if isinstance(x, str) and 'href=' in x else x)
 
140
  # フィルタリングされたカラムでデータフレームを作成
141
  filtered_df = df[unique_columns]
142
  return filtered_df
 
317
  print("Duplicate columns have been removed.")
318
  else:
319
  print("No duplicate columns found.")
 
 
 
 
 
 
 
 
 
320
 
321
  # データ型を定義
322
  datatype_dict = {}
 
327
  datatype_dict[col] = TYPES[col]
328
  else:
329
  datatype_dict[col] = "str" # デフォルトのデータ型
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
  # 'Type_' が 'datatype_dict' に含まれているか確認
332
  if 'Type_' not in datatype_dict:
 
351
  datatype[type_column] = "str"
352
 
353
  leaderboard_table = gr.components.Dataframe(
354
+ value=leaderboard_df_filtered.to_dict('records'),
355
  headers=list(leaderboard_df_filtered.columns),
356
  datatype=datatype,
357
  elem_id="leaderboard-table",
358
  interactive=False,
359
  visible=True,
360
  )
 
361
 
362
  # Dummy leaderboard for handling the case when the user uses backspace key
363
  hidden_leaderboard_table_for_search = gr.components.Dataframe(