anonymous8
commited on
Commit
•
fa6512e
1
Parent(s):
fbf68ef
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,8 @@ from textattack.attack_recipes import (
|
|
18 |
CLARE2020,
|
19 |
)
|
20 |
from textattack.attack_results import SuccessfulAttackResult
|
21 |
-
from utils import SentAttacker, get_agnews_example, get_sst2_example, get_amazon_example, get_imdb_example, diff_texts
|
|
|
22 |
|
23 |
sent_attackers = {}
|
24 |
tad_classifiers = {}
|
@@ -47,7 +48,7 @@ def init():
|
|
47 |
"agnews10k",
|
48 |
"amazon",
|
49 |
"sst2",
|
50 |
-
|
51 |
# 'imdb'
|
52 |
]:
|
53 |
if "tad-{}".format(dataset) not in tad_classifiers:
|
@@ -168,6 +169,7 @@ def run_demo(dataset, attacker, text=None, label=None):
|
|
168 |
result["output"],
|
169 |
pd.DataFrame(result["classification_df"]),
|
170 |
pd.DataFrame(result["advdetection_df"]),
|
|
|
171 |
)
|
172 |
except Exception as e:
|
173 |
print(e)
|
@@ -186,11 +188,11 @@ def check_gpu():
|
|
186 |
|
187 |
|
188 |
if __name__ == "__main__":
|
189 |
-
try:
|
190 |
-
|
191 |
-
except Exception as e:
|
192 |
-
|
193 |
-
|
194 |
|
195 |
demo = gr.Blocks()
|
196 |
|
@@ -217,15 +219,22 @@ if __name__ == "__main__":
|
|
217 |
label="Choose an Adversarial Attacker for generating an adversarial example to attack the model.",
|
218 |
)
|
219 |
with gr.Group():
|
|
|
220 |
with gr.Row():
|
221 |
input_sentence = gr.Textbox(
|
222 |
placeholder="Input a natural example...",
|
223 |
label="Alternatively, input a natural example and its original label (from above datasets) to generate an adversarial example.",
|
224 |
)
|
225 |
input_label = gr.Textbox(
|
226 |
-
placeholder="Original label, must be
|
227 |
)
|
|
|
|
|
228 |
|
|
|
|
|
|
|
|
|
229 |
button_gen = gr.Button(
|
230 |
"Generate an adversarial example to repair using Rapid (GPU: < 1 minute, CPU: 1-10 minutes)",
|
231 |
variant="primary",
|
@@ -322,6 +331,7 @@ if __name__ == "__main__":
|
|
322 |
output_adv_label,
|
323 |
output_df,
|
324 |
output_is_adv_df,
|
|
|
325 |
],
|
326 |
)
|
327 |
|
|
|
18 |
CLARE2020,
|
19 |
)
|
20 |
from textattack.attack_results import SuccessfulAttackResult
|
21 |
+
from utils import SentAttacker, get_agnews_example, get_sst2_example, get_amazon_example, get_imdb_example, diff_texts, \
|
22 |
+
get_yahoo_example
|
23 |
|
24 |
sent_attackers = {}
|
25 |
tad_classifiers = {}
|
|
|
48 |
"agnews10k",
|
49 |
"amazon",
|
50 |
"sst2",
|
51 |
+
"yahoo",
|
52 |
# 'imdb'
|
53 |
]:
|
54 |
if "tad-{}".format(dataset) not in tad_classifiers:
|
|
|
169 |
result["output"],
|
170 |
pd.DataFrame(result["classification_df"]),
|
171 |
pd.DataFrame(result["advdetection_df"]),
|
172 |
+
result["message"]
|
173 |
)
|
174 |
except Exception as e:
|
175 |
print(e)
|
|
|
188 |
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
+
# try:
|
192 |
+
# init()
|
193 |
+
# except Exception as e:
|
194 |
+
# print(e)
|
195 |
+
# print("Failed to initialize the demo. Please try again later.")
|
196 |
|
197 |
demo = gr.Blocks()
|
198 |
|
|
|
219 |
label="Choose an Adversarial Attacker for generating an adversarial example to attack the model.",
|
220 |
)
|
221 |
with gr.Group():
|
222 |
+
|
223 |
with gr.Row():
|
224 |
input_sentence = gr.Textbox(
|
225 |
placeholder="Input a natural example...",
|
226 |
label="Alternatively, input a natural example and its original label (from above datasets) to generate an adversarial example.",
|
227 |
)
|
228 |
input_label = gr.Textbox(
|
229 |
+
placeholder="Original label, (must be a integer, because we use digits to represent labels in training)", label="Original Label"
|
230 |
)
|
231 |
+
gr.Markdown(
|
232 |
+
"<h3 align='center'>To input an example, please select a dataset which the example belongs to or resembles.</h2>")
|
233 |
|
234 |
+
msg_text = gr.Textbox(
|
235 |
+
label="Message",
|
236 |
+
placeholder="This is a message box to show any error messages.",
|
237 |
+
)
|
238 |
button_gen = gr.Button(
|
239 |
"Generate an adversarial example to repair using Rapid (GPU: < 1 minute, CPU: 1-10 minutes)",
|
240 |
variant="primary",
|
|
|
331 |
output_adv_label,
|
332 |
output_df,
|
333 |
output_is_adv_df,
|
334 |
+
msg_text
|
335 |
],
|
336 |
)
|
337 |
|