jasonshaoshun commited on
Commit
a3ba9e7
·
1 Parent(s): c7c77b6
Files changed (1) hide show
  1. app.py +71 -68
app.py CHANGED
@@ -52,81 +52,84 @@ 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
- """
58
- def __init__(
59
- self,
60
- benchmark_keywords: Optional[List[str]] = None,
61
- model_keywords: Optional[List[str]] = None,
62
- initial_selected: Optional[List[str]] = None,
63
- **kwargs
64
- ):
65
- """
66
- Initialize SmartSelectColumns with minimal configuration.
67
 
68
- Args:
69
- benchmark_keywords: List of benchmark names to filter by
70
- model_keywords: List of model names to filter by
71
- initial_selected: List of columns to show initially
72
- """
73
- super().__init__(**kwargs)
74
- self.benchmark_keywords = benchmark_keywords or []
75
- self.model_keywords = model_keywords or []
76
- self.initial_selected = initial_selected or []
77
-
78
- def get_filtered_groups(self, df: pd.DataFrame) -> Dict[str, List[str]]:
79
- """
80
- Create column groups based on simple substring matching.
81
- """
82
- filtered_groups = {}
83
 
84
- # Create benchmark groups
85
- for benchmark in self.benchmark_keywords:
86
- matching_cols = [
87
- col for col in df.columns
88
- if benchmark in col.lower()
89
- ]
90
- if matching_cols:
91
- group_name = f"Benchmark group for {benchmark}"
92
- filtered_groups[group_name] = matching_cols
93
 
94
- # Create model groups
95
- for model in self.model_keywords:
96
- matching_cols = [
97
- col for col in df.columns
98
- if model in col.lower()
99
- ]
100
- if matching_cols:
101
- group_name = f"Model group for {model}"
102
- filtered_groups[group_name] = matching_cols
103
 
104
- return filtered_groups
105
-
106
- def update(
107
- self,
108
- value: Union[pd.DataFrame, Dict[str, List[str]], Any]
109
- ) -> Dict:
110
- """Update component with new values."""
111
- if isinstance(value, pd.DataFrame):
112
- choices = list(value.columns)
113
- selected = self.initial_selected if self.initial_selected else choices
114
- filtered_cols = self.get_filtered_groups(value)
115
 
116
- return {
117
- "choices": choices,
118
- "value": selected,
119
- "filtered_cols": filtered_cols
120
- }
121
 
122
- if hasattr(value, '__dataclass_fields__'):
123
- field_names = [field.name for field in fields(value)]
124
- return {
125
- "choices": field_names,
126
- "value": self.initial_selected if self.initial_selected else field_names
127
- }
128
 
129
- return super().update(value)
 
 
 
130
 
131
  class SmartSelectColumns(SelectColumns):
132
  """
 
52
  from dataclasses import fields
53
 
54
  # class SmartSelectColumns(SelectColumns):
55
+ # """
56
+ # Enhanced SelectColumns component with basic filtering functionality.
57
+ # """
58
+ # def __init__(
59
+ # self,
60
+ # benchmark_keywords: Optional[List[str]] = None,
61
+ # model_keywords: Optional[List[str]] = None,
62
+ # initial_selected: Optional[List[str]] = None,
63
+ # **kwargs
64
+ # ):
65
+ # """
66
+ # Initialize SmartSelectColumns with minimal configuration.
67
 
68
+ # Args:
69
+ # benchmark_keywords: List of benchmark names to filter by
70
+ # model_keywords: List of model names to filter by
71
+ # initial_selected: List of columns to show initially
72
+ # """
73
+ # super().__init__(**kwargs)
74
+ # self.benchmark_keywords = benchmark_keywords or []
75
+ # self.model_keywords = model_keywords or []
76
+ # self.initial_selected = initial_selected or []
77
+
78
+ # def get_filtered_groups(self, df: pd.DataFrame) -> Dict[str, List[str]]:
79
+ # """
80
+ # Create column groups based on simple substring matching.
81
+ # """
82
+ # filtered_groups = {}
83
 
84
+ # # Create benchmark groups
85
+ # for benchmark in self.benchmark_keywords:
86
+ # matching_cols = [
87
+ # col for col in df.columns
88
+ # if benchmark in col.lower()
89
+ # ]
90
+ # if matching_cols:
91
+ # group_name = f"Benchmark group for {benchmark}"
92
+ # filtered_groups[group_name] = matching_cols
93
 
94
+ # # Create model groups
95
+ # for model in self.model_keywords:
96
+ # matching_cols = [
97
+ # col for col in df.columns
98
+ # if model in col.lower()
99
+ # ]
100
+ # if matching_cols:
101
+ # group_name = f"Model group for {model}"
102
+ # filtered_groups[group_name] = matching_cols
103
 
104
+ # return filtered_groups
105
+
106
+ # def update(
107
+ # self,
108
+ # value: Union[pd.DataFrame, Dict[str, List[str]], Any]
109
+ # ) -> Dict:
110
+ # """Update component with new values."""
111
+ # if isinstance(value, pd.DataFrame):
112
+ # choices = list(value.columns)
113
+ # selected = self.initial_selected if self.initial_selected else choices
114
+ # filtered_cols = self.get_filtered_groups(value)
115
 
116
+ # return {
117
+ # "choices": choices,
118
+ # "value": selected,
119
+ # "filtered_cols": filtered_cols
120
+ # }
121
 
122
+ # if hasattr(value, '__dataclass_fields__'):
123
+ # field_names = [field.name for field in fields(value)]
124
+ # return {
125
+ # "choices": field_names,
126
+ # "value": self.initial_selected if self.initial_selected else field_names
127
+ # }
128
 
129
+ # return super().update(value)
130
+
131
+
132
+
133
 
134
  class SmartSelectColumns(SelectColumns):
135
  """