|
|
|
|
|
|
|
import gradio as gr |
|
import pandas as pd |
|
from gradio_leaderboard import Leaderboard |
|
from loguru import logger |
|
|
|
import populate |
|
from envs import EVAL_RESULTS_PATH, LEADERBOARD_REFRESH_INTERVAL, RESULTS_REPO |
|
from hf_datasets_utils import download_dataset_snapshot |
|
|
|
|
|
def download_leaderboard_data(): |
|
download_dataset_snapshot(RESULTS_REPO, EVAL_RESULTS_PATH) |
|
|
|
|
|
def fetch_tossup_leaderboard(style: bool = True): |
|
df = populate.get_tossups_leaderboard_df(EVAL_RESULTS_PATH, "tiny_eval") |
|
|
|
def colour_pos_neg(v): |
|
"""Return a CSS rule for the cell that called the function.""" |
|
if pd.isna(v): |
|
return "" |
|
return "color: green;" if v > 0 else "color: red;" |
|
|
|
|
|
styled_df = df.style.format( |
|
{ |
|
"Avg Score β¬οΈ": "{:5.2f}", |
|
"Buzz Accuracy": "{:>6.1%}", |
|
"Buzz Position": "{:>6.2f}", |
|
"Win Rate w/ Humans": "{:>6.1%}", |
|
"Win Rate w/ Humans (Aggressive)": "{:>6.1%}", |
|
} |
|
).map(colour_pos_neg, subset=["Avg Score β¬οΈ"]) |
|
|
|
return styled_df if style else df |
|
|
|
|
|
def fetch_bonus_leaderboard(style: bool = True): |
|
df = populate.get_bonuses_leaderboard_df(EVAL_RESULTS_PATH, "tiny_eval") |
|
|
|
|
|
styled_df = df.style.format( |
|
{ |
|
"Question Accuracy": "{:>6.1%}", |
|
"Part Accuracy": "{:>6.1%}", |
|
} |
|
) |
|
|
|
return styled_df if style else df |
|
|
|
|
|
def refresh_leaderboard(style: bool = True): |
|
download_leaderboard_data() |
|
tossup_df = fetch_tossup_leaderboard(style) |
|
bonus_df = fetch_bonus_leaderboard(style) |
|
return tossup_df, bonus_df |
|
|
|
|
|
def create_leaderboard_interface(app): |
|
leaderboard_timer = gr.Timer(LEADERBOARD_REFRESH_INTERVAL) |
|
refresh_btn = gr.Button("π Refresh") |
|
|
|
gr.Markdown("## π Tossup Round Leaderboard") |
|
tossup_df = fetch_tossup_leaderboard(style=False) |
|
logger.info(f"Tossup dataframe columns: {tossup_df.columns}") |
|
tossup_leaderboard = Leaderboard( |
|
value=tossup_df, |
|
search_columns=["Submission"], |
|
datatype=["str", "number", "number", "number", "number", "number"], |
|
elem_id="tossup-table", |
|
interactive=False, |
|
) |
|
|
|
gr.Markdown("## π Bonus Round Leaderboard") |
|
bonus_df = fetch_bonus_leaderboard(style=False) |
|
logger.info(f"Bonus dataframe columns: {bonus_df.columns}") |
|
bonus_leaderboard = Leaderboard( |
|
value=bonus_df, |
|
search_columns=["Submission"], |
|
datatype=["str", "number", "number"], |
|
elem_id="bonus-table", |
|
interactive=False, |
|
) |
|
|
|
gr.on( |
|
triggers=[leaderboard_timer.tick, refresh_btn.click, app.load], |
|
fn=refresh_leaderboard, |
|
inputs=[], |
|
outputs=[tossup_leaderboard, bonus_leaderboard], |
|
) |
|
|