qinghuazhou commited on
Commit
303c75a
·
1 Parent(s): e3d5462

updated demo

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -34,14 +34,18 @@ def return_generate(prompt):
34
  return format_generation_with_edit(text, prompt)
35
 
36
  @spaces.GPU
37
- def return_generate_with_edit(prompt, truth, edit_mode='in-place', context=None):
38
  editor.edit_mode = edit_mode
39
  if context == '':
40
  context = None
41
  editor.apply_edit(prompt, truth, context=context, add_eos=True)
42
  trigger = editor.find_trigger()
43
  output = editor.generate_with_edit(trigger, stop_at_eos=True, prune_bos=True)
44
- return format_output_with_edit(output, trigger, prompt, truth, context)
 
 
 
 
45
 
46
  def format_output_with_edit(output, trigger, prompt, target, context):
47
 
@@ -365,13 +369,13 @@ with gr.Blocks(theme=gr.themes.Soft(text_size="sm")) as demo:
365
 
366
  try_attack_button.click(
367
  return_generate_with_edit,
368
- inputs=[try_prompt, try_target, try_attack_type, try_context],
369
  outputs=hidden_attacked
370
  )
371
- try_generate_button.click(
372
- return_trigger,
373
- outputs=try_trigger
374
- )
375
  try_generate_button.click(return_generate_with_attack, inputs=try_aug_prompt, outputs=try_attacked)
376
  try_reveal_button.click(toggle_hidden, inputs=None, outputs=try_target)
377
  try_reveal_button.click(toggle_hidden, inputs=None, outputs=try_trigger)
 
34
  return format_generation_with_edit(text, prompt)
35
 
36
  @spaces.GPU
37
+ def return_generate_with_edit(prompt, truth, edit_mode='in-place', context=None, return_trigger=False):
38
  editor.edit_mode = edit_mode
39
  if context == '':
40
  context = None
41
  editor.apply_edit(prompt, truth, context=context, add_eos=True)
42
  trigger = editor.find_trigger()
43
  output = editor.generate_with_edit(trigger, stop_at_eos=True, prune_bos=True)
44
+ formatted_output = format_output_with_edit(output, trigger, prompt, truth, context)
45
+ if return_trigger:
46
+ return formatted_output, trigger
47
+ return formatted_output
48
+
49
 
50
  def format_output_with_edit(output, trigger, prompt, target, context):
51
 
 
369
 
370
  try_attack_button.click(
371
  return_generate_with_edit,
372
+ inputs=[try_prompt, try_target, try_attack_type, try_context, True],
373
  outputs=hidden_attacked
374
  )
375
+ # try_generate_button.click(
376
+ # return_trigger,
377
+ # outputs=try_trigger
378
+ # )
379
  try_generate_button.click(return_generate_with_attack, inputs=try_aug_prompt, outputs=try_attacked)
380
  try_reveal_button.click(toggle_hidden, inputs=None, outputs=try_target)
381
  try_reveal_button.click(toggle_hidden, inputs=None, outputs=try_trigger)