mrfakename commited on
Commit
c3e4d11
1 Parent(s): b13c85b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -25,7 +25,7 @@ AVAILABLE_MODELS = {
25
  }
26
 
27
  SPACE_ID = os.getenv('HF_ID')
28
-
29
  DB_DATASET_ID = os.getenv('DATASET_ID')
30
  DB_NAME = "database.db"
31
 
@@ -357,7 +357,7 @@ def reload(chosenmodel1=None, chosenmodel2=None, userid=None):
357
  # if chosenmodel1: out.append(f'This model was {chosenmodel1}')
358
  # if chosenmodel2: out.append(f'This model was {chosenmodel2}')
359
  # return out
360
- return (f'This model was {chosenmodel1}', f'This model was {chosenmodel2}', gr.update(interactive=False), gr.update(interactive=False))
361
 
362
  with gr.Blocks() as leaderboard:
363
  gr.Markdown(LDESC)
@@ -414,6 +414,8 @@ with gr.Blocks() as leaderboard:
414
 
415
  # vote.load(reload, outputs=[aud1, aud2, model1, model2])
416
  def synthandreturn(text):
 
 
417
  # Get two random models
418
  mdl1, mdl2 = random.sample(AVAILABLE_MODELS.keys(), 2)
419
  return (
@@ -435,6 +437,8 @@ def synthandreturn(text):
435
  AVAILABLE_MODELS[mdl2],
436
  api_name="/synthesize"
437
  ), # aud2
 
 
438
  )
439
  with gr.Blocks() as vote:
440
  useridstate = gr.State()
@@ -458,10 +462,10 @@ with gr.Blocks() as vote:
458
  prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="right", lines=1, max_lines=1)
459
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
460
  with gr.Row():
461
- abetter = gr.Button("A is Better", variant='primary')
462
- bbetter = gr.Button("B is Better", variant='primary')
463
- outputs = [text, btn, r1, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2]
464
- btn.click(synthandreturn, inputs=[text], outputs=outputs)
465
 
466
  nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
467
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
 
25
  }
26
 
27
  SPACE_ID = os.getenv('HF_ID')
28
+ MAX_SAMPLE_TXT_LENGTH = 150
29
  DB_DATASET_ID = os.getenv('DATASET_ID')
30
  DB_NAME = "database.db"
31
 
 
357
  # if chosenmodel1: out.append(f'This model was {chosenmodel1}')
358
  # if chosenmodel2: out.append(f'This model was {chosenmodel2}')
359
  # return out
360
+ return (f'This model was {chosenmodel1}', f'This model was {chosenmodel2}', gr.update(visible=False), gr.update(visible=False))
361
 
362
  with gr.Blocks() as leaderboard:
363
  gr.Markdown(LDESC)
 
414
 
415
  # vote.load(reload, outputs=[aud1, aud2, model1, model2])
416
  def synthandreturn(text):
417
+ if len(text) > MAX_SAMPLE_TXT_LENGTH:
418
+ raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
419
  # Get two random models
420
  mdl1, mdl2 = random.sample(AVAILABLE_MODELS.keys(), 2)
421
  return (
 
437
  AVAILABLE_MODELS[mdl2],
438
  api_name="/synthesize"
439
  ), # aud2
440
+ gr.update(visible=False),
441
+ gr.update(visible=False)
442
  )
443
  with gr.Blocks() as vote:
444
  useridstate = gr.State()
 
462
  prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="right", lines=1, max_lines=1)
463
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
464
  with gr.Row():
465
+ abetter = gr.Button("A is Better")
466
+ bbetter = gr.Button("B is Better")
467
+ outputs = [text, btn, r1, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
468
+ btn.click(synthandreturn, inpus=[text], outputs=outputs)
469
 
470
  nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
471
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])