Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,26 +104,12 @@ def update_metrics(selected_benchmarks):
|
|
| 104 |
return list(updated_metrics)
|
| 105 |
|
| 106 |
def update_leaderboard(selected_methods, selected_metrics):
|
| 107 |
-
|
| 108 |
-
styler = (
|
| 109 |
-
df
|
| 110 |
-
.style
|
| 111 |
-
.apply(highlight_top5, axis=0) # green shades
|
| 112 |
-
.applymap(style_method, subset=["Method"]) # text colours
|
| 113 |
-
.format(precision=4) # keep tidy numbers
|
| 114 |
-
)
|
| 115 |
-
|
| 116 |
-
return styler
|
| 117 |
-
|
| 118 |
|
| 119 |
-
def format_method(name: str) -> str:
|
| 120 |
-
"""Wrap a model name in a coloured <span> so Gradio renders it."""
|
| 121 |
-
colour = color_dict.get(name, "black")
|
| 122 |
-
return f"<span style='color:{colour}; font-weight:bold;'>{name}</span>"
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
return f"color:{color_dict.get(
|
| 127 |
|
| 128 |
# βββ background shading for the top-5 of a numeric column βββ
|
| 129 |
# darkest β lightest
|
|
@@ -144,6 +130,24 @@ def highlight_top5(col: pd.Series) -> list[str]:
|
|
| 144 |
styles.append("")
|
| 145 |
return styles
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
# ------- Visualisation helpers ---------------------------------------------
|
| 148 |
|
| 149 |
|
|
@@ -253,13 +257,7 @@ with block:
|
|
| 253 |
baseline_header = ["Method"] + metric_names
|
| 254 |
baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
|
| 255 |
|
| 256 |
-
styler = (
|
| 257 |
-
baseline_value
|
| 258 |
-
.style
|
| 259 |
-
.apply(highlight_top5, axis=0) # green shades
|
| 260 |
-
.applymap(style_method, subset=["Method"]) # text colours
|
| 261 |
-
.format(precision=4) # keep tidy numbers
|
| 262 |
-
)
|
| 263 |
|
| 264 |
with gr.Row(show_progress=True, variant='panel'):
|
| 265 |
data_component = gr.Dataframe(
|
|
|
|
| 104 |
return list(updated_metrics)
|
| 105 |
|
| 106 |
def update_leaderboard(selected_methods, selected_metrics):
|
| 107 |
+
return make_leaderboard_df(selected_methods, selected_metrics)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
def colour_method(name: str) -> str:
|
| 111 |
+
"""Wrap model name in a coloured <span>."""
|
| 112 |
+
return f"<span style='color:{color_dict.get(name, 'black')}; font-weight:bold;'>{name}</span>"
|
| 113 |
|
| 114 |
# βββ background shading for the top-5 of a numeric column βββ
|
| 115 |
# darkest β lightest
|
|
|
|
| 130 |
styles.append("")
|
| 131 |
return styles
|
| 132 |
|
| 133 |
+
def make_leaderboard_df(selected_methods=None, selected_metrics=None):
|
| 134 |
+
"""Fetch, tidy, colour, and return a Styler that Gradio will render."""
|
| 135 |
+
df = get_baseline_df(selected_methods, selected_metrics).round(4)
|
| 136 |
+
|
| 137 |
+
# 1οΈβ£ colour method names via inline HTML
|
| 138 |
+
df["Method"] = df["Method"].apply(colour_method)
|
| 139 |
+
|
| 140 |
+
numeric_cols = [c for c in df.columns if c != "Method"]
|
| 141 |
+
|
| 142 |
+
# 2οΈβ£ build Styler: shade numeric top-5, keep HTML intact
|
| 143 |
+
styler = (
|
| 144 |
+
df.style
|
| 145 |
+
.apply(shade_top5, axis=0, subset=numeric_cols)
|
| 146 |
+
.format(escape=False, precision=4) # escape=False keeps <span> alive
|
| 147 |
+
)
|
| 148 |
+
return styler
|
| 149 |
+
|
| 150 |
+
|
| 151 |
# ------- Visualisation helpers ---------------------------------------------
|
| 152 |
|
| 153 |
|
|
|
|
| 257 |
baseline_header = ["Method"] + metric_names
|
| 258 |
baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
|
| 259 |
|
| 260 |
+
styler = make_leaderboard_df()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
with gr.Row(show_progress=True, variant='panel'):
|
| 263 |
data_component = gr.Dataframe(
|