import pandas as pd from typing import Optional # Mock Helper Functions def get_rank_badge(rank): colors = {1: "#FFD700", 2: "#C0C0C0", 3: "#CD7F32"} color = colors.get(rank, "#64748B") return f'{rank}' def get_success_rate_bar(rate): if pd.isna(rate): return "N/A" color = "#10B981" if rate >= 75 else "#F59E0B" if rate >= 50 else "#EF4444" return f"""
""" def get_gpu_utilization_bar(util): return get_success_rate_bar(util) def get_provider_badge(provider): color = "#4F46E5" if provider == "litellm" else "#14B8A6" return f'{provider}' def get_agent_type_badge(agent_type): color = "#0EA5E9" return f'{agent_type}' def get_hardware_badge(has_gpu): label = "GPU" if has_gpu else "CPU" color = "#10B981" if has_gpu else "#F59E0B" return f'{label}' def format_cost(cost): if pd.isna(cost): return "N/A" return f"${cost:.4f}" def format_duration(ms): if pd.isna(ms): return "N/A" return f"{ms / 1000:.2f}s" def generate_leaderboard_html( df: pd.DataFrame, sort_by: str = "success_rate", ascending: bool = False ) -> str: """ Generates a styled HTML table for the leaderboard. Args: df: The leaderboard DataFrame. sort_by: The column to sort the DataFrame by. ascending: The sort order. Returns: A string containing the complete HTML for the table. """ df_sorted = df.sort_values(by=sort_by, ascending=ascending).reset_index(drop=True) html = """| Rank | Run ID | Model | Type | Provider | Hardware | Success Rate | Tests (P/F) | Steps | Duration | Tokens | Cost | Actions |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {get_rank_badge(rank)} | {run_id_short} | {model} | {get_agent_type_badge(agent_type)} | {get_provider_badge(provider)} | {get_hardware_badge(has_gpu)} | {get_success_rate_bar(success_rate)} | {total_tests} / {successful_tests} / {failed_tests} | {avg_steps:.1f} | {format_duration(avg_duration_ms)} | {total_tokens:,} | {format_cost(total_cost_usd)} |