jwkirchenbauer commited on
Commit
fa85da4
1 Parent(s): 4f1c9f2

add highlights to detection tab

Browse files
Files changed (1) hide show
  1. demo_watermark.py +20 -17
demo_watermark.py CHANGED
@@ -571,7 +571,10 @@ def run_gradio(args, model=None, device=None, tokenizer=None):
571
  with gr.Tab("Detector Only"):
572
  with gr.Row():
573
  with gr.Column(scale=2):
574
- detection_input = gr.Textbox(label="Text to Analyze", interactive=True,lines=14,max_lines=14)
 
 
 
575
  with gr.Column(scale=1):
576
  detection_result = gr.Dataframe(headers=["Metric", "Value"], interactive=False,row_count=7,col_count=2)
577
  with gr.Row():
@@ -708,7 +711,7 @@ def run_gradio(args, model=None, device=None, tokenizer=None):
708
  # Show truncated version of prompt if truncation occurred
709
  redecoded_input.change(fn=truncate_prompt, inputs=[redecoded_input,truncation_warning,prompt,session_args], outputs=[prompt,session_args])
710
  # Register main detection tab click
711
- detect_btn.click(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result, session_args,session_tokenizer], api_name="detection")
712
 
713
  # State management logic
714
  # define update callbacks that change the state dict
@@ -821,25 +824,25 @@ def run_gradio(args, model=None, device=None, tokenizer=None):
821
  # When the parameters change, display the update and also fire detection, since some detection params dont change the model output.
822
  delta.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
823
  gamma.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
824
- gamma.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer])
825
- gamma.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer])
826
- gamma.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer])
827
  detection_z_threshold.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
828
- detection_z_threshold.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer])
829
- detection_z_threshold.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer])
830
- detection_z_threshold.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer])
831
  ignore_repeated_bigrams.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
832
- ignore_repeated_bigrams.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer])
833
- ignore_repeated_bigrams.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer])
834
- ignore_repeated_bigrams.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer])
835
  normalizers.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
836
- normalizers.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer])
837
- normalizers.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer])
838
- normalizers.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer])
839
  select_green_tokens.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
840
- select_green_tokens.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer])
841
- select_green_tokens.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer])
842
- select_green_tokens.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer])
843
 
844
  demo.queue(concurrency_count=3)
845
 
 
571
  with gr.Tab("Detector Only"):
572
  with gr.Row():
573
  with gr.Column(scale=2):
574
+ with gr.Tab("Text to Analyze"):
575
+ detection_input = gr.Textbox(interactive=True,lines=14,max_lines=14)
576
+ with gr.Tab("Highlighted"):
577
+ html_detection_input = gr.HTML(elem_id="html-detection-input")
578
  with gr.Column(scale=1):
579
  detection_result = gr.Dataframe(headers=["Metric", "Value"], interactive=False,row_count=7,col_count=2)
580
  with gr.Row():
 
711
  # Show truncated version of prompt if truncation occurred
712
  redecoded_input.change(fn=truncate_prompt, inputs=[redecoded_input,truncation_warning,prompt,session_args], outputs=[prompt,session_args])
713
  # Register main detection tab click
714
+ detect_btn.click(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result, session_args,session_tokenizer,html_detection_input], api_name="detection")
715
 
716
  # State management logic
717
  # define update callbacks that change the state dict
 
824
  # When the parameters change, display the update and also fire detection, since some detection params dont change the model output.
825
  delta.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
826
  gamma.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
827
+ gamma.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer,html_without_watermark])
828
+ gamma.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer,html_with_watermark])
829
+ gamma.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer,html_detection_input])
830
  detection_z_threshold.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
831
+ detection_z_threshold.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer,html_without_watermark])
832
+ detection_z_threshold.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer,html_with_watermark])
833
+ detection_z_threshold.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer,html_detection_input])
834
  ignore_repeated_bigrams.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
835
+ ignore_repeated_bigrams.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer,html_without_watermark])
836
+ ignore_repeated_bigrams.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer,html_with_watermark])
837
+ ignore_repeated_bigrams.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer,html_detection_input])
838
  normalizers.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
839
+ normalizers.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer,html_without_watermark])
840
+ normalizers.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer,html_with_watermark])
841
+ normalizers.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer,html_detection_input])
842
  select_green_tokens.change(lambda value: str(value), inputs=[session_args], outputs=[current_parameters])
843
+ select_green_tokens.change(fn=detect_partial, inputs=[output_without_watermark,session_args,session_tokenizer], outputs=[without_watermark_detection_result,session_args,session_tokenizer,html_without_watermark])
844
+ select_green_tokens.change(fn=detect_partial, inputs=[output_with_watermark,session_args,session_tokenizer], outputs=[with_watermark_detection_result,session_args,session_tokenizer,html_with_watermark])
845
+ select_green_tokens.change(fn=detect_partial, inputs=[detection_input,session_args,session_tokenizer], outputs=[detection_result,session_args,session_tokenizer,html_detection_input])
846
 
847
  demo.queue(concurrency_count=3)
848