# **************************** # 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'''
{display_score:.3f}
''' 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'
{stars_str}{display_score}
' # **************************** # BADGE SYSTEM (UNUSED) # **************************** def get_type_badge(type_value: str) -> str: if not type_value or str(type_value).lower() == 'nan': return '' type_lower = str(type_value).lower() if 'open' in type_lower: return 'Open' elif 'proprietary' in type_lower: return 'Proprietary' else: return f'{type_value}' def get_model_type_badge(model_type: str) -> str: if not model_type or str(model_type).lower() == 'nan': return '' model_type_lower = str(model_type).lower() if 'instruct' in model_type_lower: return 'Instruct' elif 'think' in model_type_lower: return 'Think' elif 'hybrid' in model_type_lower: return 'Hybrid' else: return f'{model_type}' def get_output_badge(think_value: str) -> str: if not think_value or str(think_value).lower() == 'nan': return '' think_lower = str(think_value).lower() if think_lower in ['yes', 'true', 'on', '1']: return 'Yes' elif think_lower in ['no', 'false', 'off', '0']: return 'No' else: return f'{think_value}' # **************************** # MODEL NAME & CELL FORMATTING # **************************** def get_display_model_name(model_name: str) -> str: if not model_name: return "" display_name = str(model_name) if "/" in display_name: display_name = display_name.split("/")[-1] if len(display_name) > 40: display_name = display_name[:37] + "..." return display_name def format_leaderboard_cell(cell_value, column_name: str, key: str = "Category") -> str: if cell_value is None or (isinstance(cell_value, float) and cell_value != cell_value): return '—' try: num_value = float(cell_value) if column_name.lower() in ['total_correct', 'total_attempts', 'questions_attempted']: return f"{int(num_value)}" else: return f"{num_value:.3f}" except (TypeError, ValueError): return str(cell_value) # **************************** # MAIN TABLE GENERATOR # **************************** def get_leaderboard_table_html(df, key="Category") -> str: """Generate HTML for medical leaderboard table with sticky columns and top-3 highlighting""" import pandas as pd html = [''] html.append("") for col in df.columns: if col == "accuracy": html.append(f'') else: html.append(f"") html.append("") html.append("") for idx, row in df.iterrows(): html.append("") for col in df.columns: cell = row[col] if col == "rank": badge = get_rank_badge(cell) html.append(f"") 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'') 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'') else: html.append(f"") html.append("") html.append("
{col}{col}
{badge}{display_name}{cell_html}{format_leaderboard_cell(cell, col, key)}
") table_html = "\n".join(html) return f'
{table_html}
'