mgyigit commited on
Commit
976e284
·
verified ·
1 Parent(s): b0c3a0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -104,41 +104,40 @@ def update_metrics(selected_benchmarks):
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
116
  TOP5_GREENS = ["#006400", "#228B22", "#32CD32", "#7CFC00", "#ADFF2F"]
117
 
118
  def shade_top5(col: pd.Series) -> list[str]:
119
- """Return background‐colour CSS for the best 5 numeric cells of a column."""
120
  if not pd.api.types.is_numeric_dtype(col):
121
- return [""] * len(col) # leave non-numeric cols untouched
122
  ranks = col.rank(ascending=False, method="first")
123
  return [
124
  f"background-color:{TOP5_GREENS[int(r)-1]};" if r <= 5 else ""
125
  for r in ranks
126
  ]
127
 
128
- def make_leaderboard_df(selected_methods=None, selected_metrics=None):
129
- """Fetch, tidy, colour, and return a Styler that Gradio will render."""
130
  df = get_baseline_df(selected_methods, selected_metrics).round(4)
131
 
132
- # 1️⃣ colour method names via inline HTML
133
- df["Method"] = df["Method"].apply(colour_method)
134
-
135
  numeric_cols = [c for c in df.columns if c != "Method"]
136
 
137
- # 2️⃣ build Styler: shade numeric top-5, keep HTML intact
138
  styler = (
139
  df.style
 
140
  .apply(shade_top5, axis=0, subset=numeric_cols)
141
- .format(escape=False, precision=4) # escape=False keeps <span> alive
 
 
142
  )
143
  return styler
144
 
@@ -252,7 +251,7 @@ with block:
252
  baseline_header = ["Method"] + metric_names
253
  baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
254
 
255
- styler = make_leaderboard_df()
256
 
257
  with gr.Row(show_progress=True, variant='panel'):
258
  data_component = gr.Dataframe(
 
104
  return list(updated_metrics)
105
 
106
  def update_leaderboard(selected_methods, selected_metrics):
107
+ return make_leaderboard_styler(selected_methods, selected_metrics)
108
 
109
 
110
+ def style_method(val: str) -> str:
111
+ """Return CSS for the model name cell."""
112
+ return f"color:{color_dict.get(val, 'black')}; font-weight:bold;"
113
 
114
+ # darkest lightest green for ranks 1-5
 
115
  TOP5_GREENS = ["#006400", "#228B22", "#32CD32", "#7CFC00", "#ADFF2F"]
116
 
117
  def shade_top5(col: pd.Series) -> list[str]:
118
+ """Background colours for the best 5 numeric values of one column."""
119
  if not pd.api.types.is_numeric_dtype(col):
120
+ return [""] * len(col)
121
  ranks = col.rank(ascending=False, method="first")
122
  return [
123
  f"background-color:{TOP5_GREENS[int(r)-1]};" if r <= 5 else ""
124
  for r in ranks
125
  ]
126
 
127
+ def make_leaderboard_styler(selected_methods=None, selected_metrics=None):
128
+ # pull / slice the raw dataframe
129
  df = get_baseline_df(selected_methods, selected_metrics).round(4)
130
 
131
+ # numeric columns only (everything except Method)
 
 
132
  numeric_cols = [c for c in df.columns if c != "Method"]
133
 
 
134
  styler = (
135
  df.style
136
+ # 1. shade top-5 in numeric columns
137
  .apply(shade_top5, axis=0, subset=numeric_cols)
138
+ # 2. colour the Method text
139
+ .applymap(style_method, subset=["Method"])
140
+ .format(precision=4) # nice numbers
141
  )
142
  return styler
143
 
 
251
  baseline_header = ["Method"] + metric_names
252
  baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
253
 
254
+ styler = make_leaderboard_styler()
255
 
256
  with gr.Row(show_progress=True, variant='panel'):
257
  data_component = gr.Dataframe(