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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -104,18 +104,20 @@ def update_metrics(selected_benchmarks):
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")
@@ -124,20 +126,19 @@ def shade_top5(col: pd.Series) -> list[str]:
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,7 +252,7 @@ with block:
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(
 
104
  return list(updated_metrics)
105
 
106
  def update_leaderboard(selected_methods, selected_metrics):
107
+ return build_leaderboard_styler(selected_methods, selected_metrics)
108
 
109
 
110
+ def colour_method_html(name: str) -> str:
111
+ """Return the method string wrapped in a coloured <span>. Handles raw names
112
+ or markdown links like '[T5](https://…)' transparently."""
113
+ colour = color_dict.get(re.sub(r"\[|\]|\(.*?\)", "", name), "black") # strip md link
114
+ return f"<span style='color:{colour}; font-weight:bold;'>{name}</span>"
115
 
116
+ # darkest → lightest green
117
  TOP5_GREENS = ["#006400", "#228B22", "#32CD32", "#7CFC00", "#ADFF2F"]
118
 
119
  def shade_top5(col: pd.Series) -> list[str]:
120
+ """Return a CSS list for one column: background for ranks 1-5, blank else."""
121
  if not pd.api.types.is_numeric_dtype(col):
122
  return [""] * len(col)
123
  ranks = col.rank(ascending=False, method="first")
 
126
  for r in ranks
127
  ]
128
 
129
+ def build_leaderboard_styler(selected_methods=None, selected_metrics=None):
 
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_html)
134
+
135
  numeric_cols = [c for c in df.columns if c != "Method"]
136
 
137
+ # 2️⃣ add the green gradient only to numeric cols
138
  styler = (
139
  df.style
 
140
  .apply(shade_top5, axis=0, subset=numeric_cols)
141
+ .format(precision=4) # keep numbers tidy
 
 
142
  )
143
  return styler
144
 
 
252
  baseline_header = ["Method"] + metric_names
253
  baseline_datatype = ['markdown'] + ['number'] * len(metric_names)
254
 
255
+ styler = build_leaderboard_styler()
256
 
257
  with gr.Row(show_progress=True, variant='panel'):
258
  data_component = gr.Dataframe(