jbilcke-hf HF staff commited on
Commit
bb936fe
1 Parent(s): 8bdb39b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -591,11 +591,18 @@ latent_map["Pirate"] = get_latents("voices/pirate_by_coqui.wav")
591
  # Define the main function for the API endpoint that takes the input text and chatbot role
592
  def generate_story_and_speech(input_text, chatbot_role):
593
  history = [(input_text, None)] # Initialize history with user input
594
- story_text = generate_local(input_text, history) # calls your generate_local function
595
- # Serialize story_text to a single string
596
- story_text = ' '.join(sentence for sentence, _ in story_text)
597
 
598
- synthesized_speech = generate_speech_for_sentence(history, chatbot_role, story_text)
 
 
 
 
 
 
 
 
 
599
  # generate_speech_for_sentence returns a tuple, where the second item is a gr.Audio object
600
  speech_audio_bytes = synthesized_speech[1].data.getvalue() # Access the BytesIO object and extract bytes
601
 
@@ -603,7 +610,7 @@ def generate_story_and_speech(input_text, chatbot_role):
603
  speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
604
 
605
  # Return JSON object with text and base64 audio
606
- return {"text": story_text, "audio": speech_audio_base64}
607
 
608
  # Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
609
  demo = gr.Interface(
 
591
  # Define the main function for the API endpoint that takes the input text and chatbot role
592
  def generate_story_and_speech(input_text, chatbot_role):
593
  history = [(input_text, None)] # Initialize history with user input
594
+ story_sentences = get_sentence(history, chatbot_role) # calls your get_sentence function
 
 
595
 
596
+ # Initialize story_text
597
+ story_text = ""
598
+
599
+ # Iterate over sentences generated by get_sentence and concatenate them into story_text
600
+ for sentence, _ in story_sentences:
601
+ # Each 'sentence' is a tuple, where the first item is the text of the sentence
602
+ story_text += sentence + ' '
603
+
604
+ # Generate synthesized speech for the full story
605
+ synthesized_speech = generate_speech_for_sentence(history, chatbot_role, story_text)
606
  # generate_speech_for_sentence returns a tuple, where the second item is a gr.Audio object
607
  speech_audio_bytes = synthesized_speech[1].data.getvalue() # Access the BytesIO object and extract bytes
608
 
 
610
  speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
611
 
612
  # Return JSON object with text and base64 audio
613
+ return {"text": story_text.strip(), "audio": speech_audio_base64}
614
 
615
  # Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
616
  demo = gr.Interface(