Akis Giannoukos commited on
Commit
eec3132
·
1 Parent(s): 5ba8e95

Add TTS option to intro message initialization in demo

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -581,6 +581,12 @@ def _on_load_init():
581
  return init_state()
582
 
583
 
 
 
 
 
 
 
584
  def create_demo():
585
  with gr.Blocks(
586
  theme=gr.themes.Soft(),
@@ -658,8 +664,8 @@ def create_demo():
658
  finished_state = gr.State()
659
  turns_state = gr.State()
660
 
661
- # Initialize on load (top-level function to be pickle-safe under ZeroGPU)
662
- demo.load(_on_load_init, inputs=None, outputs=[chatbot, scores_state, meta_state, finished_state, turns_state])
663
 
664
  # Wire interactions
665
  audio_main.stop_recording(
 
581
  return init_state()
582
 
583
 
584
+ def _on_load_init_with_tts(tts_on: bool):
585
+ chat_history, scores_state, meta_state, finished_state, turns_state = init_state()
586
+ # Play the intro message via TTS if enabled
587
+ tts_path = synthesize_tts(chat_history[-1][1]) if bool(tts_on) else None
588
+ return chat_history, scores_state, meta_state, finished_state, turns_state, tts_path
589
+
590
  def create_demo():
591
  with gr.Blocks(
592
  theme=gr.themes.Soft(),
 
664
  finished_state = gr.State()
665
  turns_state = gr.State()
666
 
667
+ # Initialize on load and optionally speak the intro message
668
+ demo.load(_on_load_init_with_tts, inputs=[tts_enable], outputs=[chatbot, scores_state, meta_state, finished_state, turns_state, tts_audio_main])
669
 
670
  # Wire interactions
671
  audio_main.stop_recording(