natolambert commited on
Commit
4a1518a
1 Parent(s): fe666e1

add colors

Browse files
Files changed (1) hide show
  1. app.py +40 -5
app.py CHANGED
@@ -193,7 +193,36 @@ def random_sample(r: gr.Request, subset):
193
 
194
  subsets = eval_set.unique("subset")
195
 
196
- def regex_table(dataframe, regex, filter_button):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  """
198
  Takes a model name as a regex, then returns only the rows that has that in it.
199
  """
@@ -228,6 +257,8 @@ def regex_table(dataframe, regex, filter_button):
228
  # sort array by Score column
229
  data = data.sort_values(by='Score', ascending=False)
230
 
 
 
231
  # replace column '' with count/rank
232
  data[''] = np.arange(1, 1 + len(data))
233
 
@@ -242,11 +273,15 @@ def regex_table(dataframe, regex, filter_button):
242
  # replace any data[col].values == '' with np.NaN
243
  data[col] = data[col].replace('', np.NaN)
244
  data[col] = np.round(np.array(data[col].values).astype(float), 1)
 
 
 
 
245
  return data
246
 
247
  # import ipdb; ipdb.set_trace()
248
 
249
- total_models = len(regex_table(rewardbench_data_avg.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers", "Generative"]).values)
250
 
251
  with gr.Blocks(css=custom_css) as app:
252
  # create tabs for the app, moving the current table to one titled "rewardbench" and the benchmark_text to a tab called "About"
@@ -281,7 +316,7 @@ with gr.Blocks(css=custom_css) as app:
281
  visible=False,
282
  )
283
  rewardbench_table = gr.Dataframe(
284
- regex_table(rewardbench_data_avg.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers", "Generative", "Prior Sets"]).values,
285
  datatype=col_types_rewardbench_avg,
286
  headers=rewardbench_data_avg.columns.tolist(),
287
  elem_id="rewardbench_dataframe_avg",
@@ -306,7 +341,7 @@ with gr.Blocks(css=custom_css) as app:
306
  visible=False,
307
  )
308
  rewardbench_table_detailed = gr.Dataframe(
309
- regex_table(rewardbench_data.copy(), "", ["Seq. Classifiers", "DPO", "Generative", "Custom Classifiers"]).values,
310
  datatype=col_types_rewardbench,
311
  headers=rewardbench_data.columns.tolist(),
312
  elem_id="rewardbench_dataframe",
@@ -351,7 +386,7 @@ with gr.Blocks(css=custom_css) as app:
351
  visible=False,
352
  )
353
  pref_sets_table = gr.Dataframe(
354
- regex_table(prefs_data.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers"]).values,
355
  datatype=col_types_prefs,
356
  headers=prefs_data.columns.tolist(),
357
  elem_id="prefs_dataframe",
 
193
 
194
  subsets = eval_set.unique("subset")
195
 
196
+ color_map = {
197
+ "Generative": "#7497db",
198
+ "Custom Classifier": "#E8ECF2",
199
+ "Seq. Classifier": "#ffcd75",
200
+ "DPO": "#75809c",
201
+ }
202
+ def color_model_type_column(df, color_map):
203
+ """
204
+ Apply color to the 'Model Type' column of the DataFrame based on a given color mapping.
205
+
206
+ Parameters:
207
+ df (pd.DataFrame): The DataFrame containing the 'Model Type' column.
208
+ color_map (dict): A dictionary mapping model types to colors.
209
+
210
+ Returns:
211
+ pd.Styler: The styled DataFrame.
212
+ """
213
+ # Function to apply color based on the model type
214
+ def apply_color(val):
215
+ color = color_map.get(val, "default") # Default color if not specified in color_map
216
+ return f'background-color: {color}'
217
+
218
+ # Format for different columns
219
+ format_dict = {col: "{:.1f}" for col in df.columns if col not in ['Average', 'Model', 'Model Type']}
220
+ format_dict['Average'] = "{:.2f}"
221
+ format_dict[''] = "{:d}"
222
+
223
+ return df.style.applymap(apply_color, subset=['Model Type']).format(format_dict, na_rep='')
224
+
225
+ def regex_table(dataframe, regex, filter_button, style=True):
226
  """
227
  Takes a model name as a regex, then returns only the rows that has that in it.
228
  """
 
257
  # sort array by Score column
258
  data = data.sort_values(by='Score', ascending=False)
259
 
260
+ data.reset_index(drop=True, inplace=True)
261
+
262
  # replace column '' with count/rank
263
  data[''] = np.arange(1, 1 + len(data))
264
 
 
273
  # replace any data[col].values == '' with np.NaN
274
  data[col] = data[col].replace('', np.NaN)
275
  data[col] = np.round(np.array(data[col].values).astype(float), 1)
276
+ if style:
277
+ # apply color
278
+ data = color_model_type_column(data, color_map)
279
+
280
  return data
281
 
282
  # import ipdb; ipdb.set_trace()
283
 
284
+ total_models = len(regex_table(rewardbench_data_avg.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers", "Generative"], style=False).values)
285
 
286
  with gr.Blocks(css=custom_css) as app:
287
  # create tabs for the app, moving the current table to one titled "rewardbench" and the benchmark_text to a tab called "About"
 
316
  visible=False,
317
  )
318
  rewardbench_table = gr.Dataframe(
319
+ regex_table(rewardbench_data_avg.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers", "Generative", "Prior Sets"]),
320
  datatype=col_types_rewardbench_avg,
321
  headers=rewardbench_data_avg.columns.tolist(),
322
  elem_id="rewardbench_dataframe_avg",
 
341
  visible=False,
342
  )
343
  rewardbench_table_detailed = gr.Dataframe(
344
+ regex_table(rewardbench_data.copy(), "", ["Seq. Classifiers", "DPO", "Generative", "Custom Classifiers"]),
345
  datatype=col_types_rewardbench,
346
  headers=rewardbench_data.columns.tolist(),
347
  elem_id="rewardbench_dataframe",
 
386
  visible=False,
387
  )
388
  pref_sets_table = gr.Dataframe(
389
+ regex_table(prefs_data.copy(), "", ["Seq. Classifiers", "DPO", "Custom Classifiers"]),
390
  datatype=col_types_prefs,
391
  headers=prefs_data.columns.tolist(),
392
  elem_id="prefs_dataframe",