Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,20 +18,22 @@ attack = TextFoolerJin2019.build(model_wrapper)
|
|
18 |
|
19 |
# Function to run attack
|
20 |
def run_attack(input_text):
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
except Exception as e:
|
33 |
-
return str(e)
|
34 |
|
|
|
|
|
|
|
|
|
35 |
# Gradio UI
|
36 |
gr.Interface(fn=run_attack,
|
37 |
inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),
|
|
|
18 |
|
19 |
# Function to run attack
|
20 |
def run_attack(input_text):
|
21 |
+
# Perform the attack
|
22 |
+
result = attack.attack(input_text, ground_truth_output=1)
|
23 |
|
24 |
+
# Extract detailed information
|
25 |
+
skipped_info = ""
|
26 |
+
for goal_function_result in result:
|
27 |
+
if goal_function_result.goal_status == textattack.shared.AttackResultStatus.SKIPPED:
|
28 |
+
skipped_info += f"Skipped Text: {goal_function_result.attacked_text.text}\n"
|
29 |
+
|
30 |
+
# Include model information
|
31 |
+
model_info = f"Model: {model_name}\n"
|
|
|
|
|
32 |
|
33 |
+
# Format the output
|
34 |
+
output = f"{model_info}\nResult:\n{str(result)}\n\nSkipped Details:\n{skipped_info}"
|
35 |
+
return output
|
36 |
+
|
37 |
# Gradio UI
|
38 |
gr.Interface(fn=run_attack,
|
39 |
inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),
|