Minor changes of filter_model logic
Browse files
app.py
CHANGED
@@ -134,23 +134,48 @@ def filter_queries(query: str, filtered_df: pd.DataFrame) -> pd.DataFrame:
|
|
134 |
def filter_models(
|
135 |
df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, show_deleted: bool
|
136 |
) -> pd.DataFrame:
|
|
|
|
|
137 |
# Show all models
|
138 |
if show_deleted:
|
139 |
filtered_df = df
|
140 |
-
else:
|
141 |
filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
|
142 |
|
143 |
-
|
144 |
-
filtered_df = filtered_df.loc[df[AutoEvalColumn.model_type_symbol.name].isin(type_emoji)]
|
145 |
-
filtered_df = filtered_df.loc[df[AutoEvalColumn.precision.name].isin(precision_query + ["None"])]
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
return filtered_df
|
153 |
|
|
|
|
|
154 |
def uncheck_all():
|
155 |
return [], [], [], [], [], [], [], [], [], []
|
156 |
|
@@ -262,32 +287,33 @@ with demo:
|
|
262 |
)
|
263 |
with gr.Row():
|
264 |
deleted_models_visibility = gr.Checkbox(
|
265 |
-
value=
|
266 |
)
|
267 |
with gr.Column(min_width=320):
|
268 |
#with gr.Box(elem_id="box-filter"):
|
269 |
filter_columns_type = gr.CheckboxGroup(
|
270 |
label="Model types",
|
271 |
-
choices=[t.to_str() for t in ModelType],
|
272 |
-
value=[
|
273 |
interactive=True,
|
274 |
elem_id="filter-columns-type",
|
275 |
)
|
276 |
filter_columns_precision = gr.CheckboxGroup(
|
277 |
label="Precision",
|
278 |
-
choices=[i.value.name for i in Precision],
|
279 |
-
value=[
|
280 |
interactive=True,
|
281 |
elem_id="filter-columns-precision",
|
282 |
)
|
283 |
filter_columns_size = gr.CheckboxGroup(
|
284 |
label="Model sizes (in billions of parameters)",
|
285 |
-
choices=list(NUMERIC_INTERVALS.keys()),
|
286 |
-
value=
|
287 |
interactive=True,
|
288 |
elem_id="filter-columns-size",
|
289 |
)
|
290 |
|
|
|
291 |
leaderboard_table = gr.Dataframe(
|
292 |
value=leaderboard_df[
|
293 |
[c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|
|
|
134 |
def filter_models(
|
135 |
df: pd.DataFrame, type_query: list, size_query: list, precision_query: list, show_deleted: bool
|
136 |
) -> pd.DataFrame:
|
137 |
+
print("Initial number of models:", len(df))
|
138 |
+
|
139 |
# Show all models
|
140 |
if show_deleted:
|
141 |
filtered_df = df
|
142 |
+
else:
|
143 |
filtered_df = df[df[AutoEvalColumn.still_on_hub.name] == True]
|
144 |
|
145 |
+
print("After hub filter:", len(filtered_df))
|
|
|
|
|
146 |
|
147 |
+
if "All" not in type_query:
|
148 |
+
if "?" in type_query:
|
149 |
+
filtered_df = filtered_df.loc[~df[AutoEvalColumn.model_type_symbol.name].isin([t for t in ModelType if t != "?"])]
|
150 |
+
else:
|
151 |
+
type_emoji = [t[0] for t in type_query]
|
152 |
+
filtered_df = filtered_df.loc[df[AutoEvalColumn.model_type_symbol.name].isin(type_emoji)]
|
153 |
+
|
154 |
+
print("After type filter:", len(filtered_df))
|
155 |
+
|
156 |
+
if "All" not in precision_query:
|
157 |
+
if "?" in precision_query:
|
158 |
+
filtered_df = filtered_df.loc[df[AutoEvalColumn.precision.name].isna()]
|
159 |
+
else:
|
160 |
+
filtered_df = filtered_df.loc[df[AutoEvalColumn.precision.name].isin(precision_query + ["None"])]
|
161 |
+
|
162 |
+
print("After precision filter:", len(filtered_df))
|
163 |
+
|
164 |
+
if "All" not in size_query:
|
165 |
+
if "?" in size_query:
|
166 |
+
filtered_df = filtered_df.loc[df[AutoEvalColumn.params.name].isna()]
|
167 |
+
else:
|
168 |
+
numeric_interval = pd.IntervalIndex(sorted([NUMERIC_INTERVALS[s] for s in size_query]))
|
169 |
+
params_column = pd.to_numeric(df[AutoEvalColumn.params.name], errors="coerce")
|
170 |
+
mask = params_column.apply(lambda x: any(numeric_interval.contains(x)))
|
171 |
+
filtered_df = filtered_df.loc[mask]
|
172 |
+
|
173 |
+
print("After size filter:", len(filtered_df))
|
174 |
|
175 |
return filtered_df
|
176 |
|
177 |
+
|
178 |
+
|
179 |
def uncheck_all():
|
180 |
return [], [], [], [], [], [], [], [], [], []
|
181 |
|
|
|
287 |
)
|
288 |
with gr.Row():
|
289 |
deleted_models_visibility = gr.Checkbox(
|
290 |
+
value=True, label="Show gated/private/deleted models", interactive=True
|
291 |
)
|
292 |
with gr.Column(min_width=320):
|
293 |
#with gr.Box(elem_id="box-filter"):
|
294 |
filter_columns_type = gr.CheckboxGroup(
|
295 |
label="Model types",
|
296 |
+
choices=["All"] + [t.to_str() for t in ModelType],
|
297 |
+
value=["All"],
|
298 |
interactive=True,
|
299 |
elem_id="filter-columns-type",
|
300 |
)
|
301 |
filter_columns_precision = gr.CheckboxGroup(
|
302 |
label="Precision",
|
303 |
+
choices=["All"] + [i.value.name for i in Precision],
|
304 |
+
value=["All"],
|
305 |
interactive=True,
|
306 |
elem_id="filter-columns-precision",
|
307 |
)
|
308 |
filter_columns_size = gr.CheckboxGroup(
|
309 |
label="Model sizes (in billions of parameters)",
|
310 |
+
choices=["All"] + list(NUMERIC_INTERVALS.keys()) + ["?"],
|
311 |
+
value=["All"],
|
312 |
interactive=True,
|
313 |
elem_id="filter-columns-size",
|
314 |
)
|
315 |
|
316 |
+
|
317 |
leaderboard_table = gr.Dataframe(
|
318 |
value=leaderboard_df[
|
319 |
[c.name for c in fields(AutoEvalColumn) if c.never_hidden]
|