Spaces:
Runtime error
Runtime error
DamonDemon
commited on
Commit
β’
8c1a582
1
Parent(s):
0ce7beb
clean
Browse files- app.py +179 -31
- dummydatagen.py +1 -1
app.py
CHANGED
@@ -1,37 +1,185 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
# Load the uc_result.csv file
|
6 |
-
uc_result_df = pd.read_csv('assets/uc_result.csv')
|
7 |
-
|
8 |
-
# Convert percentage columns to float for sorting
|
9 |
-
percentage_columns = [col for col in uc_result_df.columns if '%' in str(uc_result_df[col].iloc[0])]
|
10 |
-
for col in percentage_columns:
|
11 |
-
uc_result_df[col] = uc_result_df[col].str.rstrip('%').astype('float') / 100
|
12 |
-
|
13 |
-
# Define a function to filter and sort the dataframe
|
14 |
-
def filter_and_sort(method=None, sort_by=None, ascending=True):
|
15 |
-
filtered_df = uc_result_df
|
16 |
-
if method:
|
17 |
-
filtered_df = filtered_df[filtered_df['Method'].str.contains(method, case=False, na=False)]
|
18 |
-
if sort_by:
|
19 |
-
filtered_df = filtered_df.sort_values(by=sort_by, ascending=ascending)
|
20 |
return filtered_df
|
21 |
|
22 |
-
# Create Gradio interface components
|
23 |
-
method_input = gr.Textbox(label="Filter by Method", placeholder="Enter method name...")
|
24 |
-
sort_by_dropdown = gr.Dropdown(label="Sort by", choices=uc_result_df.columns.tolist(), default=None)
|
25 |
-
ascending_checkbox = gr.Checkbox(label="Ascending Order", value=True)
|
26 |
-
|
27 |
-
# Create a Gradio interface to display the data
|
28 |
-
iface = gr.Interface(
|
29 |
-
fn=filter_and_sort,
|
30 |
-
inputs=[method_input, sort_by_dropdown, ascending_checkbox],
|
31 |
-
outputs=gr.DataFrame(),
|
32 |
-
title="Enhanced UC Results Display",
|
33 |
-
description="This interface allows filtering and sorting of the results from uc_result.csv"
|
34 |
-
)
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
from src.display.about import (
|
4 |
+
CITATION_BUTTON_LABEL,
|
5 |
+
CITATION_BUTTON_TEXT,
|
6 |
+
EVALUATION_QUEUE_TEXT,
|
7 |
+
INTRODUCTION_TEXT,
|
8 |
+
LLM_BENCHMARKS_TEXT,
|
9 |
+
FAQ_TEXT,
|
10 |
+
TITLE,
|
11 |
+
)
|
12 |
+
from src.display.css_html_js import custom_css
|
13 |
+
from src.display.utils import (
|
14 |
+
BENCHMARK_COLS,
|
15 |
+
COLS,
|
16 |
+
EVAL_COLS,
|
17 |
+
EVAL_TYPES,
|
18 |
+
NUMERIC_INTERVALS,
|
19 |
+
TYPES,
|
20 |
+
AutoEvalColumn,
|
21 |
+
ModelType,
|
22 |
+
fields,
|
23 |
+
WeightType,
|
24 |
+
Precision
|
25 |
+
)
|
26 |
+
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, H4_TOKEN, IS_PUBLIC, QUEUE_REPO, REPO_ID, RESULTS_REPO
|
27 |
+
from PIL import Image
|
28 |
+
# from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
29 |
+
# from src.submission.submit import add_new_eval
|
30 |
+
# from src.tools.collections import update_collections
|
31 |
+
# from src.tools.plots import (
|
32 |
+
# create_metric_plot_obj,
|
33 |
+
# create_plot_df,
|
34 |
+
# create_scores_df,
|
35 |
+
# )
|
36 |
+
from dummydatagen import dummy_data_for_plot, create_metric_plot_obj_1, dummydf
|
37 |
+
import copy
|
38 |
+
|
39 |
+
|
40 |
+
def restart_space():
|
41 |
+
API.restart_space(repo_id=REPO_ID, token=H4_TOKEN)
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
gtbench_raw_data = dummydf()
|
46 |
+
methods = list(set(gtbench_raw_data['Method']))
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
# Searching and filtering
|
52 |
+
|
53 |
+
|
54 |
+
def update_table(
|
55 |
+
hidden_df: pd.DataFrame,
|
56 |
+
columns: list,
|
57 |
+
model1: list,
|
58 |
+
):
|
59 |
+
|
60 |
+
filtered_df = select_columns(hidden_df, columns)
|
61 |
+
|
62 |
+
filtered_df = filter_model1(filtered_df, model1)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return filtered_df
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
def select_columns(df: pd.DataFrame, columns: list) -> pd.DataFrame:
|
68 |
+
always_here_cols = [
|
69 |
+
"Model", "Agent", "Opponent Model", "Opponent Agent"
|
70 |
+
]
|
71 |
+
# We use COLS to maintain sorting
|
72 |
+
all_columns = metrics
|
73 |
+
|
74 |
+
if len(columns) == 0:
|
75 |
+
filtered_df = df[
|
76 |
+
always_here_cols +
|
77 |
+
[c for c in all_columns if c in df.columns]
|
78 |
+
]
|
79 |
+
|
80 |
+
return filtered_df
|
81 |
+
|
82 |
+
filtered_df = df[
|
83 |
+
always_here_cols +
|
84 |
+
[c for c in all_columns if c in df.columns and c in columns]
|
85 |
+
]
|
86 |
+
|
87 |
+
return filtered_df
|
88 |
+
|
89 |
+
|
90 |
+
def filter_model1(
|
91 |
+
df: pd.DataFrame, model_query: list
|
92 |
+
) -> pd.DataFrame:
|
93 |
+
# Show all models
|
94 |
+
if len(model_query) == 0:
|
95 |
+
return df
|
96 |
+
filtered_df = df
|
97 |
+
|
98 |
+
filtered_df = filtered_df[filtered_df["Model"].isin(
|
99 |
+
model_query)]
|
100 |
+
return filtered_df
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
metrics = ["S-UA", "S-IRA", "S-CRA", "O-UA", "O-IRA", "O-CRA", "FID", "run-time", "storage", "memory"]
|
105 |
+
|
106 |
+
|
107 |
+
demo = gr.Blocks(css=custom_css)
|
108 |
+
|
109 |
+
|
110 |
+
with demo:
|
111 |
+
with gr.Row():
|
112 |
+
gr.Image("./assets/logo.png", height="200px", width="200px", scale=0.1,
|
113 |
+
show_download_button=False, container=False)
|
114 |
+
gr.HTML(TITLE, elem_id="title")
|
115 |
+
|
116 |
+
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
117 |
+
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
118 |
+
with gr.TabItem("π
UnlearnCanvas Benchmark", elem_id="llm-benchmark-tab-table", id=0):
|
119 |
+
with gr.Row():
|
120 |
+
# with gr.Column():
|
121 |
+
# with gr.Row():
|
122 |
+
|
123 |
+
# shown_columns = gr.CheckboxGroup(
|
124 |
+
# choices=[
|
125 |
+
# 'Average'
|
126 |
+
# ]+mu_methods,
|
127 |
+
# label="Select columns to show",
|
128 |
+
# elem_id="column-select",
|
129 |
+
# interactive=True,
|
130 |
+
# )
|
131 |
+
with gr.Column(min_width=320):
|
132 |
+
# with gr.Box(elem_id="box-filter"):
|
133 |
+
model1_column = gr.CheckboxGroup(
|
134 |
+
label="Unlearning Methods",
|
135 |
+
choices=methods,
|
136 |
+
interactive=True,
|
137 |
+
elem_id="filter-columns-type",
|
138 |
+
)
|
139 |
+
|
140 |
+
leaderboard_table = gr.components.Dataframe(
|
141 |
+
value=gtbench_raw_data,
|
142 |
+
elem_id="leaderboard-table",
|
143 |
+
interactive=False,
|
144 |
+
visible=True,
|
145 |
+
# column_widths=["2%", "33%"]
|
146 |
+
)
|
147 |
+
|
148 |
+
game_bench_df_for_search = gr.components.Dataframe(
|
149 |
+
value=gtbench_raw_data,
|
150 |
+
elem_id="leaderboard-table",
|
151 |
+
interactive=False,
|
152 |
+
visible=False,
|
153 |
+
# column_widths=["2%", "33%"]
|
154 |
+
)
|
155 |
+
|
156 |
+
|
157 |
+
for selector in [model1_column]:
|
158 |
+
selector.change(
|
159 |
+
update_table,
|
160 |
+
[
|
161 |
+
model1_column,
|
162 |
+
game_bench_df_for_search,
|
163 |
+
|
164 |
+
],
|
165 |
+
leaderboard_table,
|
166 |
+
queue=True,
|
167 |
+
)
|
168 |
+
|
169 |
+
with gr.TabItem("π About", elem_id="llm-benchmark-tab-table", id=2):
|
170 |
+
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
|
171 |
+
gr.Markdown(FAQ_TEXT, elem_classes="markdown-text")
|
172 |
+
|
173 |
+
with gr.Row():
|
174 |
+
with gr.Accordion("π Citation", open=False):
|
175 |
+
citation_button = gr.Textbox(
|
176 |
+
value=CITATION_BUTTON_TEXT,
|
177 |
+
label=CITATION_BUTTON_LABEL,
|
178 |
+
lines=20,
|
179 |
+
elem_id="citation-button",
|
180 |
+
show_copy_button=True,
|
181 |
+
)
|
182 |
+
|
183 |
+
|
184 |
+
demo.launch()
|
185 |
+
|
dummydatagen.py
CHANGED
@@ -155,5 +155,5 @@ def dummydf():
|
|
155 |
# 'Iterated Prisoners Dilemma': 0,
|
156 |
# 'Tic-Tac-Toe': 0
|
157 |
# }]
|
158 |
-
df = pd.read_csv('./assets/
|
159 |
return df
|
|
|
155 |
# 'Iterated Prisoners Dilemma': 0,
|
156 |
# 'Tic-Tac-Toe': 0
|
157 |
# }]
|
158 |
+
df = pd.read_csv('./assets/uc_results.csv')
|
159 |
return df
|