Deeplink to autoselect a model when opening the leaderboard

#462
by Wauplin HF staff - opened
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -86,6 +86,11 @@ def update_table(
86
  return df
87
 
88
 
 
 
 
 
 
89
  def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
90
  return df[(df[AutoEvalColumn.dummy.name].str.contains(query, case=False))]
91
 
@@ -236,6 +241,25 @@ with demo:
236
  ],
237
  leaderboard_table,
238
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  for selector in [shown_columns, filter_columns_type, filter_columns_precision, filter_columns_size, deleted_models_visibility]:
240
  selector.change(
241
  update_table,
 
86
  return df
87
 
88
 
89
+ def load_query(request: gr.Request): # triggered only once at startup => read query parameter if it exists
90
+ query = request.query_params.get("query") or ""
91
+ return query, query # return one for the "search_bar", one for a hidden component that triggers a reload only if value has changed
92
+
93
+
94
  def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
95
  return df[(df[AutoEvalColumn.dummy.name].str.contains(query, case=False))]
96
 
 
241
  ],
242
  leaderboard_table,
243
  )
244
+
245
+ # Define a hidden component that will trigger a reload only if a query parameter has be set
246
+ hidden_search_bar = gr.Textbox(value="", visible=False)
247
+ hidden_search_bar.change(
248
+ update_table,
249
+ [
250
+ hidden_leaderboard_table_for_search,
251
+ shown_columns,
252
+ filter_columns_type,
253
+ filter_columns_precision,
254
+ filter_columns_size,
255
+ deleted_models_visibility,
256
+ search_bar,
257
+ ],
258
+ leaderboard_table,
259
+ )
260
+ # Check query parameter once at startup and update search bar + hidden component
261
+ demo.load(load_query, inputs=[], outputs=[search_bar, hidden_search_bar])
262
+
263
  for selector in [shown_columns, filter_columns_type, filter_columns_precision, filter_columns_size, deleted_models_visibility]:
264
  selector.change(
265
  update_table,