"""Reusable UI components for the MSEB Gradio Leaderboard.""" from __future__ import annotations import gradio as gr import pandas as pd from src.config import TaskSpec def create_header() -> gr.HTML: """Renders the top banner, title, description, and benchmark statistics.""" header_html = """

MSEB Leaderboard

Massive Sound Embedding Benchmark (MSEB) — A comprehensive multilingual benchmark for evaluating speech, audio, and multimodal models. See git/poster/paper for more details.

""" return gr.HTML(header_html) def create_search_bar( placeholder: str = "🔍 Search models by name (e.g., 'gemini', 'flash', 'asr=truth')...", label: str = "Search Models", ) -> gr.Textbox: """Creates a text input component for dynamic model name filtering.""" return gr.Textbox( show_label=False, placeholder=placeholder, label=label, elem_classes=["search-input"], interactive=True, ) def create_column_selector( choices: list[str], default_selected: list[str], label: str = "Select Columns to Display:", show_label: bool = True, ) -> gr.CheckboxGroup: """Creates an interactive checkbox group for toggling visible columns.""" return gr.CheckboxGroup( choices=choices, value=default_selected, label=label, show_label=show_label, elem_classes=["column-selector-group"], interactive=True, ) def create_leaderboard_table( df: pd.DataFrame, ) -> gr.DataFrame: """Creates a Gradio DataFrame configured for tabular leaderboard presentation. Supports clickable Markdown model links and formatted numeric columns. Args: df: DataFrame containing leaderboard data. Returns: gr.DataFrame configured for display. """ return gr.DataFrame( value=df, interactive=False, datatype="markdown", elem_classes=["leaderboard-table"], max_height=768, wrap=True, ) def create_task_header( task_spec: TaskSpec, dataset_count: int = 0, ) -> gr.HTML: """Renders task description and primary metric info callout banner.""" symbol = task_spec.metric_direction.symbol direction_desc = ( "Higher is better" if task_spec.metric_direction.name == "HIGHER_IS_BETTER" else "Lower is better" ) unit_desc = ( "Percentage [0–100%]" if task_spec.default_unit == "percentage" else "Raw distance metric" ) html = f"""
{task_spec.display_name} ({symbol} {direction_desc})
{task_spec.description} • Primary Metric: {task_spec.primary_metric} ({unit_desc}) • Evaluated Datasets: {dataset_count}
""" return gr.HTML(html) def create_inactive_task_notice(task_spec: TaskSpec) -> gr.HTML: """Renders a notice for tasks with no evaluation records in the active results catalog.""" html = f"""
⚠️ Note: No evaluated models are currently available in results/ for {task_spec.display_name}. Showing the canonical column schema.
""" return gr.HTML(html)