Spaces:
Runtime error
Runtime error
| 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 | |