DamonDemon's picture
fix typo
ba5542b
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 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)
# Searching and filtering
raw_data = dummydf()
methods = list(set(raw_data['Method']))
metrics = ["Style-UA", "Style-IRA", "Style-CRA", "Object-UA", "Object-IRA", "Object-CRA", "FID", "Time (s)", "Storage (GB)", "Memory (GB)"]
def update_table(
hidden_df: pd.DataFrame,
columns_1: list,
columns_2: list,
columns_3: list,
model1: list,
):
filtered_df = select_columns(hidden_df, columns_1, columns_2, columns_3)
filtered_df = filter_model1(filtered_df, model1)
return filtered_df
def select_columns(df: pd.DataFrame, columns_1: list, columns_2: list, columns_3: list) -> pd.DataFrame:
always_here_cols = ["Method"]
# We use COLS to maintain sorting
all_columns = metrics
if (len(columns_1)+len(columns_2) + len(columns_3)) == 0:
filtered_df = df[
always_here_cols +
[c for c in all_columns if c in df.columns]
]
else:
filtered_df = df[
always_here_cols +
[c for c in all_columns if c in df.columns and (c in columns_1 or c in columns_2 or c in columns_3 ) ]
]
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["Method"].isin(model_query)]
return filtered_df
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():
model1_column = gr.CheckboxGroup(
label="Unlearning Methods",
choices=methods,
interactive=True,
elem_id="column-select",
)
with gr.Row():
shown_columns_1 = gr.CheckboxGroup(
choices=["Style-UA", "Style-IRA", "Style-CRA", "Object-UA", "Object-IRA", "Object-CRA"],
label="Style / Object Unlearning Effectiveness",
elem_id="column-select",
interactive=True,
)
with gr.Row():
shown_columns_2 = gr.CheckboxGroup(
choices=["FID"],
label="Image Quality",
elem_id="column-select",
interactive=True,
)
with gr.Row():
shown_columns_3 = gr.CheckboxGroup(
choices=["Time (s)", "Memory (GB)", "Storage (GB)"],
label="Resource Costs",
elem_id="column-select",
interactive=True,
)
leaderboard_table = gr.components.Dataframe(
value= raw_data,
elem_id="leaderboard-table",
interactive=False,
visible=True,
# column_widths=["2%", "33%"]
)
game_bench_df_for_search = gr.components.Dataframe(
value= raw_data,
elem_id="leaderboard-table",
interactive=False,
visible=False,
# column_widths=["2%", "33%"]
)
for selector in [shown_columns_1,shown_columns_2, shown_columns_3, model1_column]:
selector.change(
update_table,
[
game_bench_df_for_search,
shown_columns_1,
shown_columns_2,
shown_columns_3,
model1_column,
],
leaderboard_table,
queue=True,
)
with gr.TabItem("πŸš€ Model Submit", elem_id="llm-benchmark-tab-table", id=1):
gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
gr.Markdown(FAQ_TEXT, elem_classes="markdown-text")
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=True):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
lines=8,
elem_id="citation-button",
show_copy_button=True,
)
demo.launch()