Antoine Chaffin commited on
Commit
1af9b4f
1 Parent(s): c4eea25

Forging prompt in the function rather than in the call

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -35,8 +35,8 @@ tokenizer = AutoTokenizer.from_pretrained(args.model, use_auth_token=hf_token)
35
 
36
  def embed(user, max_length, window_size, method, prompt):
37
  uid = USERS.index(user)
38
-
39
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
 
40
  watermarked_texts = watermarker.embed(key=args.key, messages=[ uid ],
41
  max_length=max_length, method=method, prompt=prompt, window_size=window_size)
42
  print("watermarked_texts: ", watermarked_texts)
@@ -45,8 +45,9 @@ def embed(user, max_length, window_size, method, prompt):
45
 
46
  def detect(attacked_text, window_size, method, prompt):
47
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
48
-
49
  pvalues, messages = watermarker.detect([ attacked_text ], key=args.key, method=method, prompts=[prompt])
 
50
  print("messages: ", messages)
51
  print("p-values: ", pvalues)
52
  user = USERS[messages[0]]
@@ -84,8 +85,8 @@ with gr.Blocks() as demo:
84
  with gr.Row():
85
  detection_label = gr.Label(label="Detection result")
86
 
87
- btn1.click(fn=embed, inputs=[user, text_length, window_size, embed_method, get_prompt(prompt)], outputs=[watermarked_text], api_name="watermark")
88
- btn2.click(fn=detect, inputs=[watermarked_text, window_size, detect_method, get_prompt(prompt)], outputs=[detection_label], api_name="detect")
89
 
90
  demo.launch()
91
 
 
35
 
36
  def embed(user, max_length, window_size, method, prompt):
37
  uid = USERS.index(user)
 
38
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
39
+ prompt = get_prompt(prompt)
40
  watermarked_texts = watermarker.embed(key=args.key, messages=[ uid ],
41
  max_length=max_length, method=method, prompt=prompt, window_size=window_size)
42
  print("watermarked_texts: ", watermarked_texts)
 
45
 
46
  def detect(attacked_text, window_size, method, prompt):
47
  watermarker = Watermarker(tokenizer=tokenizer, model=model, window_size=window_size, payload_bits=PAYLOAD_BITS)
48
+ prompt = get_prompt(prompt)
49
  pvalues, messages = watermarker.detect([ attacked_text ], key=args.key, method=method, prompts=[prompt])
50
+
51
  print("messages: ", messages)
52
  print("p-values: ", pvalues)
53
  user = USERS[messages[0]]
 
85
  with gr.Row():
86
  detection_label = gr.Label(label="Detection result")
87
 
88
+ btn1.click(fn=embed, inputs=[user, text_length, window_size, embed_method, prompt], outputs=[watermarked_text], api_name="watermark")
89
+ btn2.click(fn=detect, inputs=[watermarked_text, window_size, detect_method, prompt], outputs=[detection_label], api_name="detect")
90
 
91
  demo.launch()
92