Spaces:
Runtime error
Runtime error
File size: 6,288 Bytes
d83a64f e74285c |
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 |
def model_hyperlink(link, model_name):
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
def make_clickable_model(model_name):
link = f"https://huggingface.co/{model_name}"
return model_hyperlink(link, model_name)
def styled_error(error):
return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>"
def styled_warning(warn):
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>"
def styled_message(message):
return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>"
def has_no_nan_values(df, columns):
return df[columns].notna().all(axis=1)
def has_nan_values(df, columns):
return df[columns].isna().any(axis=1)
def get_score_bar(score):
"""
Generate HTML for a score bar with gradient styling.
Expects score in the range 0-100.
"""
width = max(0, min(score, 100)) # Clamp to [0, 100]
return f"""
<div class="score-bar">
<div class="score-bar-track">
<div class="score-bar-fill" style="width: {width}%;"></div>
</div>
<span class="score-bar-value">{score:.3f}</span>
</div>
"""
def render_leaderboard_html(df, overall_col="average"):
"""
Render a DataFrame as an HTML table, replacing the overall_col with a gauge bar.
"""
from .formatting import get_score_bar
from src.display.css_html_js import get_rank_badge
def get_type_badge(model_type):
if model_type == "open":
return '<span class="badge badge-open">open</span>'
else:
return '<span class="badge badge-closed">closed</span>'
def get_output_badge(output_form):
if output_form == "reasoning":
return '<span class="badge badge-reasoning">reasoning</span>'
else:
return '<span class="badge badge-normal">normal</span>'
# ์จ๊ธธ ์ปฌ๋ผ
hidden_cols = ["Model", "Model Type", "Output Form", "Rank"]
# Build table header
def get_sort_arrow(col, sort_col, sort_asc):
# "Model Name", "Group" ์ปฌ๋ผ์ ์ ์ธํ ๋ชจ๋ ์ปฌ๋ผ์ ์ ๋ ฌ ๋ฒํผ ๋
ธ์ถ
if col in {"Model Name", "Group"}:
return ""
# ํ๋์ ๋ฒํผ(โฒ ๋๋ โผ)๋ง ๋
ธ์ถ, ํด๋ฆญ ์ asc๊ฐ ๋ฐ์ ๋จ
if col == sort_col:
# ํ์ฌ ์ ๋ ฌ ์ํ์ ๋ฐ๋ผ ์์ด์ฝ๊ณผ data-asc๋ฅผ ๋ฐ์
if sort_asc:
# ์ค๋ฆ์ฐจ์ ์ํ: โผ ์์ด์ฝ, ํด๋ฆญ ์ ๋ด๋ฆผ์ฐจ์
svg = (
'<svg width="14" height="14" viewBox="0 0 14 14" style="vertical-align:middle">'
'<polygon points="3,5 11,5 7,11" fill="currentColor"/></svg>'
)
return (
f'<span class="sort-arrow active" data-col="{col}" data-asc="false" aria-label="๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ">{svg}</span>'
)
else:
# ๋ด๋ฆผ์ฐจ์ ์ํ: โฒ ์์ด์ฝ, ํด๋ฆญ ์ ์ค๋ฆ์ฐจ์
svg = (
'<svg width="14" height="14" viewBox="0 0 14 14" style="vertical-align:middle">'
'<polygon points="7,3 11,9 3,9" fill="currentColor"/></svg>'
)
return (
f'<span class="sort-arrow active" data-col="{col}" data-asc="true" aria-label="์ค๋ฆ์ฐจ์ ์ ๋ ฌ">{svg}</span>'
)
else:
# ์ ๋ ฌ ์ค์ด ์๋ ์ปฌ๋ผ: โฒ(์ค๋ฆ์ฐจ์) ์์ด์ฝ, ํด๋ฆญ ์ ์ค๋ฆ์ฐจ์
svg = (
'<svg width="14" height="14" viewBox="0 0 14 14" style="vertical-align:middle">'
'<polygon points="7,3 11,9 3,9" fill="currentColor"/></svg>'
)
return (
f'<span class="sort-arrow" data-col="{col}" data-asc="true" aria-label="์ค๋ฆ์ฐจ์ ์ ๋ ฌ">{svg}</span>'
)
# ์ ๋ ฌ ์ํ ์ถ์ถ (State์์ ์ ๋ฌ๋ฐ๊ฑฐ๋ ๊ธฐ๋ณธ๊ฐ)
sort_col = getattr(df, "_sort_col", None) or (df.columns[0] if len(df.columns) > 0 else None)
sort_asc = getattr(df, "_sort_asc", None)
if sort_asc is None:
sort_asc = True
html = '<table class="pretty-leaderboard-table">\n<thead><tr>'
for col in df.columns:
if col in hidden_cols:
continue
html += f'<th>{col}{get_sort_arrow(col, sort_col, sort_asc)}</th>'
html += '</tr></thead>\n<tbody>\n'
# Build table rows
for idx, row in df.iterrows():
html += '<tr>'
for col in df.columns:
if col in hidden_cols:
continue
cell = row[col]
if col == overall_col:
try:
cell_html = get_score_bar(float(cell))
except Exception:
cell_html = str(cell)
html += f'<td>{cell_html}</td>'
elif col in ["Model Name"]:
# 1~3์ ํ์ด๋ผ์ดํธ + 4๋ฑ ์ดํ ํฐ์ + ๋ฑ์ง ํญ์ ํ์
rank = row.get("Rank", None)
model_type = row.get("Model Type", None) or row.get("Model_Type", None)
output_form = row.get("Output Form", None) or row.get("Output_Form", None)
highlight_style = ""
if rank == 1 or rank == "1":
highlight_style = "color: #ffd700; font-weight: bold; text-shadow: 0 0 4px #fff2;"
elif rank == 2 or rank == "2":
highlight_style = "color: #b0b0b0; font-weight: bold;"
elif rank == 3 or rank == "3":
highlight_style = "color: #cd7f32; font-weight: bold;"
else:
highlight_style = "color: #fff; font-weight: 600;"
badge_html = ""
if model_type:
badge_html += " " + get_type_badge(model_type)
if output_form:
badge_html += " " + get_output_badge(output_form)
html += f'<td><span style="{highlight_style}">{cell}</span>{badge_html}</td>'
else:
html += f'<td>{cell}</td>'
html += '</tr>\n'
html += '</tbody></table>'
return html
|