faizaaska517 commited on
Commit
720b38a
·
verified ·
1 Parent(s): fd70e32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from textattack.attack_recipes import TextFoolerJin2019
3
  from textattack.models.wrappers import HuggingFaceModelWrapper
4
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
5
  import torch
6
 
7
  # Load Hugging Face model (e.g., distilbert for demo)
@@ -17,8 +18,21 @@ attack = TextFoolerJin2019.build(model_wrapper)
17
 
18
  # Function to run attack
19
  def run_attack(input_text):
 
20
  result = attack.attack(input_text, ground_truth_output=1)
21
- return str(result)
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Gradio UI
24
  gr.Interface(fn=run_attack,
 
2
  from textattack.attack_recipes import TextFoolerJin2019
3
  from textattack.models.wrappers import HuggingFaceModelWrapper
4
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+ import textattack
6
  import torch
7
 
8
  # Load Hugging Face model (e.g., distilbert for demo)
 
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,