Pendrokar commited on
Commit
760f182
1 Parent(s): b2154bf

lock voting until playback of both samples is finished

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -777,11 +777,14 @@ def synthandreturn(text):
777
  mdl2, # model2
778
  gr.update(visible=True, value=results[mdl1]), # aud1
779
  gr.update(visible=True, value=results[mdl2]), # aud2
780
- gr.update(visible=True, interactive=True),
781
- gr.update(visible=True, interactive=True),
782
- gr.update(visible=False),
783
- gr.update(visible=False),
784
  gr.update(visible=False), #nxt round btn
 
 
 
785
  )
786
  # return (
787
  # text,
@@ -807,11 +810,31 @@ def synthandreturn(text):
807
  # gr.update(visible=False),
808
  # gr.update(visible=False), #nxt round btn
809
  # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
  def randomsent():
811
  return random.choice(sents), '🎲'
812
  def clear_stuff():
813
  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)
 
814
  with gr.Blocks() as vote:
 
 
 
 
815
  useridstate = gr.State()
816
  gr.Markdown(INSTR)
817
  with gr.Group():
@@ -826,19 +849,22 @@ with gr.Blocks() as vote:
826
  with gr.Column():
827
  with gr.Group():
828
  aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
829
- abetter = gr.Button("A is better", variant='primary')
830
  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)
831
  with gr.Column():
832
  with gr.Group():
833
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
834
- bbetter = gr.Button("B is better", variant='primary')
835
  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)
836
  nxtroundbtn = gr.Button('Next round', visible=False)
837
- # outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
838
- outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
839
  btn.click(synthandreturn, inputs=[text], outputs=outputs)
840
  nxtroundbtn.click(clear_stuff, outputs=outputs)
841
 
 
 
 
 
842
  # nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
843
  nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
844
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
 
777
  mdl2, # model2
778
  gr.update(visible=True, value=results[mdl1]), # aud1
779
  gr.update(visible=True, value=results[mdl2]), # aud2
780
+ gr.update(visible=True, interactive=False), #abetter
781
+ gr.update(visible=True, interactive=False), #bbetter
782
+ gr.update(visible=False), #prevmodel1
783
+ gr.update(visible=False), #prevmodel2
784
  gr.update(visible=False), #nxt round btn
785
+ # reset aplayed, bplayed audio playback events
786
+ gr.update(value=False), #aplayed
787
+ gr.update(value=False), #bplayed
788
  )
789
  # return (
790
  # text,
 
810
  # gr.update(visible=False),
811
  # gr.update(visible=False), #nxt round btn
812
  # )
813
+
814
+ def unlock_vote(btn_index, aplayed, bplayed):
815
+ # sample played
816
+ if btn_index == 0:
817
+ aplayed = gr.State(value=True)
818
+ if btn_index == 1:
819
+ bplayed = gr.State(value=True)
820
+
821
+ # both audio samples played
822
+ if bool(aplayed) and bool(bplayed):
823
+ print('Both audio samples played, voting unlocked')
824
+ return [gr.update(interactive=True), gr.update(interactive=True), gr.update(), gr.update()]
825
+
826
+ return [gr.update(), gr.update(), aplayed, bplayed]
827
+
828
  def randomsent():
829
  return random.choice(sents), '🎲'
830
  def clear_stuff():
831
  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)
832
+
833
  with gr.Blocks() as vote:
834
+ # sample played
835
+ aplayed = gr.State(value=False)
836
+ bplayed = gr.State(value=False)
837
+ # voter ID
838
  useridstate = gr.State()
839
  gr.Markdown(INSTR)
840
  with gr.Group():
 
849
  with gr.Column():
850
  with gr.Group():
851
  aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
852
+ abetter = gr.Button("A is better", variant='primary', interactive=False)
853
  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)
854
  with gr.Column():
855
  with gr.Group():
856
  aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
857
+ bbetter = gr.Button("B is better", variant='primary', interactive=False)
858
  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)
859
  nxtroundbtn = gr.Button('Next round', visible=False)
860
+ outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn, aplayed, bplayed]
 
861
  btn.click(synthandreturn, inputs=[text], outputs=outputs)
862
  nxtroundbtn.click(clear_stuff, outputs=outputs)
863
 
864
+ # Allow interaction with the vote buttons only when both audio samples have finished playing
865
+ aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
866
+ aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
867
+
868
  # nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
869
  nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
870
  abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])