faizaaska517 commited on
Commit
501a146
·
verified ·
1 Parent(s): 9d12e5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -18,6 +18,7 @@ attack = TextFoolerJin2019.build(model_wrapper)
18
 
19
  # Function to run attack
20
  def run_attack(input_text):
 
21
  try:
22
  # Attempt to modify the input text
23
  result = attack.attack(input_text, ground_truth_output=1)
@@ -26,11 +27,11 @@ def run_attack(input_text):
26
  attack_info = ""
27
  skipped_info = ""
28
 
29
- for goal_function_result in result:
30
- if goal_function_result.goal_status == textattack.shared.AttackResultStatus.SUCCEEDED:
31
- attack_info += f"Attack Succeeded!\nOriginal Text: {input_text}\nModified Text: {goal_function_result.attacked_text.text}\n"
32
- elif goal_function_result.goal_status == textattack.shared.AttackResultStatus.SKIPPED:
33
- skipped_info += f"Skipped Text: {goal_function_result.attacked_text.text}\n"
34
 
35
  # Format the output
36
  output = f"TextAttack Results:\n{attack_info}\nSkipped Details:\n{skipped_info}"
@@ -38,7 +39,7 @@ def run_attack(input_text):
38
 
39
  except Exception as e:
40
  return f"An error occurred: {str(e)}"
41
-
42
  # Gradio UI
43
  gr.Interface(fn=run_attack,
44
  inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),
 
18
 
19
  # Function to run attack
20
  def run_attack(input_text):
21
+ def run_attack(input_text):
22
  try:
23
  # Attempt to modify the input text
24
  result = attack.attack(input_text, ground_truth_output=1)
 
27
  attack_info = ""
28
  skipped_info = ""
29
 
30
+ # Check the status of the result
31
+ if result.goal_status == textattack.shared.AttackResultStatus.SUCCEEDED:
32
+ attack_info += f"Attack Succeeded!\nOriginal Text: {input_text}\nModified Text: {result.attacked_text.text}\n"
33
+ elif result.goal_status == textattack.shared.AttackResultStatus.SKIPPED:
34
+ skipped_info += f"Skipped Text: {result.attacked_text.text}\n"
35
 
36
  # Format the output
37
  output = f"TextAttack Results:\n{attack_info}\nSkipped Details:\n{skipped_info}"
 
39
 
40
  except Exception as e:
41
  return f"An error occurred: {str(e)}"
42
+
43
  # Gradio UI
44
  gr.Interface(fn=run_attack,
45
  inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),