Michael Rabinovich Cursor commited on
Commit ·
00d6e0c
1
Parent(s): 952dbca
ui: render validity_rate as percentage in the leaderboard table
Browse filesConvert the 0-1 float into 'NN%' (or 'NN.N%' for non-whole values)
just before passing the table to gr.Dataframe, so the column reads as
'100%' instead of '1' / '1.0'. Underlying row schema is unchanged -
validity_rate is still stored as a float in [0, 1] in results.jsonl.
Side-effect: this column now sorts alphabetically rather than
numerically because gr.Dataframe sees strings. Acceptable for v1 - the
primary sort is aggregate_score and validity_rate hovers around 100%
for serious submissions anyway. If finer sorting matters later, switch
to a numeric column with a Gradio formatter.
Co-authored-by: Cursor <cursoragent@cursor.com>
app.py
CHANGED
|
@@ -67,6 +67,14 @@ def _load_rows_from_local() -> list[dict]:
|
|
| 67 |
]
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def load_leaderboard() -> pd.DataFrame:
|
| 71 |
rows = _load_rows_from_hub()
|
| 72 |
if rows is None:
|
|
@@ -76,11 +84,14 @@ def load_leaderboard() -> pd.DataFrame:
|
|
| 76 |
return pd.DataFrame(columns=LEADERBOARD_COLS)
|
| 77 |
df = pd.DataFrame(rows)
|
| 78 |
cols = [c for c in LEADERBOARD_COLS if c in df.columns]
|
| 79 |
-
|
| 80 |
df[cols]
|
| 81 |
.sort_values("aggregate_score", ascending=False, na_position="last")
|
| 82 |
.reset_index(drop=True)
|
| 83 |
)
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
def handle_submit(
|
|
|
|
| 67 |
]
|
| 68 |
|
| 69 |
|
| 70 |
+
def _fmt_pct(x: float | None) -> str:
|
| 71 |
+
"""Render a 0-1 fraction as 'NN%' (or 'NN.N%' for non-whole values)."""
|
| 72 |
+
if x is None:
|
| 73 |
+
return ""
|
| 74 |
+
pct = float(x) * 100
|
| 75 |
+
return f"{pct:.0f}%" if pct == int(pct) else f"{pct:.1f}%"
|
| 76 |
+
|
| 77 |
+
|
| 78 |
def load_leaderboard() -> pd.DataFrame:
|
| 79 |
rows = _load_rows_from_hub()
|
| 80 |
if rows is None:
|
|
|
|
| 84 |
return pd.DataFrame(columns=LEADERBOARD_COLS)
|
| 85 |
df = pd.DataFrame(rows)
|
| 86 |
cols = [c for c in LEADERBOARD_COLS if c in df.columns]
|
| 87 |
+
df = (
|
| 88 |
df[cols]
|
| 89 |
.sort_values("aggregate_score", ascending=False, na_position="last")
|
| 90 |
.reset_index(drop=True)
|
| 91 |
)
|
| 92 |
+
if "validity_rate" in df.columns:
|
| 93 |
+
df["validity_rate"] = df["validity_rate"].map(_fmt_pct)
|
| 94 |
+
return df
|
| 95 |
|
| 96 |
|
| 97 |
def handle_submit(
|