doubao-bench commited on
Commit
3132066
·
1 Parent(s): 4124648

fix-style

Browse files
Files changed (2) hide show
  1. app.py +82 -59
  2. src/display/css_html_js.py +36 -0
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import html
2
  import json
3
- import re
4
  from pathlib import Path
5
 
6
  import gradio as gr
@@ -132,23 +131,81 @@ def dataframe_height(df: pd.DataFrame):
132
  return max(320, min(1200, height))
133
 
134
 
135
- def create_gr_dataframe(value, **kwargs):
136
- dataframe_ctor = getattr(gr, "DataFrame", None) or getattr(gr, "Dataframe")
137
- remaining_kwargs = dict(kwargs)
138
-
139
- for _ in range(20):
140
- try:
141
- return dataframe_ctor(value, **remaining_kwargs)
142
- except TypeError as e:
143
- match = re.search(r"unexpected keyword argument '([^']+)'", str(e))
144
- if match is None:
145
- raise
146
- bad_key = match.group(1)
147
- if bad_key not in remaining_kwargs:
148
- raise
149
- remaining_kwargs.pop(bad_key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
- return dataframe_ctor(value, **remaining_kwargs)
 
152
 
153
 
154
  def create_raw_score_df():
@@ -265,34 +322,21 @@ RAW_SCORE_DF = create_raw_score_df()
265
  UNWEIGHTED_Z_DF = create_unweighted_z_score_df()
266
  WEIGHTED_Z_DF = create_weighted_z_score_df()
267
 
268
- RAW_SCORE_COLUMN_WIDTHS = [40, 220] + [180] * (len(RAW_SCORE_DF.columns) - 2)
269
- UNWEIGHTED_Z_COLUMN_WIDTHS = [40, 220] + [180] * (len(UNWEIGHTED_Z_DF.columns) - 2)
270
- WEIGHTED_Z_COLUMN_WIDTHS = [40, 220] + [180] * (len(WEIGHTED_Z_DF.columns) - 2)
271
-
272
- DATAFRAME_HEIGHT_CSS = f"""
273
- #raw-score-table .table-wrap,
274
- #raw-score-table .wrap,
275
- #raw-score-table .wrap-inner {{
276
  max-height: {dataframe_height(RAW_SCORE_DF)}px;
277
- overflow-y: auto;
278
  }}
279
 
280
- #unweighted-z-table .table-wrap,
281
- #unweighted-z-table .wrap,
282
- #unweighted-z-table .wrap-inner {{
283
  max-height: {dataframe_height(UNWEIGHTED_Z_DF)}px;
284
- overflow-y: auto;
285
  }}
286
 
287
- #weighted-z-table .table-wrap,
288
- #weighted-z-table .wrap,
289
- #weighted-z-table .wrap-inner {{
290
  max-height: {dataframe_height(WEIGHTED_Z_DF)}px;
291
- overflow-y: auto;
292
  }}
293
  """
294
 
295
- demo = gr.Blocks(css=custom_css + DATAFRAME_HEIGHT_CSS)
296
 
297
 
298
  with demo:
@@ -304,34 +348,13 @@ with demo:
304
  with gr.TabItem("Result", elem_id="result-tab", id=0):
305
  with gr.Tabs(elem_classes="tab-buttons") as nested_tabs:
306
  with gr.TabItem("Raw Score"):
307
- create_gr_dataframe(
308
- RAW_SCORE_DF,
309
- wrap=True,
310
- column_widths=RAW_SCORE_COLUMN_WIDTHS,
311
- row_count=(len(RAW_SCORE_DF), "fixed"),
312
- height=dataframe_height(RAW_SCORE_DF),
313
- elem_id="raw-score-table",
314
- )
315
  with gr.TabItem("Weights"):
316
  gr.HTML(create_weights_table_html(), elem_id="weights-table")
317
  with gr.TabItem("Unweighted Z-score"):
318
- create_gr_dataframe(
319
- UNWEIGHTED_Z_DF,
320
- wrap=True,
321
- column_widths=UNWEIGHTED_Z_COLUMN_WIDTHS,
322
- row_count=(len(UNWEIGHTED_Z_DF), "fixed"),
323
- height=dataframe_height(UNWEIGHTED_Z_DF),
324
- elem_id="unweighted-z-table",
325
- )
326
  with gr.TabItem("Weighted Z-score"):
327
- create_gr_dataframe(
328
- WEIGHTED_Z_DF,
329
- wrap=True,
330
- column_widths=WEIGHTED_Z_COLUMN_WIDTHS,
331
- row_count=(len(WEIGHTED_Z_DF), "fixed"),
332
- height=dataframe_height(WEIGHTED_Z_DF),
333
- elem_id="weighted-z-table",
334
- )
335
 
336
  with gr.TabItem("About", elem_id="llm-benchmark-tab-table", id=2):
337
  gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
 
1
  import html
2
  import json
 
3
  from pathlib import Path
4
 
5
  import gradio as gr
 
131
  return max(320, min(1200, height))
132
 
133
 
134
+ def create_grouped_score_table_html(df: pd.DataFrame):
135
+ if df is None or df.empty:
136
+ return '<div class="score-table-scroll"><table class="score-table"></table></div>'
137
+
138
+ fixed_cols = [c for c in ("ID", "Model") if c in df.columns]
139
+
140
+ group_to_cols = {}
141
+ group_order = []
142
+ data_cols_in_order = []
143
+
144
+ for col in df.columns:
145
+ if col in fixed_cols:
146
+ continue
147
+ if isinstance(col, str) and "\n" in col:
148
+ group, metric = col.split("\n", 1)
149
+ else:
150
+ group, metric = str(col), str(col)
151
+
152
+ if group not in group_to_cols:
153
+ group_to_cols[group] = []
154
+ group_order.append(group)
155
+
156
+ group_to_cols[group].append((metric, col))
157
+ data_cols_in_order.append(col)
158
+
159
+ parts = ['<div class="score-table-scroll"><table class="score-table">']
160
+
161
+ parts.append("<colgroup>")
162
+ if len(fixed_cols) >= 1:
163
+ parts.append('<col style="width:40px">')
164
+ if len(fixed_cols) >= 2:
165
+ parts.append('<col style="width:200px">')
166
+ for _ in range(len(data_cols_in_order)):
167
+ parts.append('<col style="width:180px">')
168
+ parts.append("</colgroup>")
169
+
170
+ parts.append("<thead>")
171
+
172
+ parts.append("<tr>")
173
+ for col in fixed_cols:
174
+ parts.append(f'<th rowspan="2"><div class="score-cell">{html.escape(str(col))}</div></th>')
175
+ merged_groups = set()
176
+ for group in group_order:
177
+ metrics = group_to_cols[group]
178
+ if len(metrics) == 1 and str(metrics[0][0]) == str(group):
179
+ merged_groups.add(group)
180
+ parts.append(f'<th rowspan="2"><div class="score-cell">{html.escape(str(group))}</div></th>')
181
+ else:
182
+ parts.append(
183
+ f'<th colspan="{len(metrics)}"><div class="score-cell">{html.escape(str(group))}</div></th>'
184
+ )
185
+ parts.append("</tr>")
186
+
187
+ parts.append("<tr>")
188
+ for group in group_order:
189
+ if group in merged_groups:
190
+ continue
191
+ for metric, _ in group_to_cols[group]:
192
+ parts.append(f"<th><div class=\"score-cell\">{html.escape(str(metric))}</div></th>")
193
+ parts.append("</tr>")
194
+
195
+ parts.append("</thead>")
196
+ parts.append("<tbody>")
197
+
198
+ col_indices = [df.columns.get_loc(c) for c in (fixed_cols + data_cols_in_order)]
199
+ for row in df.itertuples(index=False, name=None):
200
+ parts.append("<tr>")
201
+ for idx in col_indices:
202
+ value = row[idx]
203
+ text = "" if pd.isna(value) else str(value)
204
+ parts.append(f"<td><div class=\"score-cell\">{html.escape(text)}</div></td>")
205
+ parts.append("</tr>")
206
 
207
+ parts.append("</tbody></table></div>")
208
+ return "".join(parts)
209
 
210
 
211
  def create_raw_score_df():
 
322
  UNWEIGHTED_Z_DF = create_unweighted_z_score_df()
323
  WEIGHTED_Z_DF = create_weighted_z_score_df()
324
 
325
+ SCORE_TABLE_HEIGHT_CSS = f"""
326
+ #raw-score-table .score-table-scroll {{
 
 
 
 
 
 
327
  max-height: {dataframe_height(RAW_SCORE_DF)}px;
 
328
  }}
329
 
330
+ #unweighted-z-table .score-table-scroll {{
 
 
331
  max-height: {dataframe_height(UNWEIGHTED_Z_DF)}px;
 
332
  }}
333
 
334
+ #weighted-z-table .score-table-scroll {{
 
 
335
  max-height: {dataframe_height(WEIGHTED_Z_DF)}px;
 
336
  }}
337
  """
338
 
339
+ demo = gr.Blocks(css=custom_css + SCORE_TABLE_HEIGHT_CSS)
340
 
341
 
342
  with demo:
 
348
  with gr.TabItem("Result", elem_id="result-tab", id=0):
349
  with gr.Tabs(elem_classes="tab-buttons") as nested_tabs:
350
  with gr.TabItem("Raw Score"):
351
+ gr.HTML(create_grouped_score_table_html(RAW_SCORE_DF), elem_id="raw-score-table")
 
 
 
 
 
 
 
352
  with gr.TabItem("Weights"):
353
  gr.HTML(create_weights_table_html(), elem_id="weights-table")
354
  with gr.TabItem("Unweighted Z-score"):
355
+ gr.HTML(create_grouped_score_table_html(UNWEIGHTED_Z_DF), elem_id="unweighted-z-table")
 
 
 
 
 
 
 
356
  with gr.TabItem("Weighted Z-score"):
357
+ gr.HTML(create_grouped_score_table_html(WEIGHTED_Z_DF), elem_id="weighted-z-table")
 
 
 
 
 
 
 
358
 
359
  with gr.TabItem("About", elem_id="llm-benchmark-tab-table", id=2):
360
  gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
src/display/css_html_js.py CHANGED
@@ -132,6 +132,42 @@ custom_css = """
132
  white-space: nowrap;
133
  }
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  #weights-table {
136
  overflow-x: auto !important;
137
  max-width: 100%;
 
132
  white-space: nowrap;
133
  }
134
 
135
+ .score-table-scroll {
136
+ overflow: auto;
137
+ max-width: 100%;
138
+ }
139
+
140
+ .score-table {
141
+ border-collapse: collapse;
142
+ width: max-content;
143
+ table-layout: fixed;
144
+ }
145
+
146
+ .score-table th,
147
+ .score-table td {
148
+ border: 1px solid rgba(0,0,0,0.08);
149
+ padding: 8px 10px;
150
+ vertical-align: middle;
151
+ box-sizing: border-box;
152
+ }
153
+
154
+ .score-cell {
155
+ display: block;
156
+ margin: 0;
157
+ }
158
+
159
+ .score-table thead th {
160
+ font-weight: 600;
161
+ background: rgba(0,0,0,0.02);
162
+ text-align: center;
163
+ }
164
+
165
+ .score-table thead .score-cell {
166
+ white-space: normal;
167
+ overflow-wrap: break-word;
168
+ word-break: normal;
169
+ }
170
+
171
  #weights-table {
172
  overflow-x: auto !important;
173
  max-width: 100%;