sanchit-gandhi HF staff commited on
Commit
2fc9c42
1 Parent(s): cd05b03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -107
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import pandas as pd
2
  import streamlit as st
3
  from huggingface_hub import HfApi
4
- from utils import ascending_metrics, metric_ranges
5
  import numpy as np
6
  from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
7
  from os.path import exists
@@ -155,114 +155,96 @@ dataset_df = dataset_df[dataset_df.split == split]
155
 
156
  dataset_df = dataset_df.dropna(axis="columns", how="all")
157
 
158
- selectable_datasets = [dataset]
159
  dataset = st.sidebar.selectbox(
160
  "Dataset",
161
- selectable_datasets,
162
  index=0,
163
  )
164
 
165
- if len(dataset_df) > 0:
166
- selectable_configs = list(set(dataset_df["config"]))
167
- selectable_configs.sort(key=lambda name: name.lower())
168
-
169
- selectable_configs.remove("-unspecified-")
170
-
171
- if dataset != "-any-":
172
- config = st.sidebar.selectbox(
173
- "Language",
174
- selectable_configs,
175
- index=0,
176
- help="Filter the results on the current leaderboard by language."
177
- )
178
- dataset_df = dataset_df[dataset_df.config == config]
179
-
180
- selectable_splits = [split]
181
- split = st.sidebar.selectbox(
182
- "Split",
183
- selectable_splits,
184
- index=0,
185
- )
186
-
187
- not_selectable_metrics = ["model_id", "dataset", "split", "config", "pipeline_tag", "only_verified"]
188
- # also ignore irrelevant ASR metrics
189
- not_selectable_metrics.extend(["wer_without_norm", "mer"])
190
-
191
- selectable_metrics = list(filter(lambda column: column not in not_selectable_metrics, dataset_df.columns))
192
-
193
- dataset_df = dataset_df.filter(["model_id"] + (["dataset"] if dataset == "-any-" else []) + selectable_metrics)
194
- dataset_df = dataset_df.dropna(thresh=2) # Want at least two non-na values (one for model_id and one for a metric).
195
-
196
- sorting_metric = st.sidebar.radio(
197
- "Sorting Metric",
198
- selectable_metrics,
199
- index=selectable_metrics.index(default_metric) if default_metric in selectable_metrics else 0,
200
- help="Select the metric to sort the leaderboard by. Click on the metric name in the leaderboard to reverse the sorting order."
201
- )
202
-
203
- current_query_params.update({"metric": [sorting_metric]})
204
-
205
- st.experimental_set_query_params(**current_query_params)
206
-
207
- st.markdown(
208
- "Please click on the model's name to be redirected to its model card."
209
- )
210
-
211
- st.markdown(
212
- "Want to beat the leaderboard? Don't see your model here? Simply ..."
213
- )
214
-
215
- # Make the default metric appear right after model names and dataset names
216
- cols = dataset_df.columns.tolist()
217
- cols.remove(sorting_metric)
218
- sorting_metric_index = 1 if dataset != "-any-" else 2
219
- cols = cols[:sorting_metric_index] + [sorting_metric] + cols[sorting_metric_index:]
220
- dataset_df = dataset_df[cols]
221
-
222
- # Sort the leaderboard, giving the sorting metric highest priority and then ordering by other metrics in the case of equal values.
223
- dataset_df = dataset_df.sort_values(by=cols[sorting_metric_index:], ascending=[metric in ascending_metrics for metric in cols[sorting_metric_index:]])
224
- dataset_df = dataset_df.replace(np.nan, '-')
225
-
226
- # If dataset is "-any-", only show the best model for a random sample of 100 datasets.
227
- # Otherwise The leaderboard is way too long and doesn't give the users a feel for all of
228
- # the datasets available for a task.
229
- if dataset == "-any-":
230
- filtered_dataset_df_dict = {column: [] for column in dataset_df.columns}
231
- seen_datasets = set()
232
- for _, row in dataset_df.iterrows():
233
- if row["dataset"] not in seen_datasets:
234
- for column in dataset_df.columns:
235
- filtered_dataset_df_dict[column].append(row[column])
236
- seen_datasets.add(row["dataset"])
237
- dataset_df = pd.DataFrame(filtered_dataset_df_dict)
238
- dataset_df = dataset_df.sample(min(100, len(dataset_df)))
239
-
240
- # Make the leaderboard
241
- gb = GridOptionsBuilder.from_dataframe(dataset_df)
242
- gb.configure_default_column(sortable=False)
243
- gb.configure_column(
244
- "model_id",
245
- cellRenderer=JsCode('''function(params) {return '<a target="_blank" href="https://huggingface.co/'+params.value+'">'+params.value+'</a>'}'''),
246
- )
247
- if dataset == "-any-":
248
- gb.configure_column(
249
- "dataset",
250
- cellRenderer=JsCode('''function(params) {return '<a target="_blank" href="https://huggingface.co/spaces/autoevaluate/leaderboards?dataset='+params.value+'">'+params.value+'</a>'}'''),
251
- )
252
- for name in selectable_metrics:
253
- gb.configure_column(name, type=["numericColumn","numberColumnFilter","customNumericFormat"], precision=4, aggFunc='sum')
254
-
255
- gb.configure_column(
256
- sorting_metric,
257
- sortable=True,
258
- cellStyle=JsCode('''function(params) { return {'backgroundColor': '#FFD21E'}}''')
259
- )
260
-
261
- go = gb.build()
262
- fit_columns = len(dataset_df.columns) < 10
263
- AgGrid(dataset_df, gridOptions=go, height=28*len(dataset_df) + (35 if fit_columns else 41), allow_unsafe_jscode=True, fit_columns_on_grid_load=fit_columns, enable_enterprise_modules=False)
264
-
265
- else:
266
- st.markdown(
267
- "No " + ("verified" if only_verified_results else "unverified") + " results to display. Try toggling the verified results filter."
268
- )
 
1
  import pandas as pd
2
  import streamlit as st
3
  from huggingface_hub import HfApi
4
+ from utils import ascending_metrics, metric_ranges, LANGUAGES
5
  import numpy as np
6
  from st_aggrid import AgGrid, GridOptionsBuilder, JsCode
7
  from os.path import exists
 
155
 
156
  dataset_df = dataset_df.dropna(axis="columns", how="all")
157
 
 
158
  dataset = st.sidebar.selectbox(
159
  "Dataset",
160
+ [dataset],
161
  index=0,
162
  )
163
 
164
+ selectable_configs = list(set(dataset_df["config"]))
165
+ selectable_configs.sort(key=lambda name: name.lower())
166
+ selectable_configs.remove("-unspecified-")
167
+ selectable_configs = [config for config in selectable_configs if config in LANGUAGES]
168
+
169
+ visual_configs = [f"{config}: {LANGUAGES[config]}" for config in selectable_configs]
170
+
171
+ config = st.sidebar.selectbox(
172
+ "Language",
173
+ visual_configs,
174
+ index=0,
175
+ help="Filter the results on the current leaderboard by language."
176
+ )
177
+
178
+ config = config.split(":")[0]
179
+
180
+ dataset_df = dataset_df[dataset_df.config == config]
181
+
182
+ split = st.sidebar.selectbox(
183
+ "Split",
184
+ [split],
185
+ index=0,
186
+ )
187
+
188
+ not_selectable_metrics = ["model_id", "dataset", "split", "config", "pipeline_tag", "only_verified"]
189
+ # also ignore irrelevant ASR metrics
190
+ not_selectable_metrics.extend(["wer_without_norm", "mer"])
191
+
192
+ selectable_metrics = list(filter(lambda column: column not in not_selectable_metrics, dataset_df.columns))
193
+
194
+ dataset_df = dataset_df.filter(["model_id"] + (["dataset"] if dataset == "-any-" else []) + selectable_metrics)
195
+ dataset_df = dataset_df.dropna(thresh=2) # Want at least two non-na values (one for model_id and one for a metric).
196
+
197
+ sorting_metric = st.sidebar.radio(
198
+ "Sorting Metric",
199
+ selectable_metrics,
200
+ index=selectable_metrics.index(default_metric) if default_metric in selectable_metrics else 0,
201
+ help="Select the metric to sort the leaderboard by. Click on the metric name in the leaderboard to reverse the sorting order."
202
+ )
203
+
204
+ current_query_params.update({"metric": [sorting_metric]})
205
+
206
+ st.experimental_set_query_params(**current_query_params)
207
+
208
+ st.markdown(
209
+ f"This is the leaderboard for {LANGUAGES[config]} ({config})."
210
+ )
211
+
212
+ st.markdown(
213
+ "Please click on the model's name to be redirected to its model card."
214
+ )
215
+
216
+ st.markdown(
217
+ "Want to beat the leaderboard? Don't see your model here? Simply ..."
218
+ )
219
+
220
+ # Make the default metric appear right after model names and dataset names
221
+ cols = dataset_df.columns.tolist()
222
+ cols.remove(sorting_metric)
223
+ sorting_metric_index = 1 if dataset != "-any-" else 2
224
+ cols = cols[:sorting_metric_index] + [sorting_metric] + cols[sorting_metric_index:]
225
+ dataset_df = dataset_df[cols]
226
+
227
+ # Sort the leaderboard, giving the sorting metric highest priority and then ordering by other metrics in the case of equal values.
228
+ dataset_df = dataset_df.sort_values(by=cols[sorting_metric_index:], ascending=[metric in ascending_metrics for metric in cols[sorting_metric_index:]])
229
+ dataset_df = dataset_df.replace(np.nan, '-')
230
+
231
+ # Make the leaderboard
232
+ gb = GridOptionsBuilder.from_dataframe(dataset_df)
233
+ gb.configure_default_column(sortable=False)
234
+ gb.configure_column(
235
+ "model_id",
236
+ cellRenderer=JsCode('''function(params) {return '<a target="_blank" href="https://huggingface.co/'+params.value+'">'+params.value+'</a>'}'''),
237
+ )
238
+
239
+ for name in selectable_metrics:
240
+ gb.configure_column(name, type=["numericColumn","numberColumnFilter","customNumericFormat"], precision=4, aggFunc='sum')
241
+
242
+ gb.configure_column(
243
+ sorting_metric,
244
+ sortable=True,
245
+ cellStyle=JsCode('''function(params) { return {'backgroundColor': '#FFD21E'}}''')
246
+ )
247
+
248
+ go = gb.build()
249
+ fit_columns = len(dataset_df.columns) < 10
250
+ AgGrid(dataset_df, gridOptions=go, height=28*len(dataset_df) + (35 if fit_columns else 41), allow_unsafe_jscode=True, fit_columns_on_grid_load=fit_columns, enable_enterprise_modules=False)