Commit
·
38d7590
1
Parent(s):
cb57d1e
Update app.py
Browse files
app.py
CHANGED
@@ -588,30 +588,30 @@ latent_map = {}
|
|
588 |
latent_map["Julian"] = get_latents("voices/julian-bedtime-style-1.wav")
|
589 |
latent_map["Pirate"] = get_latents("voices/pirate_by_coqui.wav")
|
590 |
|
591 |
-
|
592 |
# Define the main function for the API endpoint that takes the input text and chatbot role
|
593 |
def generate_story_and_speech(input_text, chatbot_role):
|
594 |
-
|
595 |
-
|
596 |
-
#
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
speech_audio_bytes =
|
602 |
-
|
603 |
-
# Convert the speech to base64 to include in
|
604 |
speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
|
605 |
|
606 |
-
# Return
|
607 |
return {"text": story_text, "audio": speech_audio_base64}
|
608 |
|
609 |
-
#
|
610 |
-
|
611 |
fn=generate_story_and_speech,
|
612 |
-
inputs=[gr.Textbox(
|
613 |
outputs="json"
|
614 |
)
|
615 |
|
616 |
-
|
617 |
-
|
|
|
|
588 |
latent_map["Julian"] = get_latents("voices/julian-bedtime-style-1.wav")
|
589 |
latent_map["Pirate"] = get_latents("voices/pirate_by_coqui.wav")
|
590 |
|
|
|
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 |
+
|
602 |
+
# Convert the speech to base64 to include in JSON response
|
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 |
+
# Define your Gradio app API
|
609 |
+
iface = gr.Interface(
|
610 |
fn=generate_story_and_speech,
|
611 |
+
inputs=[gr.Textbox(label="Enter your text"), gr.Dropdown(choices=ROLES, label="Chatbot Role")],
|
612 |
outputs="json"
|
613 |
)
|
614 |
|
615 |
+
# Launch the app
|
616 |
+
if __name__ == "__main__":
|
617 |
+
iface.launch(debug=True, enable_queue=True, api_mode=True)
|