doubao-bench commited on
Commit
66bdfc5
·
1 Parent(s): ee35dfd
Files changed (1) hide show
  1. app.py +93 -2
app.py CHANGED
@@ -3,6 +3,7 @@ import json
3
  from pathlib import Path
4
 
5
  import gradio as gr
 
6
  import pandas as pd
7
  from apscheduler.schedulers.background import BackgroundScheduler
8
  from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
@@ -24,6 +25,8 @@ from src.display.utils import (
24
  from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
25
  from src.populate import get_evaluation_queue_df, get_leaderboard_df
26
 
 
 
27
 
28
  def restart_space():
29
  API.restart_space(repo_id=REPO_ID)
@@ -304,11 +307,11 @@ def create_weights_table_html():
304
  tag = "th" if r_index == min_row else "td"
305
  if r_index != min_row:
306
  if isinstance(value, (int, float)):
307
- value = f"{float(value):.4f}"
308
  elif isinstance(value, str):
309
  stripped = value.strip()
310
  try:
311
- value = f"{float(stripped):.4f}"
312
  except Exception:
313
  pass
314
  text = "" if value is None else html.escape(str(value))
@@ -318,10 +321,94 @@ def create_weights_table_html():
318
  return "".join(parts)
319
 
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  RAW_SCORE_DF = 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;
@@ -347,6 +434,10 @@ with demo:
347
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
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"):
 
3
  from pathlib import Path
4
 
5
  import gradio as gr
6
+ import matplotlib.pyplot as plt
7
  import pandas as pd
8
  from apscheduler.schedulers.background import BackgroundScheduler
9
  from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
 
25
  from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
26
  from src.populate import get_evaluation_queue_df, get_leaderboard_df
27
 
28
+ plt.switch_backend("Agg")
29
+
30
 
31
  def restart_space():
32
  API.restart_space(repo_id=REPO_ID)
 
307
  tag = "th" if r_index == min_row else "td"
308
  if r_index != min_row:
309
  if isinstance(value, (int, float)):
310
+ value = f"{float(value) * 100:.2f}%"
311
  elif isinstance(value, str):
312
  stripped = value.strip()
313
  try:
314
+ value = f"{float(stripped) * 100:.2f}%"
315
  except Exception:
316
  pass
317
  text = "" if value is None else html.escape(str(value))
 
321
  return "".join(parts)
322
 
323
 
324
+ def parse_number(value):
325
+ if value is None or (isinstance(value, float) and pd.isna(value)):
326
+ return None
327
+ if isinstance(value, (int, float)):
328
+ return float(value)
329
+ text = str(value).strip()
330
+ if text == "":
331
+ return None
332
+ if text.endswith("%"):
333
+ try:
334
+ return float(text[:-1])
335
+ except Exception:
336
+ return None
337
+ try:
338
+ return float(text)
339
+ except Exception:
340
+ return None
341
+
342
+
343
+ def shorten_label(text: str, max_len: int = 18):
344
+ text = "" if text is None else str(text)
345
+ if len(text) <= max_len:
346
+ return text
347
+ return text[: max_len - 1] + "…"
348
+
349
+
350
+ def build_metric_choices(raw_df: pd.DataFrame):
351
+ choices = [("Overall Score", "weighted::Overall Score")]
352
+ for col in raw_df.columns:
353
+ if col in ("ID", "Model"):
354
+ continue
355
+ if isinstance(col, str) and "\n" in col:
356
+ group, metric = col.split("\n", 1)
357
+ label = f"{group} / {metric}"
358
+ else:
359
+ label = str(col)
360
+ choices.append((label, f"raw::{col}"))
361
+ return choices
362
+
363
+
364
+ def build_rank_bar_plot(metric_key: str):
365
+ if not isinstance(metric_key, str) or "::" not in metric_key:
366
+ metric_key = "weighted::Overall Score"
367
+ source, col = metric_key.split("::", 1)
368
+
369
+ if source == "weighted":
370
+ df = WEIGHTED_Z_DF
371
+ else:
372
+ df = RAW_SCORE_DF
373
+
374
+ if df is None or df.empty or col not in df.columns:
375
+ fig, ax = plt.subplots(figsize=(10, 4))
376
+ ax.set_axis_off()
377
+ return fig
378
+
379
+ series = []
380
+ for _, row in df.iterrows():
381
+ model = row.get("Model", "")
382
+ value = parse_number(row.get(col))
383
+ if value is None:
384
+ continue
385
+ series.append((str(model), float(value)))
386
+
387
+ series.sort(key=lambda x: x[1], reverse=True)
388
+
389
+ labels = [shorten_label(m) for m, _ in series]
390
+ values = [v for _, v in series]
391
+ n = len(values)
392
+ width = min(22, max(10, 0.55 * max(1, n)))
393
+ fig, ax = plt.subplots(figsize=(width, 5))
394
+ ax.bar(range(n), values)
395
+ ax.set_xticks(range(n))
396
+ ax.set_xticklabels(labels, rotation=35, ha="right")
397
+
398
+ title = "Overall Score" if (source == "weighted" and col == "Overall Score") else str(col)
399
+ ax.set_title(title)
400
+ ax.margins(x=0.01)
401
+ fig.tight_layout()
402
+ return fig
403
+
404
+
405
  RAW_SCORE_DF = create_raw_score_df()
406
  UNWEIGHTED_Z_DF = create_unweighted_z_score_df()
407
  WEIGHTED_Z_DF = create_weighted_z_score_df()
408
 
409
+ METRIC_CHOICES = build_metric_choices(RAW_SCORE_DF)
410
+ DEFAULT_METRIC = "weighted::Overall Score"
411
+
412
  SCORE_TABLE_HEIGHT_CSS = f"""
413
  #raw-score-table .score-table-scroll {{
414
  max-height: {dataframe_height(RAW_SCORE_DF)}px;
 
434
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
435
  with gr.TabItem("Result", elem_id="result-tab", id=0):
436
  with gr.Tabs(elem_classes="tab-buttons") as nested_tabs:
437
+ with gr.TabItem("Chart"):
438
+ metric = gr.Dropdown(choices=METRIC_CHOICES, value=DEFAULT_METRIC, label="Metric")
439
+ chart = gr.Plot(value=build_rank_bar_plot(DEFAULT_METRIC))
440
+ metric.change(build_rank_bar_plot, inputs=metric, outputs=chart)
441
  with gr.TabItem("Raw Score"):
442
  gr.HTML(create_grouped_score_table_html(RAW_SCORE_DF), elem_id="raw-score-table")
443
  with gr.TabItem("Weights"):