# **************************** # HTML HELPERS # **************************** def model_hyperlink(link, model_name): return f'{model_name}' 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"
{error}
" def styled_warning(warn): return f"{warn}
" def styled_message(message): return f"{message}
" # **************************** # DATA VALIDATION # **************************** 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) # **************************** # RANK & SCORE VISUALIZATION # **************************** def get_rank_badge(rank: int) -> str: if rank == 1: return '🥇' elif rank == 2: return '🥈' elif rank == 3: return '🥉' else: return f'{rank}' def get_score_gauge(score: float) -> str: """Progress bar visualization (UNUSED)""" try: score = float(score) except (TypeError, ValueError): score = 0.0 if score is None or score != score: percent = 0.0 display_score = 0.0 elif score <= 1.0: percent = score * 100 display_score = percent else: percent = score display_score = score if percent >= 95: percent = 98 + (min(percent, 100) - 95) * 0.4 percent = min(max(percent, 0), 100) display_score = min(max(display_score, 0), 100) return f''' ''' def get_score_stars(score: float, unique_id: str = None) -> str: """Star rating with numeric score display""" try: score = float(score) except (TypeError, ValueError): score = 0.0 if score <= 1.0: stars = score * 5 display_score = f"{score:.3f}" else: stars = (score / 100) * 5 display_score = f"{score:.1f}" full_stars = int(stars) partial_star = stars - full_stars empty_stars = 5 - full_stars - (1 if partial_star > 0 else 0) star_html = [] for i in range(full_stars): star_html.append('★') if partial_star > 0: star_html.append(f'★') for i in range(empty_stars): star_html.append('☆') stars_str = ''.join(star_html) return f'| {col} | ') else: html.append(f"{col} | ") html.append("||
|---|---|---|---|
| {badge} | ") elif col == "model_id": rank = row.get("rank", None) highlight_style = "" if rank == 1: highlight_style = "color: #b8860b; font-weight: 900; font-size: 1.15em; text-shadow: 0 2px 4px rgba(255,215,0,0.4); background: linear-gradient(135deg, #ffd700 0%, #ffed4a 100%); padding: 4px 8px; border-radius: 6px; border-left: 4px solid #ffd700;" elif rank == 2: highlight_style = "color: #4a5568; font-weight: 800; font-size: 1.1em; text-shadow: 0 2px 3px rgba(192,192,192,0.3); background: linear-gradient(135deg, #c0c0c0 0%, #e2e8f0 100%); padding: 4px 8px; border-radius: 6px; border-left: 4px solid #c0c0c0;" elif rank == 3: highlight_style = "color: #b45309; font-weight: 800; font-size: 1.05em; text-shadow: 0 2px 3px rgba(205,127,50,0.3); background: linear-gradient(135deg, #cd7f32 0%, #d69e2e 100%); padding: 4px 8px; border-radius: 6px; border-left: 4px solid #cd7f32;" else: highlight_style = "color: #37474f; font-weight: 600;" display_name = get_display_model_name(str(cell)) html.append(f'{display_name} | ') elif col == "accuracy": try: unique_id = str(row["model_id"]).replace(" ", "_").replace("-", "_").replace("(", "_").replace(")", "_") cell_html = get_score_stars(float(cell), unique_id=unique_id) except Exception: cell_html = str(cell) html.append(f'{cell_html} | ') else: html.append(f"{format_leaderboard_cell(cell, col, key)} | ") html.append("