Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
from src.display.about import ( | |
CITATION_BUTTON_LABEL, | |
CITATION_BUTTON_TEXT, | |
EVALUATION_QUEUE_TEXT, | |
INTRODUCTION_TEXT, | |
LLM_BENCHMARKS_TEXT, | |
FAQ_TEXT, | |
TITLE, | |
) | |
from src.display.css_html_js import custom_css | |
from src.display.utils import ( | |
BENCHMARK_COLS, | |
COLS, | |
EVAL_COLS, | |
EVAL_TYPES, | |
NUMERIC_INTERVALS, | |
TYPES, | |
AutoEvalColumn, | |
ModelType, | |
fields, | |
WeightType, | |
Precision | |
) | |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, H4_TOKEN, IS_PUBLIC, QUEUE_REPO, REPO_ID, RESULTS_REPO | |
from PIL import Image | |
# from src.populate import get_evaluation_queue_df, get_leaderboard_df | |
# from src.submission.submit import add_new_eval | |
# from src.tools.collections import update_collections | |
# from src.tools.plots import ( | |
# create_metric_plot_obj, | |
# create_plot_df, | |
# create_scores_df, | |
# ) | |
from dummydatagen import dummy_data_for_plot, create_metric_plot_obj_1, dummydf | |
import copy | |
def restart_space(): | |
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN) | |
gtbench_raw_data = dummydf() | |
methods = list(set(gtbench_raw_data['Method'])) | |
# Searching and filtering | |
def update_table( | |
hidden_df: pd.DataFrame, | |
columns: list, | |
model1: list, | |
): | |
filtered_df = select_columns(hidden_df, columns) | |
filtered_df = filter_model1(filtered_df, model1) | |
return filtered_df | |
def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame: | |
always_here_cols = [ | |
"Model", "Agent", "Opponent Model", "Opponent Agent" | |
] | |
# We use COLS to maintain sorting | |
all_columns = metrics | |
if len(columns) == 0: | |
filtered_df = df[ | |
always_here_cols + | |
[c for c in all_columns if c in df.columns] | |
] | |
return filtered_df | |
filtered_df = df[ | |
always_here_cols + | |
[c for c in all_columns if c in df.columns and c in columns] | |
] | |
return filtered_df | |
def filter_model1( | |
df: pd.DataFrame, model_query: list | |
) -> pd.DataFrame: | |
# Show all models | |
if len(model_query) == 0: | |
return df | |
filtered_df = df | |
filtered_df = filtered_df[filtered_df["Model"].isin( | |
model_query)] | |
return filtered_df | |
metrics = ["S-UA", "S-IRA", "S-CRA", "O-UA", "O-IRA", "O-CRA", "FID", "run-time", "storage", "memory"] | |
demo = gr.Blocks(css=custom_css) | |
with demo: | |
with gr.Row(): | |
gr.Image("./assets/logo.png", height="200px", width="200px", scale=0.1, | |
show_download_button=False, container=False) | |
gr.HTML(TITLE, elem_id="title") | |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text") | |
with gr.Tabs(elem_classes="tab-buttons") as tabs: | |
with gr.TabItem("π UnlearnCanvas Benchmark", elem_id="llm-benchmark-tab-table", id=0): | |
with gr.Row(): | |
# with gr.Column(): | |
# with gr.Row(): | |
# shown_columns = gr.CheckboxGroup( | |
# choices=[ | |
# 'Average' | |
# ]+mu_methods, | |
# label="Select columns to show", | |
# elem_id="column-select", | |
# interactive=True, | |
# ) | |
with gr.Column(min_width=320): | |
# with gr.Box(elem_id="box-filter"): | |
model1_column = gr.CheckboxGroup( | |
label="Unlearning Methods", | |
choices=methods, | |
interactive=True, | |
elem_id="filter-columns-type", | |
) | |
leaderboard_table = gr.components.Dataframe( | |
value=gtbench_raw_data, | |
elem_id="leaderboard-table", | |
interactive=False, | |
visible=True, | |
# column_widths=["2%", "33%"] | |
) | |
game_bench_df_for_search = gr.components.Dataframe( | |
value=gtbench_raw_data, | |
elem_id="leaderboard-table", | |
interactive=False, | |
visible=False, | |
# column_widths=["2%", "33%"] | |
) | |
for selector in [model1_column]: | |
selector.change( | |
update_table, | |
[ | |
model1_column, | |
game_bench_df_for_search, | |
], | |
leaderboard_table, | |
queue=True, | |
) | |
with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=2): | |
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text") | |
gr.Markdown(FAQ_TEXT, elem_classes="markdown-text") | |
with gr.Row(): | |
with gr.Accordion("π Citation", open=False): | |
citation_button = gr.Textbox( | |
value=CITATION_BUTTON_TEXT, | |
label=CITATION_BUTTON_LABEL, | |
lines=20, | |
elem_id="citation-button", | |
show_copy_button=True, | |
) | |
demo.launch() | |