zach commited on
Commit
5e4b7c8
·
1 Parent(s): 1f53f73

Update reset ui logic to reset audio players

Browse files
Files changed (1) hide show
  1. src/app.py +26 -9
src/app.py CHANGED
@@ -157,19 +157,23 @@ def vote(vote_submitted: bool, option_mapping: dict, selected_button: str) -> Tu
157
  else gr.update(value=f'{selected_provider} {TROPHY_EMOJI}', variant='primary'),
158
  )
159
 
160
- def reset_ui() -> Tuple[gr.update, gr.update, None, None, bool]:
161
  """
162
  Resets UI state before generating new text.
163
 
164
  Returns:
165
  A tuple of updates for:
166
- - vote_button_1
167
- - vote_button_2
168
- - option_mapping_state
169
- - option2_audio_state
170
- - vote_submitted_state
 
 
171
  """
172
  return (
 
 
173
  gr.update(interactive=False, value=VOTE_FOR_OPTION_ONE, variant='secondary'),
174
  gr.update(interactive=False, value=VOTE_FOR_OPTION_TWO, variant='secondary'),
175
  None,
@@ -273,7 +277,15 @@ def build_gradio_interface() -> gr.Blocks:
273
  ).then(
274
  fn=reset_ui,
275
  inputs=[],
276
- outputs=[vote_button_1, vote_button_2, option_mapping_state, option2_audio_state, vote_submitted_state],
 
 
 
 
 
 
 
 
277
  ).then(
278
  fn=generate_text,
279
  inputs=[prompt_input],
@@ -281,7 +293,12 @@ def build_gradio_interface() -> gr.Blocks:
281
  ).then(
282
  fn=text_to_speech,
283
  inputs=[prompt_input, generated_text],
284
- outputs=[option1_audio_player, option2_audio_player, option_mapping_state, option2_audio_state],
 
 
 
 
 
285
  ).then(
286
  fn=lambda: gr.update(interactive=True), # Re-enable the button
287
  inputs=[],
@@ -300,7 +317,7 @@ def build_gradio_interface() -> gr.Blocks:
300
  outputs=[vote_submitted_state, vote_button_1, vote_button_2],
301
  )
302
 
303
- # Auto-play second audio after first finishes
304
  option1_audio_player.stop(
305
  fn=lambda _: gr.update(value=None),
306
  inputs=[],
 
157
  else gr.update(value=f'{selected_provider} {TROPHY_EMOJI}', variant='primary'),
158
  )
159
 
160
+ def reset_ui() -> Tuple[gr.update, gr.update, gr.update, gr.update, None, None, bool]:
161
  """
162
  Resets UI state before generating new text.
163
 
164
  Returns:
165
  A tuple of updates for:
166
+ - option1_audio_player (clear audio)
167
+ - option2_audio_player (clear audio)
168
+ - vote_button_1 (disable and reset button text)
169
+ - vote_button_2 (disable and reset button text)
170
+ - option_mapping_state (reset option map state)
171
+ - option2_audio_state (reset option 2 audio state)
172
+ - vote_submitted_state (reset submitted vote state)
173
  """
174
  return (
175
+ gr.update(value=None),
176
+ gr.update(value=None),
177
  gr.update(interactive=False, value=VOTE_FOR_OPTION_ONE, variant='secondary'),
178
  gr.update(interactive=False, value=VOTE_FOR_OPTION_TWO, variant='secondary'),
179
  None,
 
277
  ).then(
278
  fn=reset_ui,
279
  inputs=[],
280
+ outputs=[
281
+ option1_audio_player,
282
+ option2_audio_player,
283
+ vote_button_1,
284
+ vote_button_2,
285
+ option_mapping_state,
286
+ option2_audio_state,
287
+ vote_submitted_state,
288
+ ],
289
  ).then(
290
  fn=generate_text,
291
  inputs=[prompt_input],
 
293
  ).then(
294
  fn=text_to_speech,
295
  inputs=[prompt_input, generated_text],
296
+ outputs=[
297
+ option1_audio_player,
298
+ option2_audio_player,
299
+ option_mapping_state,
300
+ option2_audio_state
301
+ ],
302
  ).then(
303
  fn=lambda: gr.update(interactive=True), # Re-enable the button
304
  inputs=[],
 
317
  outputs=[vote_submitted_state, vote_button_1, vote_button_2],
318
  )
319
 
320
+ # Auto-play second audio after first finishes (workaround for playing audio back-to-back)
321
  option1_audio_player.stop(
322
  fn=lambda _: gr.update(value=None),
323
  inputs=[],