fzoll commited on
Commit
c88a66b
·
verified ·
1 Parent(s): ae1ceab

Add secondary header (#12)

Browse files

- Add secondary header (881b278aaee9cec3d4c5cb0c7f36e29a20237d16)

Files changed (2) hide show
  1. app/backend/data_page.py +166 -54
  2. requirements.txt +2 -2
app/backend/data_page.py CHANGED
@@ -20,8 +20,9 @@ COLUMNS = ['model_name', 'vendor',
20
  'query_instruct', 'corpus_instruct', 'reference'
21
 
22
  ]
23
- HEADER_STYLE = {'fontSize': '18px'}
24
- CELL_STYLE = {'fontSize': '18px'}
 
25
 
26
 
27
  def is_section(group_name):
@@ -63,6 +64,153 @@ def get_column_state():
63
  return None
64
 
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  def render_page(group_name):
67
  grid_state = st.session_state.get("grid_state", {})
68
  st.session_state.sider_bar_hidden = True
@@ -156,7 +304,6 @@ def render_page(group_name):
156
  position: fixed !important;
157
  z-index: 2147483647 !important;
158
  }
159
-
160
  </style>
161
 
162
  """, unsafe_allow_html=True)
@@ -175,13 +322,6 @@ def render_page(group_name):
175
 
176
  csv = convert_df_to_csv(df)
177
  file_name = f"{group_name.capitalize()} Leaderboard" if is_section(group_name) else group_name.capitalize()
178
- st.download_button(
179
- label="Download CSV",
180
- data=csv,
181
- file_name=f"{file_name}.csv",
182
- mime="text/csv",
183
- icon=":material/download:",
184
- )
185
 
186
  # get columns
187
  column_list = []
@@ -212,6 +352,10 @@ def render_page(group_name):
212
  if dataset_dict["name"] == group_name:
213
  dataset_list = dataset_dict["datasets"]
214
  if not is_section(group_name):
 
 
 
 
215
  column_list.extend(dataset_list)
216
  closed_list = get_closed_dataset()
217
  close_avg_list = list(set(dataset_list) & set(closed_list))
@@ -330,49 +474,7 @@ def render_page(group_name):
330
  # 'suppressSizeToFit': True,
331
  },
332
 
333
- *[{'headerName': column if "Average" not in column else column.replace("Average", "").strip().capitalize(),
334
- 'field': column,
335
- 'headerStyle': HEADER_STYLE,
336
- 'cellStyle': CELL_STYLE,
337
- "headerTooltip": column if "Average" not in column else column.replace("Average",
338
- "").strip().capitalize(),
339
- 'headerComponent': JsCode(f"""
340
- class DatasetHeaderRenderer {{
341
- init(params) {{
342
- this.eGui = document.createElement('div');
343
- const columnName = params.displayName;
344
- const fieldName = params.column.colId;
345
-
346
- if (fieldName.includes('Average')) {{
347
- // For group columns (like "Code Average", "English Average"), display as plain text
348
- this.eGui.textContent = columnName;
349
- }} else {{
350
- // For dataset columns, create clickable link to HuggingFace dataset
351
- const link = document.createElement('a');
352
- link.href = 'https://huggingface.co/datasets/embedding-benchmark/' + fieldName;
353
- link.target = '_blank';
354
- link.style.color = 'white';
355
- link.style.textDecoration = 'underline';
356
- link.style.cursor = 'pointer';
357
- link.textContent = columnName;
358
-
359
- // Prevent event bubbling to avoid sorting trigger
360
- link.addEventListener('click', function(e) {{
361
- e.stopPropagation();
362
- }});
363
-
364
- this.eGui.appendChild(link);
365
- }}
366
- }}
367
-
368
- getGui() {{
369
- return this.eGui;
370
- }}
371
- }}
372
- """)
373
- # 'suppressSizeToFit': True
374
- } for column in column_list if
375
- column not in (avg_column, "Closed average", "Open average")]
376
  ],
377
  'defaultColDef': {
378
  'filter': True,
@@ -461,7 +563,17 @@ def render_page(group_name):
461
  st_copy_to_clipboard(share_link, before_copy_label='📋Push to copy', after_copy_label='✅Text copied!',
462
  theme=theme)
463
 
464
- share_btn = st.button("Share this page", icon=":material/share:")
 
 
 
 
 
 
 
 
 
 
465
 
466
  if share_btn:
467
  share_url()
 
20
  'query_instruct', 'corpus_instruct', 'reference'
21
 
22
  ]
23
+ LARGER_HEADER_STYLE = {'fontSize': '18px'}
24
+ HEADER_STYLE = {'fontSize': '14px'}
25
+ CELL_STYLE = {'fontSize': '14px'}
26
 
27
 
28
  def is_section(group_name):
 
64
  return None
65
 
66
 
67
+ def _get_dataset_columns(group_name, column_list, avg_column):
68
+ """Generate dataset columns with proper grouping for individual dataset pages."""
69
+ dataset_columns = [col for col in column_list if col not in (avg_column, "Closed average", "Open average")]
70
+
71
+ # For individual dataset pages (not sections), group datasets by open/closed
72
+ if not is_section(group_name) and dataset_columns:
73
+ # Separate open and closed datasets
74
+ open_datasets = [d for d in dataset_columns if not d.startswith('_')]
75
+ closed_datasets = [d for d in dataset_columns if d.startswith('_')]
76
+
77
+ grouped_columns = []
78
+
79
+ # Add Open Datasets group
80
+ if open_datasets:
81
+ grouped_columns.append({
82
+ 'headerName': 'Open Datasets',
83
+ 'headerStyle': LARGER_HEADER_STYLE,
84
+ 'headerClass': 'group-header',
85
+ 'marryChildren': True,
86
+ 'openByDefault': True,
87
+ 'children': [
88
+ {
89
+ 'headerName': column,
90
+ 'field': column,
91
+ 'headerStyle': HEADER_STYLE,
92
+ 'cellStyle': CELL_STYLE,
93
+ "headerTooltip": column,
94
+ 'headerComponent': JsCode(f"""
95
+ class DatasetHeaderRenderer {{
96
+ init(params) {{
97
+ this.eGui = document.createElement('div');
98
+ const columnName = params.displayName;
99
+ const fieldName = params.column.colId;
100
+
101
+ const link = document.createElement('a');
102
+ link.href = 'https://huggingface.co/datasets/embedding-benchmark/' + fieldName;
103
+ link.target = '_blank';
104
+ link.style.color = 'white';
105
+ link.style.textDecoration = 'underline';
106
+ link.style.cursor = 'pointer';
107
+ link.textContent = columnName;
108
+
109
+ link.addEventListener('click', function(e) {{
110
+ e.stopPropagation();
111
+ }});
112
+
113
+ this.eGui.appendChild(link);
114
+ }}
115
+
116
+ getGui() {{
117
+ return this.eGui;
118
+ }}
119
+ }}
120
+ """)
121
+ } for column in open_datasets
122
+ ]
123
+ })
124
+
125
+ # Add Closed Datasets group
126
+ if closed_datasets:
127
+ grouped_columns.append({
128
+ 'headerName': 'Closed Datasets',
129
+ 'headerStyle': LARGER_HEADER_STYLE,
130
+ 'headerClass': 'group-header',
131
+ 'marryChildren': True,
132
+ 'openByDefault': True,
133
+ 'children': [
134
+ {
135
+ 'headerName': column,
136
+ 'field': column,
137
+ 'headerStyle': HEADER_STYLE,
138
+ 'cellStyle': CELL_STYLE,
139
+ "headerTooltip": column,
140
+ 'headerComponent': JsCode(f"""
141
+ class DatasetHeaderRenderer {{
142
+ init(params) {{
143
+ this.eGui = document.createElement('div');
144
+ const columnName = params.displayName;
145
+ const fieldName = params.column.colId;
146
+
147
+ const link = document.createElement('a');
148
+ link.href = 'https://huggingface.co/datasets/embedding-benchmark/' + fieldName;
149
+ link.target = '_blank';
150
+ link.style.color = 'white';
151
+ link.style.textDecoration = 'underline';
152
+ link.style.cursor = 'pointer';
153
+ link.textContent = columnName;
154
+
155
+ link.addEventListener('click', function(e) {{
156
+ e.stopPropagation();
157
+ }});
158
+
159
+ this.eGui.appendChild(link);
160
+ }}
161
+
162
+ getGui() {{
163
+ return this.eGui;
164
+ }}
165
+ }}
166
+ """)
167
+ } for column in closed_datasets
168
+ ]
169
+ })
170
+
171
+ return grouped_columns
172
+ else:
173
+ # For section pages, return columns without grouping (original behavior)
174
+ return [{'headerName': column if "Average" not in column else column.replace("Average", "").strip().capitalize(),
175
+ 'field': column,
176
+ 'headerStyle': HEADER_STYLE,
177
+ 'cellStyle': CELL_STYLE,
178
+ "headerTooltip": column if "Average" not in column else column.replace("Average",
179
+ "").strip().capitalize(),
180
+ 'headerComponent': JsCode(f"""
181
+ class DatasetHeaderRenderer {{
182
+ init(params) {{
183
+ this.eGui = document.createElement('div');
184
+ const columnName = params.displayName;
185
+ const fieldName = params.column.colId;
186
+
187
+ if (fieldName.includes('Average')) {{
188
+ this.eGui.textContent = columnName;
189
+ }} else {{
190
+ const link = document.createElement('a');
191
+ link.href = 'https://huggingface.co/datasets/embedding-benchmark/' + fieldName;
192
+ link.target = '_blank';
193
+ link.style.color = 'white';
194
+ link.style.textDecoration = 'underline';
195
+ link.style.cursor = 'pointer';
196
+ link.textContent = columnName;
197
+
198
+ link.addEventListener('click', function(e) {{
199
+ e.stopPropagation();
200
+ }});
201
+
202
+ this.eGui.appendChild(link);
203
+ }}
204
+ }}
205
+
206
+ getGui() {{
207
+ return this.eGui;
208
+ }}
209
+ }}
210
+ """)
211
+ } for column in dataset_columns]
212
+
213
+
214
  def render_page(group_name):
215
  grid_state = st.session_state.get("grid_state", {})
216
  st.session_state.sider_bar_hidden = True
 
304
  position: fixed !important;
305
  z-index: 2147483647 !important;
306
  }
 
307
  </style>
308
 
309
  """, unsafe_allow_html=True)
 
322
 
323
  csv = convert_df_to_csv(df)
324
  file_name = f"{group_name.capitalize()} Leaderboard" if is_section(group_name) else group_name.capitalize()
 
 
 
 
 
 
 
325
 
326
  # get columns
327
  column_list = []
 
352
  if dataset_dict["name"] == group_name:
353
  dataset_list = dataset_dict["datasets"]
354
  if not is_section(group_name):
355
+ # Sort datasets: open first, then closed
356
+ open_datasets = [d for d in dataset_list if not d.startswith('_')]
357
+ closed_datasets = [d for d in dataset_list if d.startswith('_')]
358
+ dataset_list = open_datasets + closed_datasets
359
  column_list.extend(dataset_list)
360
  closed_list = get_closed_dataset()
361
  close_avg_list = list(set(dataset_list) & set(closed_list))
 
474
  # 'suppressSizeToFit': True,
475
  },
476
 
477
+ *(_get_dataset_columns(group_name, column_list, avg_column))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  ],
479
  'defaultColDef': {
480
  'filter': True,
 
563
  st_copy_to_clipboard(share_link, before_copy_label='📋Push to copy', after_copy_label='✅Text copied!',
564
  theme=theme)
565
 
566
+ col1, col2 = st.columns([1, 1])
567
+ with col1:
568
+ st.download_button(
569
+ label="Download CSV",
570
+ data=csv,
571
+ file_name=f"{file_name}.csv",
572
+ mime="text/csv",
573
+ icon=":material/download:",
574
+ )
575
+ with col2:
576
+ share_btn = st.button("Share this page", icon=":material/share:")
577
 
578
  if share_btn:
579
  share_url()
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- streamlit==1.41.1
2
- streamlit-aggrid==1.0.5
3
  st-pages==1.0.1
4
  msgpack==1.1.0
5
  zstandard==0.23.0
 
1
+ streamlit==1.47.1
2
+ streamlit-aggrid==1.1.7
3
  st-pages==1.0.1
4
  msgpack==1.1.0
5
  zstandard==0.23.0