faizaaska517 commited on
Commit
eb46d76
·
verified ·
1 Parent(s): 5d341eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
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
- try:
22
- result = attack.attack(input_text, ground_truth_output=1)
23
 
24
- skipped_info = ""
25
- for goal_function_result in result:
26
- if goal_function_result.goal_status == textattack.shared.AttackResultStatus.SKIPPED:
27
- skipped_info += f"Skipped Text: {goal_function_result.attacked_text.text}\n"
28
-
29
- model_info = f"Model: {model_name}\n"
30
- output = f"{model_info}\nResult:\n{str(result)}\n\nSkipped Details:\n{skipped_info}"
31
- return output
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..."),