shayekh commited on
Commit
7366dc0
Β·
verified Β·
1 Parent(s): a31f502

Updated theme and gradient

Browse files
Files changed (1) hide show
  1. app.py +80 -58
app.py CHANGED
@@ -1,7 +1,9 @@
1
  import gradio as gr
2
  import pandas as pd
 
3
  from gradio_leaderboard import Leaderboard, SelectColumns, ColumnFilter
4
 
 
5
  TITLE = "<h1>M-RewardBench Leaderboard</h1>"
6
  INTRODUCTION_TEXT = "https://m-rewardbench.github.io/"
7
  GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/1qrD7plUdrBwAw7G6UeDVZAaV9ihxaNAcoiKwSaqotR4/export?gid=0&format=csv"
@@ -17,67 +19,22 @@ class AutoEvalColumn:
17
  }
18
 
19
  model_type = {
20
- "name": "Model_Type",
21
  "type": "markdown",
22
  "displayed_by_default": True,
23
  "never_hidden": True,
24
- }
25
-
26
- eng_Latn = {
27
- "name": "eng_Latn",
28
- "type": "float",
29
- "displayed_by_default": True,
30
- "never_hidden": False,
31
- }
32
-
33
- Avg_Multilingual = {
34
- "name": "Avg_Multilingual",
35
- "type": "float",
36
- "displayed_by_default": True,
37
- "never_hidden": False,
38
- }
39
 
40
- arb_Arab = {
41
- "name": "arb_Arab",
42
- "type": "float",
43
- "displayed_by_default": True,
44
- "never_hidden": False,
45
- }
46
-
47
- tur_Latn = {
48
- "name": "tur_Latn",
49
- "type": "float",
50
- "displayed_by_default": True,
51
- "never_hidden": False,
52
- }
53
-
54
- rus_Cyrl = {
55
- "name": "rus_Cyrl",
56
- "type": "float",
57
- "displayed_by_default": True,
58
- "never_hidden": False,
59
- }
60
-
61
- ces_Latn = {
62
- "name": "ces_Latn",
63
- "type": "float",
64
- "displayed_by_default": True,
65
- "never_hidden": False,
66
- }
67
-
68
- pol_Latn = {
69
- "name": "pol_Latn",
70
- "type": "float",
71
- "displayed_by_default": True,
72
- "never_hidden": False,
73
- }
74
-
75
- kor_Hang = {
76
- "name": "kor_Hang",
77
- "type": "float",
78
- "displayed_by_default": True,
79
- "never_hidden": False,
80
- }
81
 
82
 
83
  def get_result_data():
@@ -121,8 +78,39 @@ def format_model_link(row):
121
  # return f'<a href="{url}" target="_blank">{model_name}</a>'
122
  return model_name
123
 
 
 
 
124
 
125
- demo = gr.Blocks()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  with demo:
127
  gr.HTML(TITLE)
128
  gr.Markdown(INTRODUCTION_TEXT)
@@ -130,7 +118,41 @@ with demo:
130
  with gr.Tabs() as tabs:
131
  with gr.TabItem("πŸ… Leaderboard"):
132
  df = get_result_data()
 
 
133
  df["Model"] = df.apply(format_model_link, axis=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  leaderboard = init_leaderboard(df)
 
135
 
136
  demo.launch(ssr_mode=False)
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import numpy as np
4
  from gradio_leaderboard import Leaderboard, SelectColumns, ColumnFilter
5
 
6
+ # Define constants and enums
7
  TITLE = "<h1>M-RewardBench Leaderboard</h1>"
8
  INTRODUCTION_TEXT = "https://m-rewardbench.github.io/"
9
  GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/1qrD7plUdrBwAw7G6UeDVZAaV9ihxaNAcoiKwSaqotR4/export?gid=0&format=csv"
 
19
  }
20
 
21
  model_type = {
22
+ "name": "MT",
23
  "type": "markdown",
24
  "displayed_by_default": True,
25
  "never_hidden": True,
26
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ @classmethod
29
+ def add_columns_from_df(cls, df, columns):
30
+ for col in columns:
31
+ if col.lower() != 'model': # Skip if it's the model column since it's predefined
32
+ setattr(cls, col, {
33
+ "name": col,
34
+ "type": "markdown",
35
+ "displayed_by_default": True,
36
+ "never_hidden": False,
37
+ })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
  def get_result_data():
 
78
  # return f'<a href="{url}" target="_blank">{model_name}</a>'
79
  return model_name
80
 
81
+ lang_ids = "eng_Latn arb_Arab tur_Latn rus_Cyrl ces_Latn pol_Latn kor_Hang zho_Hans zho_Hant fra_Latn ell_Grek deu_Latn ron_Latn ita_Latn nld_Latn pes_Arab hin_Deva ukr_Cyrl por_Latn ind_Latn jpn_Jpan spa_Latn heb_Hebr vie_Latn"
82
+
83
+ emojis = "πŸ”’ πŸ’¬ 🎯"
84
 
85
+ model_types = {"Generative RM": "πŸ’¬", "DPO": "🎯", "Sequence Classifier": "πŸ”’"}
86
+
87
+ from functools import partial
88
+ def format_with_color(val, min_val=50, max_val=100):
89
+ """
90
+ Formats a value with inline green color gradient CSS.
91
+ Returns an HTML string with bold, black text and muted green background.
92
+ """
93
+ try:
94
+ val = float(val)
95
+ if pd.isna(val):
96
+ return str(val)
97
+
98
+ # Normalize value between 50 and 100 to 0-1 range
99
+ normalized = (val - min_val) / (max_val - min_val)
100
+ # Clamp value between 0 and 1
101
+ normalized = max(0, min(1, normalized))
102
+
103
+ # Create color gradient with reduced brightness (max 200 instead of 255)
104
+ # and increased minimum intensity (50 instead of 0)
105
+ intensity = int(50 + (150 * (1 - normalized)))
106
+
107
+ # Return HTML with inline CSS - bold black text
108
+ return f'<div val={val} style="background-color: rgb({intensity}, 200, {intensity}); color: black; font-weight: bold; text-align: center; vertical-align: middle;">{val*100:.1f}</div>'
109
+
110
+ except (ValueError, TypeError):
111
+ return str(val)
112
+
113
+ demo = gr.Blocks(theme=gr.themes.Soft())
114
  with demo:
115
  gr.HTML(TITLE)
116
  gr.Markdown(INTRODUCTION_TEXT)
 
118
  with gr.Tabs() as tabs:
119
  with gr.TabItem("πŸ… Leaderboard"):
120
  df = get_result_data()
121
+ df["Model_Type"] = df["Model_Type"].map(model_types)
122
+
123
  df["Model"] = df.apply(format_model_link, axis=1)
124
+
125
+ df["zho"] = df[["zho_Hans", "zho_Hant"]].mean(axis=1)
126
+
127
+ columns = lang_ids.split("\t")
128
+ # print(df.head())
129
+ df.pop("zho_Hans")
130
+ df.pop("zho_Hant")
131
+
132
+ df.rename(columns={
133
+ "Model_Type": "MT",
134
+ "Avg_Multilingual": "AVG",
135
+ }, inplace=True)
136
+ df.rename(columns={col: col[:3] for col in columns}, inplace=True)
137
+
138
+ # df = df.style.applymap(apply_color_gradient, subset=['eng'])
139
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
140
+
141
+
142
+ for col in numeric_cols:
143
+ lang_format_with_color = partial(format_with_color,
144
+ min_val=df[col].min(),
145
+ max_val=df[col].max())
146
+
147
+ df[col] = df[col].apply(lang_format_with_color)
148
+
149
+
150
+ # for col in numeric_cols:
151
+ # df[col] = (df[col] * 100).round(1).astype(str)
152
+
153
+ AutoEvalColumn.add_columns_from_df(df, numeric_cols)
154
+
155
  leaderboard = init_leaderboard(df)
156
+
157
 
158
  demo.launch(ssr_mode=False)