Pendrokar commited on
Commit
5eaaec8
·
2 Parent(s): 18337bb 760f182

Merge branch 'wait_playback'

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