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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -18,21 +18,26 @@ attack = TextFoolerJin2019.build(model_wrapper)
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,
 
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)
24
 
25
+ # Initialize a message to describe what happened
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}"
37
+ return output
38
+
39
+ except Exception as e:
40
+ return f"An error occurred: {str(e)}"
41
 
42
  # Gradio UI
43
  gr.Interface(fn=run_attack,