Spaces:
Sleeping
Sleeping
File size: 10,632 Bytes
ce5dc1f 353cfb3 ce5dc1f cb288c7 353cfb3 cb288c7 ce5dc1f cb288c7 353cfb3 ce5dc1f 353cfb3 ce5dc1f ecd99d2 ce5dc1f ecd99d2 ce5dc1f ecd99d2 ce5dc1f ecd99d2 ce5dc1f ecd99d2 ce5dc1f ecd99d2 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f cb288c7 ce5dc1f 353cfb3 ce5dc1f cb288c7 ce5dc1f cb288c7 353cfb3 cb288c7 ce5dc1f 353cfb3 ecd99d2 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f ecd99d2 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 cb288c7 ecd99d2 353cfb3 ecd99d2 353cfb3 ecd99d2 353cfb3 cb288c7 353cfb3 cb288c7 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 ce5dc1f 353cfb3 09591bc |
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# -*- coding: utf-8 -*-
# @Date : 2025/2/5 16:26
# @Author : q275343119
# @File : data_page.py
# @Description:
import io
from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
import streamlit as st
from app.backend.app_init_func import LEADERBOARD_MAP
from app.backend.constant import LEADERBOARD_ICON_MAP
COLUMNS = ['model_name',
'embd_dtype', 'embd_dim', 'num_params', 'max_tokens', 'similarity',
'query_instruct', 'corpus_instruct', 'reference'
]
HEADER_STYLE = {'fontSize': '18px'}
CELL_STYLE = {'fontSize': '18px'}
def is_section(group_name):
for k, v in LEADERBOARD_MAP.items():
leaderboard_name = v[0][0]
if group_name == leaderboard_name:
return True
return False
def get_closed_dataset():
data_engine = st.session_state["data_engine"]
closed_list = []
results = data_engine.results
for result in results:
if result.get("is_closed"):
closed_list.append(result.get("dataset_name"))
return closed_list
def convert_df_to_csv(df):
output = io.StringIO()
df.to_csv(output, index=False)
return output.getvalue()
def render_page(group_name):
# Add theme color and grid styles
st.title("Retrieval Embedding Benchmark (RTEB)")
st.markdown("""
<style>
:root {
--theme-color: rgb(129, 150, 64);
--theme-color-light: rgba(129, 150, 64, 0.2);
}
/* AG Grid specific overrides */
.ag-theme-alpine {
--ag-selected-row-background-color: var(--theme-color-light) !important;
--ag-row-hover-color: var(--theme-color-light) !important;
--ag-selected-tab-color: var(--theme-color) !important;
--ag-range-selection-border-color: var(--theme-color) !important;
--ag-range-selection-background-color: var(--theme-color-light) !important;
}
.ag-row-hover {
background-color: var(--theme-color-light) !important;
}
.ag-row-selected {
background-color: var(--theme-color-light) !important;
}
.ag-row-focus {
background-color: var(--theme-color-light) !important;
}
.ag-cell-focus {
border-color: var(--theme-color) !important;
}
/* Keep existing styles */
.center-text {
text-align: center;
color: var(--theme-color);
}
.center-image {
display: block;
margin-left: auto;
margin-right: auto;
}
h2 {
color: var(--theme-color) !important;
}
.ag-header-cell {
background-color: var(--theme-color) !important;
color: white !important;
}
a {
color: var(--theme-color) !important;
}
a:hover {
color: rgba(129, 150, 64, 0.8) !important;
}
/* Download Button */
button[data-testid="stBaseButton-secondary"] {
float: right;
}
</style>
""", unsafe_allow_html=True)
# logo
# st.markdown('<img src="https://www.voyageai.com/logo.svg" class="center-image" width="200">', unsafe_allow_html=True)
title = f'<h2 class="center-text">{LEADERBOARD_ICON_MAP.get(group_name.capitalize(), "")} {group_name.capitalize()}</h2>'
if is_section(group_name):
title = f'<h2 class="center-text">{LEADERBOARD_ICON_MAP.get(group_name.capitalize() + " Leaderboard", "")} {group_name.capitalize() + " Leaderboard"}</h2>'
# title
st.markdown(title, unsafe_allow_html=True)
data_engine = st.session_state["data_engine"]
df = data_engine.jsons_to_df().copy()
csv = convert_df_to_csv(df)
file_name = f"{group_name.capitalize()} Leaderboard" if is_section(group_name) else group_name.capitalize()
st.download_button(
label="Download CSV",
data=csv,
file_name=f"{file_name}.csv",
mime="text/csv",
icon=":material/download:",
)
# get columns
column_list = []
avg_column = None
if is_section(group_name):
avg_columns = []
for column in df.columns:
if column.startswith("Average"):
avg_columns.insert(0, column)
continue
if "Average" in column:
avg_columns.append(column)
continue
avg_column = avg_columns[0]
column_list.extend(avg_columns)
else:
for column in df.columns:
if column.startswith(group_name.capitalize() + " "):
avg_column = column
column_list.append(avg_column)
dataset_list = []
for dataset_dict in data_engine.datasets:
if dataset_dict["name"] == group_name:
dataset_list = dataset_dict["datasets"]
if not is_section(group_name):
column_list.extend(dataset_list)
closed_list = get_closed_dataset()
close_avg_list = list(set(dataset_list) & set(closed_list))
df["Closed average"] = df[close_avg_list].mean(axis=1).round(2)
column_list.append("Closed average")
open_avg_list = list(set(dataset_list) - set(closed_list))
df["Open average"] = df[open_avg_list].mean(axis=1).round(2)
column_list.append("Open average")
df = df[COLUMNS + column_list].sort_values(by=avg_column, ascending=False)
# rename avg column name
if not is_section(group_name):
new_column = avg_column.replace(group_name.capitalize(), "").strip()
df.rename(columns={avg_column: new_column}, inplace=True)
column_list.remove(avg_column)
avg_column = new_column
# setting column config
grid_options = {
'columnDefs': [
{
'headerName': 'Model Name',
'field': 'model_name',
'pinned': 'left',
'sortable': False,
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
"tooltipValueGetter": JsCode(
"""function(p) {return p.value}"""
),
"width": 250,
'cellRenderer': JsCode("""class CustomHTML {
init(params) {
const link = params.data.reference;
this.eGui = document.createElement('div');
this.eGui.innerHTML = link ?
`<a href="${link}" class="a-cell" target="_blank">${params.value} </a>` :
params.value;
}
getGui() {
return this.eGui;
}
}"""),
'suppressSizeToFit': True
},
{'headerName': "Overall Score",
'field': avg_column,
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True
},
# Add Open average column definition
{'headerName': 'Open Average',
'field': 'Open average',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True
},
{'headerName': 'Closed Average',
'field': 'Closed average',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True
},
{
'headerName': 'Embd Dtype',
'field': 'embd_dtype',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True,
},
{
'headerName': 'Embd Dim',
'field': 'embd_dim',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True,
},
{
'headerName': 'Number of Parameters',
'field': 'num_params',
'cellDataType': 'number',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
'valueFormatter': JsCode(
"""function(params) {
const num = params.value;
if (num >= 1e9) return (num / 1e9).toFixed(2) + "B";
if (num >= 1e6) return (num / 1e6).toFixed(2) + "M";
if (num >= 1e3) return (num / 1e3).toFixed(2) + "K";
return num;
}"""
),
# 'suppressSizeToFit': True,
},
{
'headerName': 'Context Length',
'field': 'max_tokens',
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True,
},
*[{'headerName': column if "Average" not in column else column.replace("Average", "").strip().capitalize(),
'field': column,
'headerStyle': HEADER_STYLE,
'cellStyle': CELL_STYLE,
# 'suppressSizeToFit': True
} for column in column_list if
column not in (avg_column, "Closed average", "Open average")]
],
'defaultColDef': {
'filter': True,
'sortable': True,
'resizable': True,
'headerClass': "multi-line-header",
'autoHeaderHeight': True
},
"autoSizeStrategy": {
"type": 'fitGridWidth',
"defaultMinWidth": 105,
},
"tooltipShowDelay": 500,
}
custom_css = {
".a-cell": {
"display": "inline-block",
"white-space": "nowrap",
"overflow": "hidden",
"text-overflow": "ellipsis",
"width": "100%",
"min-width": "0"
},
".multi-line-header": {
"text-overflow": "clip",
"overflow": "visible",
"white-space": "normal",
"height": "auto",
}
}
AgGrid(
df,
enable_enterprise_modules=False,
gridOptions=grid_options,
allow_unsafe_jscode=True,
columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
theme="streamlit",
custom_css=custom_css
)
|