Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -85,22 +85,11 @@ def update_table(
|
|
85 |
df = select_columns(filtered_df, columns)
|
86 |
return df
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
size_query: list,
|
94 |
-
show_deleted: bool,
|
95 |
-
request: gr.Request,
|
96 |
-
):
|
97 |
-
query_from_params = request.query_params.get("query") or ""
|
98 |
-
return (
|
99 |
-
# Update search bar
|
100 |
-
query_from_params,
|
101 |
-
# Update dataframe
|
102 |
-
update_table(hidden_df, columns, type_query, precision_query, size_query, show_deleted, query_from_params),
|
103 |
-
)
|
104 |
|
105 |
def search_table(df: pd.DataFrame, query: str) -> pd.DataFrame:
|
106 |
return df[(df[AutoEvalColumn.dummy.name].str.contains(query, case=False))]
|
@@ -218,12 +207,13 @@ with demo:
|
|
218 |
elem_id="filter-columns-size",
|
219 |
)
|
220 |
|
|
|
|
|
|
|
|
|
|
|
221 |
leaderboard_table = gr.components.Dataframe(
|
222 |
-
value=
|
223 |
-
[c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|
224 |
-
+ shown_columns.value
|
225 |
-
+ [AutoEvalColumn.dummy.name]
|
226 |
-
],
|
227 |
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
|
228 |
datatype=TYPES,
|
229 |
elem_id="leaderboard-table",
|
@@ -252,18 +242,25 @@ with demo:
|
|
252 |
],
|
253 |
leaderboard_table,
|
254 |
)
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
258 |
hidden_leaderboard_table_for_search,
|
259 |
shown_columns,
|
260 |
filter_columns_type,
|
261 |
filter_columns_precision,
|
262 |
filter_columns_size,
|
263 |
deleted_models_visibility,
|
|
|
264 |
],
|
265 |
-
|
266 |
)
|
|
|
|
|
|
|
267 |
for selector in [shown_columns, filter_columns_type, filter_columns_precision, filter_columns_size, deleted_models_visibility]:
|
268 |
selector.change(
|
269 |
update_table,
|
|
|
85 |
df = select_columns(filtered_df, columns)
|
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))]
|
|
|
207 |
elem_id="filter-columns-size",
|
208 |
)
|
209 |
|
210 |
+
default_leaderboard_df = value=leaderboard_df[
|
211 |
+
[c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|
212 |
+
+ shown_columns.value
|
213 |
+
+ [AutoEvalColumn.dummy.name]
|
214 |
+
]
|
215 |
leaderboard_table = gr.components.Dataframe(
|
216 |
+
value=default_leaderboard_df,
|
|
|
|
|
|
|
|
|
217 |
headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
|
218 |
datatype=TYPES,
|
219 |
elem_id="leaderboard-table",
|
|
|
242 |
],
|
243 |
leaderboard_table,
|
244 |
)
|
245 |
+
|
246 |
+
# Define a hidden component that will trigger a reload only if a query parameter has be set
|
247 |
+
hidden_search_bar = gr.Textbox(value="", visible=False)
|
248 |
+
hidden.change(
|
249 |
+
update_table,
|
250 |
+
[
|
251 |
hidden_leaderboard_table_for_search,
|
252 |
shown_columns,
|
253 |
filter_columns_type,
|
254 |
filter_columns_precision,
|
255 |
filter_columns_size,
|
256 |
deleted_models_visibility,
|
257 |
+
search_bar,
|
258 |
],
|
259 |
+
leaderboard_table,
|
260 |
)
|
261 |
+
# Check query parameter once at startup and update search bar + hidden component
|
262 |
+
demo.load(load_query, inputs=[], outputs=[search_bar, hidden_search_bar])
|
263 |
+
|
264 |
for selector in [shown_columns, filter_columns_type, filter_columns_precision, filter_columns_size, deleted_models_visibility]:
|
265 |
selector.change(
|
266 |
update_table,
|