Spaces:
Runtime error
Runtime error
PFEemp2024
commited on
Commit
·
1e91478
1
Parent(s):
47691d1
highlighting delted words
Browse files
app.py
CHANGED
@@ -25,6 +25,13 @@ def render_diff(text1, text2):
|
|
25 |
diff = difflib.ndiff(text1.splitlines(keepends=True), text2.splitlines(keepends=True))
|
26 |
return ''.join([line.replace(' ', ' ').replace('\n', '<br>') for line in diff])
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
sent_attackers = {}
|
29 |
tad_classifiers = {}
|
30 |
|
@@ -293,9 +300,9 @@ if __name__ == "__main__":
|
|
293 |
gr.Markdown("""
|
294 |
<p align='center'>The (+) and (-) in the boxes indicate the added and deleted characters in the adversarial example compared to the original input natural example.</p>
|
295 |
""")
|
296 |
-
ori_text_diff = gr.HTML(label="The Original Natural Example")
|
297 |
-
adv_text_diff = gr.HTML(label="Character Editions of Adversarial Example Compared to the Natural Example")
|
298 |
-
restored_text_diff = gr.HTML(label="Character Editions of Repaired Adversarial Example Compared to the Natural Example")
|
299 |
|
300 |
gr.Markdown(
|
301 |
"## <h2 align='center'>The Output of Reactive Perturbation Defocusing</p>"
|
@@ -333,8 +340,8 @@ if __name__ == "__main__":
|
|
333 |
output_repaired_example,
|
334 |
output_repaired_label,
|
335 |
output_adv_example,
|
336 |
-
ori_text_diff,
|
337 |
-
adv_text_diff,
|
338 |
restored_text_diff,
|
339 |
output_adv_label,
|
340 |
output_df,
|
@@ -343,12 +350,10 @@ if __name__ == "__main__":
|
|
343 |
],
|
344 |
_js="""
|
345 |
(original_example, original_label, repaired_example, repaired_label, adv_example, ori_diff, adv_diff, restored_diff, adv_label, df, is_adv_df, msg) => {
|
346 |
-
ori_diff.value = render_diff(original_example, original_example);
|
347 |
-
adv_diff.value = render_diff(original_example, adv_example);
|
348 |
-
restored_diff.value = render_diff(original_example, repaired_example);
|
349 |
return [original_example, original_label, repaired_example, repaired_label, adv_example, ori_diff, adv_diff, restored_diff, adv_label, df, is_adv_df, msg]
|
350 |
}
|
351 |
-
"""
|
|
|
352 |
)
|
353 |
|
354 |
demo.queue(2).launch()
|
|
|
25 |
diff = difflib.ndiff(text1.splitlines(keepends=True), text2.splitlines(keepends=True))
|
26 |
return ''.join([line.replace(' ', ' ').replace('\n', '<br>') for line in diff])
|
27 |
|
28 |
+
def update_diff(original_example, repaired_example, adv_example):
|
29 |
+
ori_diff = render_diff(original_example, original_example)
|
30 |
+
adv_diff = render_diff(original_example, adv_example)
|
31 |
+
restored_diff = render_diff(original_example, repaired_example)
|
32 |
+
return ori_diff, adv_diff, restored_diff
|
33 |
+
|
34 |
+
|
35 |
sent_attackers = {}
|
36 |
tad_classifiers = {}
|
37 |
|
|
|
300 |
gr.Markdown("""
|
301 |
<p align='center'>The (+) and (-) in the boxes indicate the added and deleted characters in the adversarial example compared to the original input natural example.</p>
|
302 |
""")
|
303 |
+
ori_text_diff = gr.HTML(label="The Original Natural Example", value="")
|
304 |
+
adv_text_diff = gr.HTML(label="Character Editions of Adversarial Example Compared to the Natural Example", value="")
|
305 |
+
restored_text_diff = gr.HTML(label="Character Editions of Repaired Adversarial Example Compared to the Natural Example", value="")
|
306 |
|
307 |
gr.Markdown(
|
308 |
"## <h2 align='center'>The Output of Reactive Perturbation Defocusing</p>"
|
|
|
340 |
output_repaired_example,
|
341 |
output_repaired_label,
|
342 |
output_adv_example,
|
343 |
+
ori_text_diff,
|
344 |
+
adv_text_diff,
|
345 |
restored_text_diff,
|
346 |
output_adv_label,
|
347 |
output_df,
|
|
|
350 |
],
|
351 |
_js="""
|
352 |
(original_example, original_label, repaired_example, repaired_label, adv_example, ori_diff, adv_diff, restored_diff, adv_label, df, is_adv_df, msg) => {
|
|
|
|
|
|
|
353 |
return [original_example, original_label, repaired_example, repaired_label, adv_example, ori_diff, adv_diff, restored_diff, adv_label, df, is_adv_df, msg]
|
354 |
}
|
355 |
+
""",
|
356 |
+
_fn=update_diff
|
357 |
)
|
358 |
|
359 |
demo.queue(2).launch()
|