File size: 5,009 Bytes
941a9ef
 
7366dc0
cea6930
 
7366dc0
cea6930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7366dc0
cea6930
 
 
7366dc0
cea6930
7366dc0
 
 
 
 
 
 
 
 
 
cea6930
 
 
 
941a9ef
 
 
cea6930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7366dc0
 
 
cea6930
7366dc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
941a9ef
cea6930
 
941a9ef
cea6930
 
 
7366dc0
 
cea6930
7366dc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cea6930
7366dc0
941a9ef
411541a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import gradio as gr
import pandas as pd
import numpy as np
from gradio_leaderboard import Leaderboard, SelectColumns, ColumnFilter

# Define constants and enums
TITLE = "<h1>M-RewardBench Leaderboard</h1>"
INTRODUCTION_TEXT = "https://m-rewardbench.github.io/"
GOOGLE_SHEET_URL = "https://docs.google.com/spreadsheets/d/1qrD7plUdrBwAw7G6UeDVZAaV9ihxaNAcoiKwSaqotR4/export?gid=0&format=csv"
ABOUT_TEXT = """Welcome to M-RewardBench Leaderboard!"""


class AutoEvalColumn:
  model = {
    "name": "Model",
    "type": "markdown",
    "displayed_by_default": True,
    "never_hidden": True,
  }
  
  model_type = {
    "name": "MT",
    "type": "markdown",
    "displayed_by_default": True,
    "never_hidden": True,
  }	
  
  @classmethod
  def add_columns_from_df(cls, df, columns):
    for col in columns:
      if col.lower() != 'model':  # Skip if it's the model column since it's predefined
        setattr(cls, col, {
              "name": col,
              "type": "markdown",
              "displayed_by_default": True,
              "never_hidden": False,
        })				


def get_result_data():
  return pd.read_csv(GOOGLE_SHEET_URL)


def init_leaderboard(dataframe):
  if dataframe is None or dataframe.empty:
    raise ValueError("Leaderboard DataFrame is empty or None.")

  return Leaderboard(
    value=dataframe,
    datatype=[
      col["type"]
      for col in AutoEvalColumn.__dict__.values()
      if isinstance(col, dict)
    ],
    select_columns=SelectColumns(
      default_selection=[
        col["name"]
        for col in AutoEvalColumn.__dict__.values()
        if isinstance(col, dict) and col["displayed_by_default"]
      ],
      cant_deselect=[
        col["name"]
        for col in AutoEvalColumn.__dict__.values()
        if isinstance(col, dict) and col.get("never_hidden", False)
      ],
      label="Select Columns to Display:",
    ),
    search_columns=["Model"],
    interactive=False,
  )


def format_model_link(row):
  """Format model name as HTML link if URL is available"""
  model_name = row["Model"]
  # url = row.get("URL", "")
  # if pd.notna(url) and url.strip():
  #   return f'<a href="{url}" target="_blank">{model_name}</a>'
  return model_name

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"

emojis = "πŸ”’ πŸ’¬ 🎯"

model_types = {"Generative RM": "πŸ’¬", "DPO": "🎯", "Sequence Classifier": "πŸ”’"}

from functools import partial
def format_with_color(val, min_val=50, max_val=100):
    """
    Formats a value with inline green color gradient CSS.
    Returns an HTML string with bold, black text and muted green background.
    """
    try:
        val = float(val)
        if pd.isna(val):
            return str(val)
            
        # Normalize value between 50 and 100 to 0-1 range
        normalized = (val - min_val) / (max_val - min_val)
        # Clamp value between 0 and 1
        normalized = max(0, min(1, normalized))
        
        # Create color gradient with reduced brightness (max 200 instead of 255)
        # and increased minimum intensity (50 instead of 0)
        intensity = int(50 + (150 * (1 - normalized)))        
        
        # Return HTML with inline CSS - bold black text
        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>'
      
    except (ValueError, TypeError):
        return str(val)

demo = gr.Blocks(theme=gr.themes.Soft())
with demo:
  gr.HTML(TITLE)
  gr.Markdown(INTRODUCTION_TEXT)

  with gr.Tabs() as tabs:
    with gr.TabItem("πŸ… Leaderboard"):
      df = get_result_data()
      df["Model_Type"] = df["Model_Type"].map(model_types)
    
      df["Model"] = df.apply(format_model_link, axis=1)
      
      df["zho"] = df[["zho_Hans", "zho_Hant"]].mean(axis=1)
      
      columns = lang_ids.split("\t")
      # print(df.head())
      df.pop("zho_Hans")
      df.pop("zho_Hant")
      
      df.rename(columns={
        "Model_Type": "MT",
        "Avg_Multilingual": "AVG",
      }, inplace=True)
      df.rename(columns={col: col[:3] for col in columns}, inplace=True)
  
      # df = df.style.applymap(apply_color_gradient, subset=['eng'])
      numeric_cols = df.select_dtypes(include=[np.number]).columns
      
      
      for col in numeric_cols:
        lang_format_with_color = partial(format_with_color, 
                                        min_val=df[col].min(),
                                        max_val=df[col].max())
    
        df[col] = df[col].apply(lang_format_with_color)
        
      
      # for col in numeric_cols:
      #   df[col] = (df[col] * 100).round(1).astype(str)
      
      AutoEvalColumn.add_columns_from_df(df, numeric_cols)
        
      leaderboard = init_leaderboard(df)
      

demo.launch(ssr_mode=False)