gremlin97 commited on
Commit
beff22b
·
1 Parent(s): 8b08b97

Simplify filters to separate dataset and metric checkboxes

Browse files
Files changed (1) hide show
  1. app.py +39 -54
app.py CHANGED
@@ -139,30 +139,23 @@ def build_tab(df, name):
139
  elem_classes="filter-group"
140
  )
141
 
142
- # Add metric filters
143
- gr.Markdown("**Filter by Metrics**")
144
- metric_filters = {}
145
- for metric in metric_cols:
146
- # Get all numeric values for this metric across all dataset columns
147
- metric_values = []
148
- for col in metric_combo_cols:
149
- if f"({metric})" in col:
150
- values = pd.to_numeric(pivoted_df[col], errors='coerce').dropna()
151
- metric_values.extend(values.tolist())
152
-
153
- if metric_values:
154
- min_val = min(metric_values)
155
- max_val = max(metric_values)
156
- metric_filters[metric] = gr.Slider(
157
- minimum=min_val,
158
- maximum=max_val,
159
- value=min_val,
160
- step=(max_val - min_val) / 100,
161
- label=f"Min {metric}",
162
- elem_classes="metric-filter"
163
- )
164
-
165
- def update(search, md, org, cols, *metric_values):
166
  filtered = pivoted_df.copy()
167
 
168
  if search:
@@ -174,33 +167,33 @@ def build_tab(df, name):
174
  if org:
175
  filtered = filtered[filtered["Organization"].isin(org)]
176
 
177
- # Apply metric filters
178
- metric_names = list(metric_filters.keys())
179
- for i, metric_name in enumerate(metric_names):
180
- min_threshold = metric_values[i]
181
- # Filter rows where at least one column with this metric meets the threshold
182
- metric_columns = [col for col in metric_combo_cols if f"({metric_name})" in col and col in filtered.columns]
183
- if metric_columns:
184
- mask = filtered[metric_columns].apply(
185
- lambda row: any(pd.to_numeric(val, errors='coerce') >= min_threshold if pd.notna(val) and val != "-" else False for val in row),
186
- axis=1
187
- )
188
- filtered = filtered[mask]
189
-
190
  if cols:
191
- display_cols = [col for col in cols if col in filtered.columns]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  filtered = filtered[display_cols]
193
 
194
  return filtered
195
 
196
- inputs = [search_bar, model_filter, org_filter, col_selector] + list(metric_filters.values())
197
-
198
- search_bar.change(update, inputs, table)
199
- model_filter.change(update, inputs, table)
200
- org_filter.change(update, inputs, table)
201
- col_selector.change(update, inputs, table)
202
- for metric_filter in metric_filters.values():
203
- metric_filter.change(update, inputs, table)
204
 
205
 
206
  custom_css = """
@@ -283,14 +276,6 @@ custom_css = """
283
  font-size: 14px;
284
  }
285
 
286
- .metric-filter {
287
- margin-bottom: 1em;
288
- }
289
-
290
- .metric-filter label {
291
- font-size: 14px;
292
- }
293
-
294
  .column-select {
295
  margin-bottom: 1.5em;
296
  }
 
139
  elem_classes="filter-group"
140
  )
141
 
142
+ gr.Markdown("**Datasets**")
143
+ dataset_filter = gr.CheckboxGroup(
144
+ choices=datasets,
145
+ value=datasets,
146
+ label="",
147
+ elem_classes="filter-group"
148
+ )
149
+
150
+ gr.Markdown("**Metrics**")
151
+ metric_filter = gr.CheckboxGroup(
152
+ choices=metric_cols,
153
+ value=metric_cols,
154
+ label="",
155
+ elem_classes="filter-group"
156
+ )
157
+
158
+ def update(search, md, org, dset, metrics, cols):
 
 
 
 
 
 
 
159
  filtered = pivoted_df.copy()
160
 
161
  if search:
 
167
  if org:
168
  filtered = filtered[filtered["Organization"].isin(org)]
169
 
170
+ # Filter by dataset and metric - hide columns that don't match
 
 
 
 
 
 
 
 
 
 
 
 
171
  if cols:
172
+ display_cols = []
173
+ # Always include base columns
174
+ for col in ["Model", "Organization", "First Author"]:
175
+ if col in cols and col in filtered.columns:
176
+ display_cols.append(col)
177
+
178
+ # Add metric columns that match selected datasets and metrics
179
+ for col in cols:
180
+ if col in metric_combo_cols:
181
+ # Check if this column matches selected datasets and metrics
182
+ col_dataset = col.split(" (")[0]
183
+ col_metric = col.split(" (")[1].rstrip(")")
184
+ if col_dataset in dset and col_metric in metrics:
185
+ display_cols.append(col)
186
+
187
  filtered = filtered[display_cols]
188
 
189
  return filtered
190
 
191
+ search_bar.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
192
+ model_filter.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
193
+ org_filter.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
194
+ dataset_filter.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
195
+ metric_filter.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
196
+ col_selector.change(update, [search_bar, model_filter, org_filter, dataset_filter, metric_filter, col_selector], table)
 
 
197
 
198
 
199
  custom_css = """
 
276
  font-size: 14px;
277
  }
278
 
 
 
 
 
 
 
 
 
279
  .column-select {
280
  margin-bottom: 1.5em;
281
  }