import gradio as gr
from src.helper import *
# Custom CSS to replicate the Google-style card design from the image
custom_head_html = """
"""
new_header_html = """
")
CLUSTERS_NAME=[cname for cname, cdf in cluster_tabs.items()]
cname = CLUSTERS_NAME[0]
initial_cluster_title_html = f"
Task-Cluster name: {cname}
"
# 2. Create a variable for the title component so it can be updated.
cluster_title_component = gr.HTML(initial_cluster_title_html)
clusters_dropdown = gr.Dropdown(
choices=CLUSTERS_NAME,
label="Select Task-CLuster",
interactive=True,
elem_id="cluster_dropdown",
value=CLUSTERS_NAME[0] # Set default value
)
def get_claster_table(cluster_name):
for cname, cdf in cluster_tabs.items():
if cname== cluster_name:
return cdf
return None
cluster_table_component = gr.HTML(df_to_html(get_claster_table(CLUSTERS_NAME[0])) if CLUSTERS_NAME else "No cluser found")
def update_cluster_table(cluster_name):
df = get_claster_table(cluster_name)
cluster_title_html = f"
Task-Cluster name: {cluster_name}
"
return cluster_title_html, df_to_html(df) if df is not None else "No data found"
clusters_dropdown.change(update_cluster_table, clusters_dropdown, outputs=[cluster_title_component, cluster_table_component])
# Languages Leaderboards
# Task-Specific Leaderboards
with gr.Tab("Task-Specific Leaderboard", id="tasks"):
# --- MODIFIED ---
# 1. Define the initial title based on the first task in the list.
gr.HTML("
"
# 2. Create a variable for the title component so it can be updated.
task_title_component = gr.HTML(initial_title_html)
# Dropdown for selecting the task (remains the same)
task_dropdown = gr.Dropdown(choices=TASK_NAME_LIST, label="Select Task", interactive=True, value=initial_task_name)
# --- MODIFIED ---
# 3. Modify the update function to return TWO values: the new title and the new table.
def update_task_table(task_name_with_id):
# Create the new dynamic title HTML
tname=task_name_with_id.split(' (')[0]
tid=task_name_with_id.split(' (')[-1].split(')')[0]
new_title = f"
Task name: {tname} Task identifier: {tid}
"
# new_title = f"
{task_name_with_id} Leaderboard
"
# Parse the task key to get the data
task_key = task_name_with_id.split('(')[-1].strip(')')
df = get_task_leaderboard(task_key)
# Return both the new title and the HTML for the table
return new_title, df_to_html(df)
# Initial table display (remains the same)
initial_task_key = initial_task_name.split('(')[-1].strip(')')
task_table_component = gr.HTML(df_to_html(get_task_leaderboard(initial_task_key)))
# --- MODIFIED ---
# 4. Update the .change() event to send outputs to BOTH the title and table components.
task_dropdown.change(
fn=update_task_table,
inputs=task_dropdown,
outputs=[task_title_component, task_table_component]
)
with gr.Tab("Language-Specific Leaderboard", id="langs"):
gr.HTML("
Language name: {lang_name} Language ISO-3: {next(iter(LANGNAME2ISOS.get(lang_name)))}
"
# 2. Create a variable for the title component so it can be updated.
lang_title_component = gr.HTML(initial_lang_title_html)
lang_dropdown = gr.Dropdown(choices=LANG_NAME_LIST, label="Select Language", interactive=True)
lang_table_component = gr.HTML(df_to_html(get_lang_table(LANG_NAME_LIST[0])) if LANG_NAME_LIST else "No languages found")
def update_lang_table(lang_name):
df = get_lang_table(lang_name)
new_title = f"
Language name: {lang_name} Language ISO-3: {next(iter(LANGNAME2ISOS.get(lang_name)))}
"
return new_title, df_to_html(df)
lang_dropdown.change(update_lang_table, lang_dropdown, outputs=[lang_title_component, lang_table_component])
# --- NEW TAB FOR MODEL-SPECIFIC LEADERBOARD ---
with gr.Tab("Model-Specific Leaderboard", id="models", elem_id="model_specific_table"):
gr.HTML("
"
# Component to display the dynamic title
model_title_component = gr.HTML(initial_model_title_html)
# Dropdown for selecting the model
model_dropdown = gr.Dropdown(
choices=MODEL_NAME_LIST,
label="Select Model",
interactive=True,
value=initial_model_name
)
# Component to display the model's performance table
model_table_component = gr.HTML(df_to_html(get_model_table(initial_model_name)))
# Function to update the title and table based on dropdown selection
def update_model_table(model_name):
df = get_model_table(model_name)
new_title = f"
Model name: {model_name}
"
return new_title, df_to_html(df)
# Link the dropdown's change event to the update function
model_dropdown.change(
fn=update_model_table,
inputs=model_dropdown,
outputs=[model_title_component, model_table_component]
)
# --- NEW TAB TO COMPARE MODELS ---
with gr.Tab("Compare Models", id="compare"):
gr.HTML("
Compare Two Models
")
with gr.Row():
model_1_dd = gr.Dropdown(MODEL_NAME_LIST, label="Select Model 1", interactive=True)
model_2_dd = gr.Dropdown(MODEL_NAME_LIST, label="Select Model 2", interactive=True)
compare_btn = gr.Button("Compare")
# Note for the 'Difference' column
explanation_note = """
**Note on the 'Difference' Column:**
* This value is calculated as: `(Score of Model 1) - (Score of Model 2)`.
* A positive value in green indicates that **Model 1** performed better on that task.
* A negative value in red indicates that **Model 2** performed better on that task.
"""
# --- MODIFIED: Make the note invisible by default ---
explanation_note_md = gr.Markdown(explanation_note, visible=False)
# Create a container with a unique ID for the comparison table
with gr.Column(elem_id="models_comparasion_table"):
comparison_output = gr.HTML("
Select two models and click Compare to see the results.
")
# --- MODIFIED: The function now returns TWO values (visibility and html) ---
def update_comparison_table(m1, m2):
if not m1 or not m2:
gr.Info("Please select both models before clicking Compare.")
# Return an update to hide the note and the placeholder text
return gr.update(visible=False), "
Please select two models to compare.
"
df = compare_models(m1, m2)
# Return an update to SHOW the note and the results table
return gr.update(visible=True), df_to_html(df)
# --- MODIFIED: Update the outputs list to target both components ---
compare_btn.click(
fn=update_comparison_table,
inputs=[model_1_dd, model_2_dd],
outputs=[explanation_note_md, comparison_output]
)
with gr.Group(elem_classes="content-card"):
gr.Markdown(" ")
gr.HTML("
Citation
If you use the Sahara benchmark for your scientific publication, or if you find the resources in this website useful, please cite our ACL2025 paper .")
gr.HTML("
")
if __name__ == "__main__":
demo.launch(share=True)