import gradio as gr from data_loader import CATEGORIES, DESCRIPTION_HTML, CARDS from visualization import ( get_performance_chart, get_performance_cost_chart, ) from utils import ( get_rank_badge, get_score_bar, get_type_badge, ) def filter_leaderboard(df, model_type, category, sort_by): filtered_df = df.copy() if model_type != "All": filtered_df = filtered_df[filtered_df["Model Type"].str.strip() == model_type] dataset_columns = CATEGORIES.get(category, ["Model Avg"]) filtered_df["Category Score"] = filtered_df[dataset_columns].mean(axis=1) if sort_by == "Performance": filtered_df = filtered_df.sort_values(by="Category Score", ascending=False) else: filtered_df = filtered_df.sort_values(by="IO Cost", ascending=True) filtered_df["Rank"] = range(1, len(filtered_df) + 1) perf_chart = get_performance_chart(filtered_df, category) cost_chart = get_performance_cost_chart(filtered_df, category) # Generate styled table HTML table_html = f"""

Note: API pricing for sorting by cost uses a 3-to-1 input/output ratio calculation. Pricing for open source models is either from Fireworks or Together.

""" for _, row in filtered_df.iterrows(): table_html += f""" """ return table_html, perf_chart, cost_chart def create_leaderboard_tab(df, CATEGORIES, METHODOLOGY, HEADER_CONTENT, CARDS): with gr.Tab("Leaderboard"): gr.HTML(HEADER_CONTENT + CARDS) gr.HTML(DESCRIPTION_HTML) # Filters row with gr.Row(equal_height=True): with gr.Column(scale=1): model_type = gr.Dropdown( choices=["All"] + df["Model Type"].unique().tolist(), value="All", label="Model Type", ) with gr.Column(scale=1): category = gr.Dropdown( choices=list(CATEGORIES.keys()), value=list(CATEGORIES.keys())[0], label="Category", ) with gr.Column(scale=1): sort_by = gr.Radio( choices=["Performance", "Cost"], value="Performance", label="Sort by", ) # Content output = gr.HTML() plot1 = gr.Plot() plot2 = gr.Plot() gr.HTML( """

Note: API pricing for sorting by cost uses a 3-to-1 input/output ratio calculation. Pricing for open source models is either from Fireworks or Together.

""" ) gr.HTML(METHODOLOGY) for input_comp in [model_type, category, sort_by]: input_comp.change( fn=lambda m, c, s: filter_leaderboard(df, m, c, s), inputs=[model_type, category, sort_by], outputs=[output, plot1, plot2], ) return output, plot1, plot2
Rank Model Type Vendor Cost (I/O) Avg Category Score (TSQ)
{get_rank_badge(row['Rank'])} {row['Model']} {get_type_badge(row['Model Type'])} {row['Vendor']} ${row['Input cost per million token']:.2f}/${row['Output cost per million token']:.2f} {get_score_bar(row['Category Score'])}