wangruisi1 commited on
Commit ·
707db45
1
Parent(s): 39b9fcf
Fix column colors
Browse files- app.py +70 -22
- src/display/css_html_js.py +59 -110
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from src.about import (
|
|
| 10 |
LLM_BENCHMARKS_TEXT,
|
| 11 |
TITLE,
|
| 12 |
)
|
| 13 |
-
from src.display.css_html_js import custom_css
|
| 14 |
|
| 15 |
|
| 16 |
# ============================================================
|
|
@@ -45,6 +45,30 @@ DEFAULT_GROUPS = [
|
|
| 45 |
# Columns always shown regardless of group selection
|
| 46 |
ALWAYS_VISIBLE_COLS = ["Model", "Type"]
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
# ============================================================
|
| 49 |
# Static model scores data
|
| 50 |
# ============================================================
|
|
@@ -62,12 +86,6 @@ MODEL_LINKS = {
|
|
| 62 |
"HunyuanVideo-I2V": "https://huggingface.co/tencent/HunyuanVideo-I2V",
|
| 63 |
}
|
| 64 |
|
| 65 |
-
def make_model_link(model_name):
|
| 66 |
-
"""Create a clickable HTML link for a model if URL exists."""
|
| 67 |
-
if model_name in MODEL_LINKS:
|
| 68 |
-
return f'<a href="{MODEL_LINKS[model_name]}" target="_blank">{model_name}</a>'
|
| 69 |
-
return model_name
|
| 70 |
-
|
| 71 |
MODELS_DATA = [
|
| 72 |
{
|
| 73 |
"Model": "Human",
|
|
@@ -168,25 +186,60 @@ def build_full_dataframe():
|
|
| 168 |
# Round numeric columns to 3 decimal places for clean display
|
| 169 |
numeric_cols = df.select_dtypes(include="number").columns
|
| 170 |
df[numeric_cols] = df[numeric_cols].round(3)
|
| 171 |
-
# Add clickable links to model names
|
| 172 |
-
df["Model"] = df["Model"].apply(make_model_link)
|
| 173 |
return df
|
| 174 |
|
| 175 |
|
| 176 |
FULL_DF = build_full_dataframe()
|
| 177 |
|
| 178 |
|
| 179 |
-
def
|
| 180 |
-
"""
|
| 181 |
if not selected_groups:
|
| 182 |
-
selected_groups = ["Overall"]
|
| 183 |
|
| 184 |
cols = list(ALWAYS_VISIBLE_COLS)
|
| 185 |
for group_name, group_cols in COLUMN_GROUPS.items():
|
| 186 |
if group_name in selected_groups:
|
| 187 |
cols.extend(group_cols)
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
# ============================================================
|
|
@@ -207,17 +260,15 @@ with demo:
|
|
| 207 |
interactive=True,
|
| 208 |
)
|
| 209 |
|
| 210 |
-
|
| 211 |
-
value=
|
| 212 |
-
interactive=False,
|
| 213 |
elem_id="leaderboard-table",
|
| 214 |
-
datatype=["html"] + ["str"] * 20, # First column (Model) renders as HTML for links
|
| 215 |
)
|
| 216 |
|
| 217 |
column_selector.change(
|
| 218 |
-
fn=
|
| 219 |
inputs=[column_selector],
|
| 220 |
-
outputs=[
|
| 221 |
)
|
| 222 |
|
| 223 |
with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=1):
|
|
@@ -236,7 +287,4 @@ with demo:
|
|
| 236 |
show_copy_button=True,
|
| 237 |
)
|
| 238 |
|
| 239 |
-
# Inject JS to dynamically color columns based on header text
|
| 240 |
-
gr.HTML(f"<script>{COLOR_COLUMNS_JS}</script>")
|
| 241 |
-
|
| 242 |
demo.queue(default_concurrency_limit=40).launch()
|
|
|
|
| 10 |
LLM_BENCHMARKS_TEXT,
|
| 11 |
TITLE,
|
| 12 |
)
|
| 13 |
+
from src.display.css_html_js import custom_css
|
| 14 |
|
| 15 |
|
| 16 |
# ============================================================
|
|
|
|
| 45 |
# Columns always shown regardless of group selection
|
| 46 |
ALWAYS_VISIBLE_COLS = ["Model", "Type"]
|
| 47 |
|
| 48 |
+
# ============================================================
|
| 49 |
+
# Column-to-color mapping
|
| 50 |
+
# Soft, harmonious palette: dark/light pairs for each group
|
| 51 |
+
# ============================================================
|
| 52 |
+
COLUMN_COLORS = {}
|
| 53 |
+
# Overall (dark amber)
|
| 54 |
+
for col in ["Overall"]:
|
| 55 |
+
COLUMN_COLORS[col] = "rgba(232, 180, 58, 0.30)"
|
| 56 |
+
# Overall by Category (light amber)
|
| 57 |
+
for col in ["Abst.(All)", "Know.(All)", "Perc.(All)", "Spat.(All)", "Trans.(All)"]:
|
| 58 |
+
COLUMN_COLORS[col] = "rgba(242, 200, 90, 0.15)"
|
| 59 |
+
# In-Domain Overall (dark green)
|
| 60 |
+
for col in ["Overall(In-Domain)"]:
|
| 61 |
+
COLUMN_COLORS[col] = "rgba(82, 183, 120, 0.30)"
|
| 62 |
+
# In-Domain by Category (light green)
|
| 63 |
+
for col in ["Abst.(ID)", "Know.(ID)", "Perc.(ID)", "Spat.(ID)", "Trans.(ID)"]:
|
| 64 |
+
COLUMN_COLORS[col] = "rgba(110, 200, 145, 0.15)"
|
| 65 |
+
# Out-of-Domain Overall (dark blue)
|
| 66 |
+
for col in ["Overall(Out-of-Domain)"]:
|
| 67 |
+
COLUMN_COLORS[col] = "rgba(95, 150, 215, 0.30)"
|
| 68 |
+
# Out-of-Domain by Category (light blue)
|
| 69 |
+
for col in ["Abst.(OOD)", "Know.(OOD)", "Perc.(OOD)", "Spat.(OOD)", "Trans.(OOD)"]:
|
| 70 |
+
COLUMN_COLORS[col] = "rgba(125, 175, 228, 0.15)"
|
| 71 |
+
|
| 72 |
# ============================================================
|
| 73 |
# Static model scores data
|
| 74 |
# ============================================================
|
|
|
|
| 86 |
"HunyuanVideo-I2V": "https://huggingface.co/tencent/HunyuanVideo-I2V",
|
| 87 |
}
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
MODELS_DATA = [
|
| 90 |
{
|
| 91 |
"Model": "Human",
|
|
|
|
| 186 |
# Round numeric columns to 3 decimal places for clean display
|
| 187 |
numeric_cols = df.select_dtypes(include="number").columns
|
| 188 |
df[numeric_cols] = df[numeric_cols].round(3)
|
|
|
|
|
|
|
| 189 |
return df
|
| 190 |
|
| 191 |
|
| 192 |
FULL_DF = build_full_dataframe()
|
| 193 |
|
| 194 |
|
| 195 |
+
def render_html_table(selected_groups):
|
| 196 |
+
"""Render the leaderboard as a styled HTML table with column group colors."""
|
| 197 |
if not selected_groups:
|
| 198 |
+
selected_groups = ["Overall"]
|
| 199 |
|
| 200 |
cols = list(ALWAYS_VISIBLE_COLS)
|
| 201 |
for group_name, group_cols in COLUMN_GROUPS.items():
|
| 202 |
if group_name in selected_groups:
|
| 203 |
cols.extend(group_cols)
|
| 204 |
|
| 205 |
+
df = FULL_DF[cols]
|
| 206 |
+
|
| 207 |
+
# Build HTML table
|
| 208 |
+
html = '<div class="leaderboard-scroll"><table class="leaderboard-html-table">\n'
|
| 209 |
+
|
| 210 |
+
# Header
|
| 211 |
+
html += '<thead><tr>\n'
|
| 212 |
+
for col in cols:
|
| 213 |
+
bg = COLUMN_COLORS.get(col, "")
|
| 214 |
+
style = f' style="background-color: {bg};"' if bg else ''
|
| 215 |
+
html += f' <th{style}>{col}</th>\n'
|
| 216 |
+
html += '</tr></thead>\n'
|
| 217 |
+
|
| 218 |
+
# Body
|
| 219 |
+
html += '<tbody>\n'
|
| 220 |
+
for _, row in df.iterrows():
|
| 221 |
+
html += '<tr>\n'
|
| 222 |
+
for col in cols:
|
| 223 |
+
bg = COLUMN_COLORS.get(col, "")
|
| 224 |
+
style = f' style="background-color: {bg};"' if bg else ''
|
| 225 |
+
val = row[col]
|
| 226 |
+
|
| 227 |
+
if col == "Model":
|
| 228 |
+
# Render model name with link
|
| 229 |
+
model_name = val
|
| 230 |
+
if model_name in MODEL_LINKS:
|
| 231 |
+
cell = f'<a href="{MODEL_LINKS[model_name]}" target="_blank">{model_name}</a>'
|
| 232 |
+
else:
|
| 233 |
+
cell = model_name
|
| 234 |
+
elif isinstance(val, float):
|
| 235 |
+
cell = f'{val:.3f}'
|
| 236 |
+
else:
|
| 237 |
+
cell = str(val)
|
| 238 |
+
|
| 239 |
+
html += f' <td{style}>{cell}</td>\n'
|
| 240 |
+
html += '</tr>\n'
|
| 241 |
+
html += '</tbody>\n</table></div>'
|
| 242 |
+
return html
|
| 243 |
|
| 244 |
|
| 245 |
# ============================================================
|
|
|
|
| 260 |
interactive=True,
|
| 261 |
)
|
| 262 |
|
| 263 |
+
leaderboard_html = gr.HTML(
|
| 264 |
+
value=render_html_table(DEFAULT_GROUPS),
|
|
|
|
| 265 |
elem_id="leaderboard-table",
|
|
|
|
| 266 |
)
|
| 267 |
|
| 268 |
column_selector.change(
|
| 269 |
+
fn=render_html_table,
|
| 270 |
inputs=[column_selector],
|
| 271 |
+
outputs=[leaderboard_html],
|
| 272 |
)
|
| 273 |
|
| 274 |
with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=1):
|
|
|
|
| 287 |
show_copy_button=True,
|
| 288 |
)
|
| 289 |
|
|
|
|
|
|
|
|
|
|
| 290 |
demo.queue(default_concurrency_limit=40).launch()
|
src/display/css_html_js.py
CHANGED
|
@@ -22,11 +22,7 @@ custom_css = """
|
|
| 22 |
}
|
| 23 |
|
| 24 |
#leaderboard-table {
|
| 25 |
-
margin-top: 15px
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
#leaderboard-table-lite {
|
| 29 |
-
margin-top: 15px
|
| 30 |
}
|
| 31 |
|
| 32 |
#search-bar-table-box > div:first-child {
|
|
@@ -38,31 +34,6 @@ custom_css = """
|
|
| 38 |
padding: 0px;
|
| 39 |
}
|
| 40 |
|
| 41 |
-
/* Model column — wider to avoid truncation */
|
| 42 |
-
#leaderboard-table td:nth-child(1),
|
| 43 |
-
#leaderboard-table th:nth-child(1) {
|
| 44 |
-
min-width: 220px !important;
|
| 45 |
-
white-space: nowrap;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
/* Type column — wider to avoid truncation */
|
| 49 |
-
#leaderboard-table td:nth-child(2),
|
| 50 |
-
#leaderboard-table th:nth-child(2) {
|
| 51 |
-
min-width: 170px !important;
|
| 52 |
-
white-space: nowrap;
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
/* Model links: underline + hover color */
|
| 56 |
-
#leaderboard-table td a {
|
| 57 |
-
color: #2563eb;
|
| 58 |
-
text-decoration: underline;
|
| 59 |
-
text-underline-offset: 2px;
|
| 60 |
-
transition: color 0.2s ease;
|
| 61 |
-
}
|
| 62 |
-
#leaderboard-table td a:hover {
|
| 63 |
-
color: #d97706;
|
| 64 |
-
}
|
| 65 |
-
|
| 66 |
.tab-buttons button {
|
| 67 |
font-size: 20px;
|
| 68 |
}
|
|
@@ -113,34 +84,71 @@ custom_css = """
|
|
| 113 |
}
|
| 114 |
|
| 115 |
/* ============================================================
|
| 116 |
-
|
| 117 |
-
Soft, harmonious palette with dark/light pairs per group.
|
| 118 |
-
Applied dynamically via JS based on column header text.
|
| 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 |
-
background-color: rgba(125, 175, 228, 0.15) !important;
|
| 144 |
}
|
| 145 |
"""
|
| 146 |
|
|
@@ -151,62 +159,3 @@ get_window_url_params = """
|
|
| 151 |
return url_params;
|
| 152 |
}
|
| 153 |
"""
|
| 154 |
-
|
| 155 |
-
# JavaScript to dynamically color columns based on header text.
|
| 156 |
-
# Runs on load and re-runs via MutationObserver whenever the table updates.
|
| 157 |
-
COLOR_COLUMNS_JS = """
|
| 158 |
-
function colorLeaderboardColumns() {
|
| 159 |
-
const table = document.querySelector('#leaderboard-table table');
|
| 160 |
-
if (!table) return;
|
| 161 |
-
|
| 162 |
-
const headers = table.querySelectorAll('thead th');
|
| 163 |
-
if (!headers.length) return;
|
| 164 |
-
|
| 165 |
-
// Map header text -> color class
|
| 166 |
-
const colorMap = {};
|
| 167 |
-
headers.forEach((th, idx) => {
|
| 168 |
-
const text = th.textContent.trim();
|
| 169 |
-
let cls = '';
|
| 170 |
-
if (text === 'Overall') {
|
| 171 |
-
cls = 'col-overall-dark';
|
| 172 |
-
} else if (text.includes('(All)')) {
|
| 173 |
-
cls = 'col-overall-light';
|
| 174 |
-
} else if (text === 'Overall(In-Domain)') {
|
| 175 |
-
cls = 'col-id-dark';
|
| 176 |
-
} else if (text.includes('(ID)')) {
|
| 177 |
-
cls = 'col-id-light';
|
| 178 |
-
} else if (text === 'Overall(Out-of-Domain)') {
|
| 179 |
-
cls = 'col-ood-dark';
|
| 180 |
-
} else if (text.includes('(OOD)')) {
|
| 181 |
-
cls = 'col-ood-light';
|
| 182 |
-
}
|
| 183 |
-
colorMap[idx] = cls;
|
| 184 |
-
|
| 185 |
-
// Apply to header cell
|
| 186 |
-
th.classList.remove('col-overall-dark','col-overall-light','col-id-dark','col-id-light','col-ood-dark','col-ood-light');
|
| 187 |
-
if (cls) th.classList.add(cls);
|
| 188 |
-
});
|
| 189 |
-
|
| 190 |
-
// Apply to body cells
|
| 191 |
-
const rows = table.querySelectorAll('tbody tr');
|
| 192 |
-
rows.forEach(row => {
|
| 193 |
-
const cells = row.querySelectorAll('td');
|
| 194 |
-
cells.forEach((td, idx) => {
|
| 195 |
-
td.classList.remove('col-overall-dark','col-overall-light','col-id-dark','col-id-light','col-ood-dark','col-ood-light');
|
| 196 |
-
if (colorMap[idx]) td.classList.add(colorMap[idx]);
|
| 197 |
-
});
|
| 198 |
-
});
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
// Run on initial load
|
| 202 |
-
setTimeout(colorLeaderboardColumns, 500);
|
| 203 |
-
|
| 204 |
-
// Re-run when table changes (column toggle, etc.)
|
| 205 |
-
const observer = new MutationObserver(() => {
|
| 206 |
-
setTimeout(colorLeaderboardColumns, 100);
|
| 207 |
-
});
|
| 208 |
-
const target = document.querySelector('#leaderboard-table');
|
| 209 |
-
if (target) {
|
| 210 |
-
observer.observe(target, { childList: true, subtree: true });
|
| 211 |
-
}
|
| 212 |
-
"""
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
#leaderboard-table {
|
| 25 |
+
margin-top: 15px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
#search-bar-table-box > div:first-child {
|
|
|
|
| 34 |
padding: 0px;
|
| 35 |
}
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
.tab-buttons button {
|
| 38 |
font-size: 20px;
|
| 39 |
}
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
/* ============================================================
|
| 87 |
+
Styled HTML leaderboard table
|
|
|
|
|
|
|
| 88 |
============================================================ */
|
| 89 |
|
| 90 |
+
.leaderboard-scroll {
|
| 91 |
+
overflow-x: auto;
|
| 92 |
+
width: 100%;
|
| 93 |
}
|
| 94 |
+
|
| 95 |
+
.leaderboard-html-table {
|
| 96 |
+
width: 100%;
|
| 97 |
+
border-collapse: collapse;
|
| 98 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 99 |
+
font-size: 14px;
|
| 100 |
+
line-height: 1.5;
|
| 101 |
}
|
| 102 |
+
|
| 103 |
+
.leaderboard-html-table thead th {
|
| 104 |
+
position: sticky;
|
| 105 |
+
top: 0;
|
| 106 |
+
z-index: 1;
|
| 107 |
+
padding: 10px 14px;
|
| 108 |
+
text-align: center;
|
| 109 |
+
font-weight: 600;
|
| 110 |
+
font-size: 13px;
|
| 111 |
+
border-bottom: 2px solid #d1d5db;
|
| 112 |
+
white-space: nowrap;
|
| 113 |
}
|
| 114 |
+
|
| 115 |
+
.leaderboard-html-table tbody td {
|
| 116 |
+
padding: 8px 14px;
|
| 117 |
+
text-align: center;
|
| 118 |
+
border-bottom: 1px solid #e5e7eb;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/* Model column — left-aligned, wider */
|
| 122 |
+
.leaderboard-html-table th:first-child,
|
| 123 |
+
.leaderboard-html-table td:first-child {
|
| 124 |
+
text-align: left;
|
| 125 |
+
min-width: 220px;
|
| 126 |
+
white-space: nowrap;
|
| 127 |
+
font-weight: 500;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/* Type column — left-aligned, wider */
|
| 131 |
+
.leaderboard-html-table th:nth-child(2),
|
| 132 |
+
.leaderboard-html-table td:nth-child(2) {
|
| 133 |
+
text-align: left;
|
| 134 |
+
min-width: 170px;
|
| 135 |
+
white-space: nowrap;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* Row hover */
|
| 139 |
+
.leaderboard-html-table tbody tr:hover td {
|
| 140 |
+
filter: brightness(0.95);
|
| 141 |
}
|
| 142 |
+
|
| 143 |
+
/* Model links: underline + hover color change */
|
| 144 |
+
.leaderboard-html-table td a {
|
| 145 |
+
color: #2563eb;
|
| 146 |
+
text-decoration: underline;
|
| 147 |
+
text-underline-offset: 2px;
|
| 148 |
+
transition: color 0.2s ease;
|
| 149 |
}
|
| 150 |
+
.leaderboard-html-table td a:hover {
|
| 151 |
+
color: #d97706;
|
|
|
|
| 152 |
}
|
| 153 |
"""
|
| 154 |
|
|
|
|
| 159 |
return url_params;
|
| 160 |
}
|
| 161 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|