jasonshaoshun commited on
Commit
c7c77b6
·
1 Parent(s): 29eaa40
Files changed (1) hide show
  1. app.py +66 -4
app.py CHANGED
@@ -51,7 +51,7 @@ import pandas as pd
51
  from typing import List, Dict, Union, Optional, Any
52
  from dataclasses import fields
53
 
54
- class SmartSelectColumns(SelectColumns):
55
  """
56
  Enhanced SelectColumns component with basic filtering functionality.
57
  """
@@ -128,7 +128,67 @@ class SmartSelectColumns(SelectColumns):
128
 
129
  return super().update(value)
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
 
134
 
@@ -409,14 +469,15 @@ def init_leaderboard_mib_subgraph(dataframe, track):
409
  benchmark_keywords = ["ioi", "mcqa", "arithmetic", "arc"]
410
  model_keywords = ["qwen2_5", "gpt2", "gemma2", "llama3"]
411
 
412
- # Create SmartSelectColumns with minimal configuration
413
  smart_columns = SmartSelectColumns(
414
  benchmark_keywords=benchmark_keywords,
415
  model_keywords=model_keywords,
416
- initial_selected=["Method", "Average"]
 
417
  )
418
 
419
- # Create and return the leaderboard
420
  print("\nCreating leaderboard...")
421
  leaderboard = Leaderboard(
422
  value=dataframe,
@@ -427,6 +488,7 @@ def init_leaderboard_mib_subgraph(dataframe, track):
427
  interactive=False
428
  )
429
  print("Leaderboard created successfully")
 
430
  return leaderboard
431
 
432
 
 
51
  from typing import List, Dict, Union, Optional, Any
52
  from dataclasses import fields
53
 
54
+ # class SmartSelectColumns(SelectColumns):
55
  """
56
  Enhanced SelectColumns component with basic filtering functionality.
57
  """
 
128
 
129
  return super().update(value)
130
 
131
+ class SmartSelectColumns(SelectColumns):
132
+ """
133
+ Enhanced SelectColumns component with minimal modifications from original.
134
+ """
135
+ def __init__(
136
+ self,
137
+ benchmark_keywords: Optional[List[str]] = None,
138
+ model_keywords: Optional[List[str]] = None,
139
+ initial_selected: Optional[List[str]] = None,
140
+ label: str = "Select Results:",
141
+ **kwargs
142
+ ):
143
+ """
144
+ Initialize SmartSelectColumns.
145
+ """
146
+ super().__init__(label=label, **kwargs)
147
+ self.benchmark_keywords = benchmark_keywords or []
148
+ self.model_keywords = model_keywords or []
149
+ self.initial_selected = initial_selected or []
150
+
151
+ def get_filtered_groups(self, columns: List[str]) -> Dict[str, List[str]]:
152
+ """Get column groups based on keywords."""
153
+ filtered_groups = {}
154
+
155
+ # Add benchmark groups
156
+ for benchmark in self.benchmark_keywords:
157
+ matching_cols = [
158
+ col for col in columns
159
+ if benchmark in col.lower()
160
+ ]
161
+ if matching_cols:
162
+ filtered_groups[f"Benchmark group for {benchmark}"] = matching_cols
163
+
164
+ # Add model groups
165
+ for model in self.model_keywords:
166
+ matching_cols = [
167
+ col for col in columns
168
+ if model in col.lower()
169
+ ]
170
+ if matching_cols:
171
+ filtered_groups[f"Model group for {model}"] = matching_cols
172
+
173
+ return filtered_groups
174
 
175
+ def update(
176
+ self,
177
+ value: Union[pd.DataFrame, Dict[str, List[str]], Any]
178
+ ) -> Dict:
179
+ """Update component, staying close to original SelectColumns behavior."""
180
+ if isinstance(value, pd.DataFrame):
181
+ columns = list(value.columns)
182
+ filtered_cols = self.get_filtered_groups(columns)
183
+
184
+ return {
185
+ "choices": columns,
186
+ "value": self.initial_selected or columns,
187
+ "filtered_cols": filtered_cols,
188
+ "__type__": "update"
189
+ }
190
+
191
+ return super().update(value)
192
 
193
 
194
 
 
469
  benchmark_keywords = ["ioi", "mcqa", "arithmetic", "arc"]
470
  model_keywords = ["qwen2_5", "gpt2", "gemma2", "llama3"]
471
 
472
+ # Create SmartSelectColumns instance
473
  smart_columns = SmartSelectColumns(
474
  benchmark_keywords=benchmark_keywords,
475
  model_keywords=model_keywords,
476
+ initial_selected=["Method", "Average"],
477
+ label="Select Results:" # Match original label
478
  )
479
 
480
+ # Create Leaderboard
481
  print("\nCreating leaderboard...")
482
  leaderboard = Leaderboard(
483
  value=dataframe,
 
488
  interactive=False
489
  )
490
  print("Leaderboard created successfully")
491
+ print("Leaderboard is", leaderboard)
492
  return leaderboard
493
 
494