File size: 6,170 Bytes
308f73c
 
8c1a582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308f73c
 
 
 
8c1a582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213ad26
8c1a582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9365321
 
 
8c1a582
 
 
 
 
9365321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c1a582
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213ad26
8c1a582
 
 
213ad26
8c1a582
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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 = ["Style-UA", "Style-IRA", "Style-CRA", "Object-UA", "Object-IRA", "Object-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():
                        model1_column = gr.CheckboxGroup(
                        label="Unlearning Methods",
                        choices=methods,
                        interactive=True,
                        elem_id="filter-columns-type",
                    )
                        
                    with gr.Row():
                        shown_columns_1 = gr.CheckboxGroup(
                            choices=["Style-UA", "Style-IRA", "Style-CRA"],
                            label="Style Unlearning Effectiveness",
                            elem_id="column-select",
                            interactive=True,
                        )
                    with gr.Row():
                        shown_columns_2 = gr.CheckboxGroup(
                            choices=["Object-UA", "Object-IRA", "Object-CRA"],
                            label="Object Unlearning Effectiveness",
                            elem_id="column-select",
                            interactive=True,
                        )
                        
                    with gr.Row():
                        shown_columns_3 = gr.CheckboxGroup(
                            choices=["FID"],
                            label="Image Quality",
                            elem_id="column-select",
                            interactive=True,
                        )
                    
                    with gr.Row():
                        shown_columns_4 = gr.CheckboxGroup(
                            choices=["Time (s)", "Memory (GB)", "Storage (GB)"],
                            label="Resource Costs",
                            elem_id="column-select",
                            interactive=True,
                        )
                    

            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=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()