hysts HF staff commited on
Commit
285f1d2
·
1 Parent(s): 0f09631

Apply black to app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -28
app.py CHANGED
@@ -41,14 +41,24 @@ def restart_space():
41
  try:
42
  print(EVAL_REQUESTS_PATH)
43
  snapshot_download(
44
- repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
 
 
 
 
 
45
  )
46
  except Exception:
47
  restart_space()
48
  try:
49
  print(EVAL_RESULTS_PATH)
50
  snapshot_download(
51
- repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
 
 
 
 
 
52
  )
53
  except Exception:
54
  restart_space()
@@ -78,16 +88,30 @@ def update_table(
78
  show_flagged: bool,
79
  query: str,
80
  ):
81
- print(f"Update table called with: type_query={type_query}, precision_query={precision_query}, size_query={size_query}")
 
 
82
  print(f"hidden_df shape before filtering: {hidden_df.shape}")
83
 
84
- filtered_df = filter_models(hidden_df, type_query, size_query, precision_query, add_special_tokens_query, num_few_shots_query, show_deleted, show_merges, show_flagged)
 
 
 
 
 
 
 
 
 
 
85
  print(f"filtered_df shape after filter_models: {filtered_df.shape}")
86
 
87
  filtered_df = filter_queries(query, filtered_df)
88
  print(f"filtered_df shape after filter_queries: {filtered_df.shape}")
89
 
90
- print(f"Filter applied: query={query}, columns={columns}, type_query={type_query}, precision_query={precision_query}")
 
 
91
  print("Filtered dataframe head:")
92
  print(filtered_df.head())
93
 
@@ -100,7 +124,10 @@ def update_table(
100
 
101
  def load_query(request: gr.Request): # triggered only once at startup => read query parameter if it exists
102
  query = request.query_params.get("query") or ""
103
- return query, query # return one for the "search_bar", one for a hidden component that triggers a reload only if value has changed
 
 
 
104
 
105
 
106
  def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
@@ -118,10 +145,11 @@ def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
118
  # ]
119
  # return filtered_df
120
 
 
121
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
122
  always_here_cols = [
123
  AutoEvalColumn.model_type_symbol.name, # 'T'
124
- AutoEvalColumn.model.name, # 'Model'
125
  ]
126
 
127
  # 'always_here_cols' を 'columns' から除外して重複を避ける
@@ -137,8 +165,14 @@ def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
137
  seen.add(c)
138
 
139
  # 'Model' カラムにリンクを含む形式で再構築
140
- if 'Model' in df.columns:
141
- df['Model'] = df['Model'].apply(lambda x: f'[{x.split(">")[-2].split("<")[0]}]({x.split("href=")[1].split(chr(34))[1]})' if isinstance(x, str) and 'href=' in x else x)
 
 
 
 
 
 
142
 
143
  # フィルタリングされたカラムでデータフレームを作成
144
  filtered_df = df[unique_columns]
@@ -166,7 +200,15 @@ def filter_queries(query: str, filtered_df: pd.DataFrame):
166
 
167
 
168
  def filter_models(
169
- df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, add_special_tokens_query: list, num_few_shots_query: list, show_deleted: bool, show_merges: bool, show_flagged: bool
 
 
 
 
 
 
 
 
170
  ) -> pd.DataFrame:
171
  print(f"Initial df shape: {df.shape}")
172
  print(f"Initial df content:\n{df}")
@@ -174,34 +216,38 @@ def filter_models(
174
  filtered_df = df
175
 
176
  # Model Type フィルタリング
177
- type_column = 'T' if 'T' in df.columns else 'Type_'
178
  type_emoji = [t.split()[0] for t in type_query]
179
  filtered_df = df[df[type_column].isin(type_emoji)]
180
  print(f"After type filter: {filtered_df.shape}")
181
 
182
  # Precision フィルタリング
183
- filtered_df = filtered_df[filtered_df['Precision'].isin(precision_query + ['Unknown', '?'])]
184
  print(f"After precision filter: {filtered_df.shape}")
185
 
186
  # Model Size フィルタリング
187
- if 'Unknown' in size_query:
188
- size_mask = filtered_df['#Params (B)'].isna() | (filtered_df['#Params (B)'] == 0)
189
  else:
190
- size_mask = filtered_df['#Params (B)'].apply(lambda x: any(x in NUMERIC_INTERVALS[s] for s in size_query if s != 'Unknown'))
 
 
191
  filtered_df = filtered_df[size_mask]
192
  print(f"After size filter: {filtered_df.shape}")
193
 
194
  # Add Special Tokens フィルタリング
195
- filtered_df = filtered_df[filtered_df['Add Special Tokens'].isin(add_special_tokens_query + ['Unknown', '?'])]
196
  print(f"After add_special_tokens filter: {filtered_df.shape}")
197
 
198
  # Num Few Shots フィルタリング
199
- filtered_df = filtered_df[filtered_df['Few-shot'].astype(str).isin([str(x) for x in num_few_shots_query] + ['Unknown', '?'])]
 
 
200
  print(f"After num_few_shots filter: {filtered_df.shape}")
201
 
202
  # Show deleted models フィルタリング
203
  if not show_deleted:
204
- filtered_df = filtered_df[filtered_df['Available on the hub'] == True]
205
  print(f"After show_deleted filter: {filtered_df.shape}")
206
 
207
  print("Filtered dataframe head:")
@@ -211,9 +257,29 @@ def filter_models(
211
 
212
  # Prepare leaderboard dataframes
213
 
214
- leaderboard_df = filter_models(leaderboard_df, [t.to_str(" : ") for t in ModelType], list(NUMERIC_INTERVALS.keys()), [i.value.name for i in Precision], [i.value.name for i in AddSpecialTokens], [i.value.name for i in NumFewShots], False, False, False)
 
 
 
 
 
 
 
 
 
 
215
 
216
- leaderboard_df_filtered = filter_models(leaderboard_df, [t.to_str(" : ") for t in ModelType], list(NUMERIC_INTERVALS.keys()), [i.value.name for i in Precision], [i.value.name for i in AddSpecialTokens], [i.value.name for i in NumFewShots], False, False, False)
 
 
 
 
 
 
 
 
 
 
217
  # initial_columns = [c.name for c in fields(AutoEvalColumn) if c.never_hidden or c.displayed_by_default]
218
  # leaderboard_df_filtered = select_columns(leaderboard_df_filtered, initial_columns)
219
 
@@ -227,17 +293,23 @@ leaderboard_df_filtered = filter_models(leaderboard_df, [t.to_str(" : ") for t i
227
  # )
228
 
229
  # DataFrameの初期化部分のみを修正
230
- initial_columns = ['T'] + [c.name for c in fields(AutoEvalColumn) if (c.never_hidden or c.displayed_by_default) and c.name != 'T']
 
 
231
  leaderboard_df_filtered = select_columns(leaderboard_df, initial_columns)
232
 
233
  # Model列のリンク形式を修正
234
- leaderboard_df_filtered['Model'] = leaderboard_df_filtered['Model'].apply(
235
- lambda x: f'[{x.split(">")[-2].split("<")[0]}]({x.split("href=")[1].split(chr(34))[1]})' if isinstance(x, str) and 'href=' in x else x
 
 
 
 
236
  )
237
 
238
  # 数値データを文字列に変換
239
  for col in leaderboard_df_filtered.columns:
240
- if col not in ['T', 'Model']:
241
  leaderboard_df_filtered[col] = leaderboard_df_filtered[col].astype(str)
242
 
243
  # Leaderboard demo
@@ -252,9 +324,7 @@ with gr.Blocks() as demo_leaderboard:
252
  )
253
  shown_columns = gr.CheckboxGroup(
254
  choices=[
255
- c.name
256
- for c in fields(AutoEvalColumn)
257
- if not c.hidden and not c.never_hidden# and not c.dummy
258
  ],
259
  value=[
260
  c.name
@@ -468,7 +538,7 @@ with gr.Blocks() as demo_submission:
468
  add_special_tokens,
469
  ],
470
  submission_result,
471
- )
472
 
473
  # Main demo
474
 
 
41
  try:
42
  print(EVAL_REQUESTS_PATH)
43
  snapshot_download(
44
+ repo_id=QUEUE_REPO,
45
+ local_dir=EVAL_REQUESTS_PATH,
46
+ repo_type="dataset",
47
+ tqdm_class=None,
48
+ etag_timeout=30,
49
+ token=TOKEN,
50
  )
51
  except Exception:
52
  restart_space()
53
  try:
54
  print(EVAL_RESULTS_PATH)
55
  snapshot_download(
56
+ repo_id=RESULTS_REPO,
57
+ local_dir=EVAL_RESULTS_PATH,
58
+ repo_type="dataset",
59
+ tqdm_class=None,
60
+ etag_timeout=30,
61
+ token=TOKEN,
62
  )
63
  except Exception:
64
  restart_space()
 
88
  show_flagged: bool,
89
  query: str,
90
  ):
91
+ print(
92
+ f"Update table called with: type_query={type_query}, precision_query={precision_query}, size_query={size_query}"
93
+ )
94
  print(f"hidden_df shape before filtering: {hidden_df.shape}")
95
 
96
+ filtered_df = filter_models(
97
+ hidden_df,
98
+ type_query,
99
+ size_query,
100
+ precision_query,
101
+ add_special_tokens_query,
102
+ num_few_shots_query,
103
+ show_deleted,
104
+ show_merges,
105
+ show_flagged,
106
+ )
107
  print(f"filtered_df shape after filter_models: {filtered_df.shape}")
108
 
109
  filtered_df = filter_queries(query, filtered_df)
110
  print(f"filtered_df shape after filter_queries: {filtered_df.shape}")
111
 
112
+ print(
113
+ f"Filter applied: query={query}, columns={columns}, type_query={type_query}, precision_query={precision_query}"
114
+ )
115
  print("Filtered dataframe head:")
116
  print(filtered_df.head())
117
 
 
124
 
125
  def load_query(request: gr.Request): # triggered only once at startup => read query parameter if it exists
126
  query = request.query_params.get("query") or ""
127
+ return (
128
+ query,
129
+ query,
130
+ ) # return one for the "search_bar", one for a hidden component that triggers a reload only if value has changed
131
 
132
 
133
  def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
 
145
  # ]
146
  # return filtered_df
147
 
148
+
149
  def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
150
  always_here_cols = [
151
  AutoEvalColumn.model_type_symbol.name, # 'T'
152
+ AutoEvalColumn.model.name, # 'Model'
153
  ]
154
 
155
  # 'always_here_cols' を 'columns' から除外して重複を避ける
 
165
  seen.add(c)
166
 
167
  # 'Model' カラムにリンクを含む形式で再構築
168
+ if "Model" in df.columns:
169
+ df["Model"] = df["Model"].apply(
170
+ lambda x: (
171
+ f'[{x.split(">")[-2].split("<")[0]}]({x.split("href=")[1].split(chr(34))[1]})'
172
+ if isinstance(x, str) and "href=" in x
173
+ else x
174
+ )
175
+ )
176
 
177
  # フィルタリングされたカラムでデータフレームを作成
178
  filtered_df = df[unique_columns]
 
200
 
201
 
202
  def filter_models(
203
+ df: pd.DataFrame,
204
+ type_query: list,
205
+ size_query: list,
206
+ precision_query: list,
207
+ add_special_tokens_query: list,
208
+ num_few_shots_query: list,
209
+ show_deleted: bool,
210
+ show_merges: bool,
211
+ show_flagged: bool,
212
  ) -> pd.DataFrame:
213
  print(f"Initial df shape: {df.shape}")
214
  print(f"Initial df content:\n{df}")
 
216
  filtered_df = df
217
 
218
  # Model Type フィルタリング
219
+ type_column = "T" if "T" in df.columns else "Type_"
220
  type_emoji = [t.split()[0] for t in type_query]
221
  filtered_df = df[df[type_column].isin(type_emoji)]
222
  print(f"After type filter: {filtered_df.shape}")
223
 
224
  # Precision フィルタリング
225
+ filtered_df = filtered_df[filtered_df["Precision"].isin(precision_query + ["Unknown", "?"])]
226
  print(f"After precision filter: {filtered_df.shape}")
227
 
228
  # Model Size フィルタリング
229
+ if "Unknown" in size_query:
230
+ size_mask = filtered_df["#Params (B)"].isna() | (filtered_df["#Params (B)"] == 0)
231
  else:
232
+ size_mask = filtered_df["#Params (B)"].apply(
233
+ lambda x: any(x in NUMERIC_INTERVALS[s] for s in size_query if s != "Unknown")
234
+ )
235
  filtered_df = filtered_df[size_mask]
236
  print(f"After size filter: {filtered_df.shape}")
237
 
238
  # Add Special Tokens フィルタリング
239
+ filtered_df = filtered_df[filtered_df["Add Special Tokens"].isin(add_special_tokens_query + ["Unknown", "?"])]
240
  print(f"After add_special_tokens filter: {filtered_df.shape}")
241
 
242
  # Num Few Shots フィルタリング
243
+ filtered_df = filtered_df[
244
+ filtered_df["Few-shot"].astype(str).isin([str(x) for x in num_few_shots_query] + ["Unknown", "?"])
245
+ ]
246
  print(f"After num_few_shots filter: {filtered_df.shape}")
247
 
248
  # Show deleted models フィルタリング
249
  if not show_deleted:
250
+ filtered_df = filtered_df[filtered_df["Available on the hub"] == True]
251
  print(f"After show_deleted filter: {filtered_df.shape}")
252
 
253
  print("Filtered dataframe head:")
 
257
 
258
  # Prepare leaderboard dataframes
259
 
260
+ leaderboard_df = filter_models(
261
+ leaderboard_df,
262
+ [t.to_str(" : ") for t in ModelType],
263
+ list(NUMERIC_INTERVALS.keys()),
264
+ [i.value.name for i in Precision],
265
+ [i.value.name for i in AddSpecialTokens],
266
+ [i.value.name for i in NumFewShots],
267
+ False,
268
+ False,
269
+ False,
270
+ )
271
 
272
+ leaderboard_df_filtered = filter_models(
273
+ leaderboard_df,
274
+ [t.to_str(" : ") for t in ModelType],
275
+ list(NUMERIC_INTERVALS.keys()),
276
+ [i.value.name for i in Precision],
277
+ [i.value.name for i in AddSpecialTokens],
278
+ [i.value.name for i in NumFewShots],
279
+ False,
280
+ False,
281
+ False,
282
+ )
283
  # initial_columns = [c.name for c in fields(AutoEvalColumn) if c.never_hidden or c.displayed_by_default]
284
  # leaderboard_df_filtered = select_columns(leaderboard_df_filtered, initial_columns)
285
 
 
293
  # )
294
 
295
  # DataFrameの初期化部分のみを修正
296
+ initial_columns = ["T"] + [
297
+ c.name for c in fields(AutoEvalColumn) if (c.never_hidden or c.displayed_by_default) and c.name != "T"
298
+ ]
299
  leaderboard_df_filtered = select_columns(leaderboard_df, initial_columns)
300
 
301
  # Model列のリンク形式を修正
302
+ leaderboard_df_filtered["Model"] = leaderboard_df_filtered["Model"].apply(
303
+ lambda x: (
304
+ f'[{x.split(">")[-2].split("<")[0]}]({x.split("href=")[1].split(chr(34))[1]})'
305
+ if isinstance(x, str) and "href=" in x
306
+ else x
307
+ )
308
  )
309
 
310
  # 数値データを文字列に変換
311
  for col in leaderboard_df_filtered.columns:
312
+ if col not in ["T", "Model"]:
313
  leaderboard_df_filtered[col] = leaderboard_df_filtered[col].astype(str)
314
 
315
  # Leaderboard demo
 
324
  )
325
  shown_columns = gr.CheckboxGroup(
326
  choices=[
327
+ c.name for c in fields(AutoEvalColumn) if not c.hidden and not c.never_hidden # and not c.dummy
 
 
328
  ],
329
  value=[
330
  c.name
 
538
  add_special_tokens,
539
  ],
540
  submission_result,
541
+ )
542
 
543
  # Main demo
544