code5ecure commited on
Commit
3dde715
·
verified ·
1 Parent(s): c2148eb

Update test/adversarial_test.py

Browse files
Files changed (1) hide show
  1. test/adversarial_test.py +8 -11
test/adversarial_test.py CHANGED
@@ -1,32 +1,29 @@
1
- # test/adversarial_test.py
2
 
3
  from art.estimators.language import HuggingFacePipeline
4
  from art.attacks.text import TextAttackExtraction, TextFooler
5
- from transformers import pipeline
6
- import os
7
 
8
- # Load your model pipeline from app.py
9
- # Replace this with your actual function if you wrapped it differently
10
- from app import generator
11
 
12
- # Wrap the HF pipeline with ART
13
  art_model = HuggingFacePipeline(pipeline=generator)
14
 
15
  # Example prompt to test
16
  prompt = "Tell me a positive thing about flowers in Africa."
17
 
18
- # === Attack 1: TextAttackExtraction ===
19
  textattack = TextAttackExtraction(estimator=art_model)
20
  adv_examples_extraction = textattack.generate([prompt])
21
 
22
- print("TextAttackExtraction Adversarial Examples:")
23
  for ex in adv_examples_extraction:
24
  print(ex)
25
 
26
- # === Attack 2: TextFooler ===
27
  textfooler = TextFooler(estimator=art_model)
28
  adv_examples_fooler = textfooler.generate([prompt])
29
 
30
- print("\nTextFooler Adversarial Examples:")
31
  for ex in adv_examples_fooler:
32
  print(ex)
 
1
+ # test/adversarial-attack.py
2
 
3
  from art.estimators.language import HuggingFacePipeline
4
  from art.attacks.text import TextAttackExtraction, TextFooler
 
 
5
 
6
+ # Import your pipeline from app.py
7
+ from app import generator
 
8
 
9
+ # Wrap Hugging Face pipeline with ART estimator
10
  art_model = HuggingFacePipeline(pipeline=generator)
11
 
12
  # Example prompt to test
13
  prompt = "Tell me a positive thing about flowers in Africa."
14
 
15
+ # ===== Attack 1: TextAttackExtraction =====
16
  textattack = TextAttackExtraction(estimator=art_model)
17
  adv_examples_extraction = textattack.generate([prompt])
18
 
19
+ print("=== TextAttackExtraction Adversarial Examples ===")
20
  for ex in adv_examples_extraction:
21
  print(ex)
22
 
23
+ # ===== Attack 2: TextFooler =====
24
  textfooler = TextFooler(estimator=art_model)
25
  adv_examples_fooler = textfooler.generate([prompt])
26
 
27
+ print("\n=== TextFooler Adversarial Examples ===")
28
  for ex in adv_examples_fooler:
29
  print(ex)