Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,7 +115,30 @@ def format_method(name: str) -> str:
|
|
| 115 |
"""Wrap a model name in a coloured <span> so Gradio renders it."""
|
| 116 |
colour = color_dict.get(name, "black")
|
| 117 |
return f"<span style='color:{colour}; font-weight:bold;'>{name}</span>"
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# ------- Visualisation helpers ---------------------------------------------
|
| 120 |
|
| 121 |
|
|
@@ -222,13 +245,21 @@ with block:
|
|
| 222 |
|
| 223 |
baseline_value = get_baseline_df(method_names, metric_names)
|
| 224 |
baseline_value = baseline_value.applymap(lambda x: round(x, 4) if isinstance(x, (int, float)) else x)
|
| 225 |
-
baseline_value['Method'] = baseline_value['Method'].apply(format_method)
|
| 226 |
baseline_header = ["Method"] + metric_names
|
| 227 |
baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
with gr.Row(show_progress=True, variant='panel'):
|
| 230 |
data_component = gr.Dataframe(
|
| 231 |
-
value=
|
| 232 |
headers=baseline_header,
|
| 233 |
type="pandas",
|
| 234 |
datatype=baseline_datatype,
|
|
|
|
| 115 |
"""Wrap a model name in a coloured <span> so Gradio renders it."""
|
| 116 |
colour = color_dict.get(name, "black")
|
| 117 |
return f"<span style='color:{colour}; font-weight:bold;'>{name}</span>"
|
| 118 |
+
|
| 119 |
+
# βββ text colour for the Method column βββ
|
| 120 |
+
def style_method(val: str) -> str:
|
| 121 |
+
return f"color:{color_dict.get(val, 'black')}; font-weight:bold;"
|
| 122 |
+
|
| 123 |
+
# βββ background shading for the top-5 of a numeric column βββ
|
| 124 |
+
# darkest β lightest
|
| 125 |
+
TOP5_GREENS = ["#006400", "#228B22", "#32CD32", "#7CFC00", "#ADFF2F"]
|
| 126 |
+
|
| 127 |
+
def highlight_top5(col: pd.Series) -> list[str]:
|
| 128 |
+
"""Return a list of CSS strings for one numeric column."""
|
| 129 |
+
# ignore non-numeric cols
|
| 130 |
+
if not pd.api.types.is_numeric_dtype(col):
|
| 131 |
+
return [""] * len(col)
|
| 132 |
+
|
| 133 |
+
ranks = col.rank(ascending=False, method="first") # 1 = best
|
| 134 |
+
styles = []
|
| 135 |
+
for r in ranks:
|
| 136 |
+
if r <= 5:
|
| 137 |
+
styles.append(f"background-color:{TOP5_GREENS[int(r)-1]};")
|
| 138 |
+
else:
|
| 139 |
+
styles.append("")
|
| 140 |
+
return styles
|
| 141 |
+
|
| 142 |
# ------- Visualisation helpers ---------------------------------------------
|
| 143 |
|
| 144 |
|
|
|
|
| 245 |
|
| 246 |
baseline_value = get_baseline_df(method_names, metric_names)
|
| 247 |
baseline_value = baseline_value.applymap(lambda x: round(x, 4) if isinstance(x, (int, float)) else x)
|
| 248 |
+
#baseline_value['Method'] = baseline_value['Method'].apply(format_method)
|
| 249 |
baseline_header = ["Method"] + metric_names
|
| 250 |
baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
|
| 251 |
+
|
| 252 |
+
styler = (
|
| 253 |
+
baseline_value
|
| 254 |
+
.style
|
| 255 |
+
.applymap(style_method, subset=["Method"]) # text colours
|
| 256 |
+
.apply(highlight_top5, axis=0) # green shades
|
| 257 |
+
.format(precision=4) # keep tidy numbers
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
with gr.Row(show_progress=True, variant='panel'):
|
| 261 |
data_component = gr.Dataframe(
|
| 262 |
+
value=styler,
|
| 263 |
headers=baseline_header,
|
| 264 |
type="pandas",
|
| 265 |
datatype=baseline_datatype,
|