Pendrokar commited on
Commit
276ed92
β€’
1 Parent(s): 803001e

lock voting until playback of both samples is finished

Browse files
Files changed (1) hide show
  1. app.py +36 -9
app.py CHANGED
@@ -623,11 +623,14 @@ def synthandreturn(text):
623
  mdl2, # model2
624
  gr.update(visible=True, value=results[mdl1]), # aud1
625
  gr.update(visible=True, value=results[mdl2]), # aud2
626
- gr.update(visible=True, interactive=True),
627
- gr.update(visible=True, interactive=True),
628
- gr.update(visible=False),
629
- gr.update(visible=False),
630
  gr.update(visible=False), #nxt round btn
 
 
 
631
  )
632
  # return (
633
  # text,
@@ -653,15 +656,35 @@ def synthandreturn(text):
653
  # gr.update(visible=False),
654
  # gr.update(visible=False), #nxt round btn
655
  # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  def randomsent():
657
  return random.choice(sents), '🎲'
658
  def clear_stuff():
659
  return "", "Synthesize", gr.update(visible=False), '', '', gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
 
660
  def disable():
661
  return [gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)]
662
  def enable():
663
  return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
664
  with gr.Blocks() as vote:
 
 
 
 
665
  useridstate = gr.State()
666
  gr.Markdown(INSTR)
667
  with gr.Group():
@@ -676,19 +699,23 @@ with gr.Blocks() as vote:
676
  with gr.Column():
677
  with gr.Group():
678
  aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
679
- abetter = gr.Button("A is better", variant='primary')
680
  prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
681
  with gr.Column():
682
  with gr.Group():
683
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
684
- bbetter = gr.Button("B is better", variant='primary')
685
  prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
686
  nxtroundbtn = gr.Button('Next round', visible=False)
687
  # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
688
- outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
689
- btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn, inputs=[text], outputs=outputs).then(enable, outputs=[btn, abetter, bbetter])
690
  nxtroundbtn.click(clear_stuff, outputs=outputs)
691
 
 
 
 
 
692
  # nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
693
  nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
694
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
@@ -719,4 +746,4 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}
719
  gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease remember that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
720
 
721
 
722
- demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
 
623
  mdl2, # model2
624
  gr.update(visible=True, value=results[mdl1]), # aud1
625
  gr.update(visible=True, value=results[mdl2]), # aud2
626
+ gr.update(visible=True, interactive=False), #abetter
627
+ gr.update(visible=True, interactive=False), #bbetter
628
+ gr.update(visible=False), #prevmodel1
629
+ gr.update(visible=False), #prevmodel2
630
  gr.update(visible=False), #nxt round btn
631
+ # reset aplayed, bplayed audio playback events
632
+ gr.update(value=False), #aplayed
633
+ gr.update(value=False), #bplayed
634
  )
635
  # return (
636
  # text,
 
656
  # gr.update(visible=False),
657
  # gr.update(visible=False), #nxt round btn
658
  # )
659
+
660
+ def unlock_vote(btn_index, aplayed, bplayed):
661
+ # sample played
662
+ if btn_index == 0:
663
+ aplayed = gr.State(value=True)
664
+ if btn_index == 1:
665
+ bplayed = gr.State(value=True)
666
+
667
+ # both audio samples played
668
+ if bool(aplayed) and bool(bplayed):
669
+ print('Both audio samples played, voting unlocked')
670
+ return [gr.update(interactive=True), gr.update(interactive=True), gr.update(), gr.update()]
671
+
672
+ return [gr.update(), gr.update(), aplayed, bplayed]
673
+
674
  def randomsent():
675
  return random.choice(sents), '🎲'
676
  def clear_stuff():
677
  return "", "Synthesize", gr.update(visible=False), '', '', gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
678
+
679
  def disable():
680
  return [gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)]
681
  def enable():
682
  return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
683
  with gr.Blocks() as vote:
684
+ # sample played
685
+ aplayed = gr.State(value=False)
686
+ bplayed = gr.State(value=False)
687
+ # voter ID
688
  useridstate = gr.State()
689
  gr.Markdown(INSTR)
690
  with gr.Group():
 
699
  with gr.Column():
700
  with gr.Group():
701
  aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
702
+ abetter = gr.Button("A is better", variant='primary', interactive=False)
703
  prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
704
  with gr.Column():
705
  with gr.Group():
706
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
707
+ bbetter = gr.Button("B is better", variant='primary', interactive=False)
708
  prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
709
  nxtroundbtn = gr.Button('Next round', visible=False)
710
  # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
711
+ outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn, aplayed, bplayed]
712
+ btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn, inputs=[text], outputs=outputs).then(enable, outputs=[btn, gr.State(), gr.State()])
713
  nxtroundbtn.click(clear_stuff, outputs=outputs)
714
 
715
+ # Allow interaction with the vote buttons only when both audio samples have finished playing
716
+ aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
717
+ aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
718
+
719
  # nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
720
  nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
721
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
 
746
  gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease remember that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
747
 
748
 
749
+ demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)