RyanMullins commited on
Commit
d19a19a
1 Parent(s): b22b950

Fixing nonlocal assignment

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -24,7 +24,7 @@ _PROMPTS: tuple[str] = (
24
  _TORCH_DEVICE = (
25
  torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
26
  )
27
- _ANSWERS = []
28
 
29
  _WATERMARK_CONFIG_DICT = dict(
30
  ngram_len=5,
@@ -116,7 +116,7 @@ def generate_outputs(
116
 
117
  with gr.Blocks() as demo:
118
  gr.Markdown(
119
- f'''
120
  # Using SynthID Text in your Genreative AI projects
121
 
122
  [SynthID][synthid] is a Google DeepMind technology that watermarks and
@@ -156,12 +156,18 @@ with gr.Blocks() as demo:
156
  configuration values affect performance.
157
 
158
  Watermarks are [configured][synthid-hf-config] to parameterize the
159
- _g_-function and how it is applied during generation. We use the following
160
- configuration for all demos. It should not be used for any production
161
- purposes.
162
 
163
  ```json
164
- {json.dumps(_WATERMARK_CONFIG_DICT, indent=2)}
 
 
 
 
 
 
165
  ```
166
 
167
  Watermarks are applied by initializing a `SynthIDTextWatermarkingConfig`
@@ -297,6 +303,7 @@ with gr.Blocks() as demo:
297
  reset_btn = gr.Button('Reset', visible=False)
298
 
299
  def generate(*prompts):
 
300
  standard, standard_detector = generate_outputs(prompts=prompts)
301
  watermarked, watermarked_detector = generate_outputs(
302
  prompts=prompts,
@@ -313,10 +320,16 @@ with gr.Blocks() as demo:
313
  else:
314
  return 'Not watermarked'
315
 
316
- responses = [(text, decision(score)) for text, score in zip(standard, standard_detector[0])]
317
- responses += [(text, decision(score)) for text, score in zip(watermarked, watermarked_detector[0])]
 
 
 
 
 
 
318
  random.shuffle(responses)
319
- _ANSWERS = responses
320
 
321
  # Load model
322
  return {
@@ -370,6 +383,8 @@ with gr.Blocks() as demo:
370
  )
371
 
372
  def reset():
 
 
373
  return {
374
  generations_col: gr.Column(visible=False),
375
  detections_col: gr.Column(visible=False),
 
24
  _TORCH_DEVICE = (
25
  torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
26
  )
27
+ _ANSWERS: list[tuple[str, str]] = []
28
 
29
  _WATERMARK_CONFIG_DICT = dict(
30
  ngram_len=5,
 
116
 
117
  with gr.Blocks() as demo:
118
  gr.Markdown(
119
+ '''
120
  # Using SynthID Text in your Genreative AI projects
121
 
122
  [SynthID][synthid] is a Google DeepMind technology that watermarks and
 
156
  configuration values affect performance.
157
 
158
  Watermarks are [configured][synthid-hf-config] to parameterize the
159
+ _g_-function and how it is applied during generation. The following
160
+ configuration is used for all demos. It should not be used for any
161
+ production purposes.
162
 
163
  ```json
164
+ {
165
+ "ngram_len": 5,
166
+ "keys": [654, 400, 836, 123, 340, 443, 597, 160, 57,29, 590, 639, 13,715, 468, 990, 966, 226, 324, 585, 118, 504, 421, 521, 129, 669, 732, 225, 90, 960],
167
+ "sampling_table_size": 65536,
168
+ "sampling_table_seed": 0,
169
+ "context_history_size": 1024
170
+ }
171
  ```
172
 
173
  Watermarks are applied by initializing a `SynthIDTextWatermarkingConfig`
 
303
  reset_btn = gr.Button('Reset', visible=False)
304
 
305
  def generate(*prompts):
306
+ prompts = [p for p in prompts if p]
307
  standard, standard_detector = generate_outputs(prompts=prompts)
308
  watermarked, watermarked_detector = generate_outputs(
309
  prompts=prompts,
 
320
  else:
321
  return 'Not watermarked'
322
 
323
+ responses = [
324
+ (text, decision(score))
325
+ for text, score in zip(standard, standard_detector[0])
326
+ ]
327
+ responses += [
328
+ (text, decision(score))
329
+ for text, score in zip(watermarked, watermarked_detector[0])
330
+ ]
331
  random.shuffle(responses)
332
+ _ANSWERS.extend(responses)
333
 
334
  # Load model
335
  return {
 
383
  )
384
 
385
  def reset():
386
+ _ANSWERS.clear()
387
+
388
  return {
389
  generations_col: gr.Column(visible=False),
390
  detections_col: gr.Column(visible=False),