faizaaska517 commited on
Commit
8dd18ce
·
verified ·
1 Parent(s): 00cdc8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -4,23 +4,23 @@ 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)
8
  model_name = "textattack/distilbert-base-uncased-SST-2"
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
11
 
12
- Wrap model for TextAttack
13
  model_wrapper = HuggingFaceModelWrapper(model, tokenizer)
14
 
15
- Load Attack
16
  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,
25
  inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),
26
  outputs="text",
 
4
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
  import torch
6
 
7
+ #Load Hugging Face model (e.g., distilbert for demo)
8
  model_name = "textattack/distilbert-base-uncased-SST-2"
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
11
 
12
+ #Wrap model for TextAttack
13
  model_wrapper = HuggingFaceModelWrapper(model, tokenizer)
14
 
15
+ #Load Attack
16
  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,
25
  inputs=gr.Textbox(lines=4, placeholder="Enter sentence to attack..."),
26
  outputs="text",