Commit
•
cb57d1e
1
Parent(s):
0774599
Update app.py
Browse files
app.py
CHANGED
@@ -588,59 +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 |
-
#### GRADIO INTERFACE ####
|
592 |
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
)
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
with gr.Row():
|
618 |
-
sentence = gr.Textbox(visible=False)
|
619 |
-
audio = gr.Audio(
|
620 |
-
value=None,
|
621 |
-
label="Generated audio response",
|
622 |
-
streaming=True,
|
623 |
-
autoplay=True,
|
624 |
-
interactive=False,
|
625 |
-
show_label=True,
|
626 |
-
)
|
627 |
-
|
628 |
-
def clear_inputs(chatbot):
|
629 |
-
return None
|
630 |
-
clear_btn = gr.ClearButton([chatbot, audio])
|
631 |
-
chatbot_role.change(fn=clear_inputs, inputs=[chatbot], outputs=[chatbot])
|
632 |
-
|
633 |
-
txt_msg = txt_btn.click(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
634 |
-
generate_speech, [chatbot,chatbot_role], [chatbot,chatbot_role, sentence, audio]
|
635 |
-
)
|
636 |
-
|
637 |
-
txt_msg.then(lambda: gr.update(interactive=True), None, [txt], queue=False)
|
638 |
-
|
639 |
-
txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
640 |
-
generate_speech, [chatbot,chatbot_role], [chatbot,chatbot_role, sentence, audio]
|
641 |
-
)
|
642 |
-
|
643 |
-
txt_msg.then(lambda: gr.update(interactive=True), None, [txt], queue=False)
|
644 |
|
645 |
demo.queue()
|
646 |
demo.launch(debug=True)
|
|
|
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 |
+
# We assume that other necessary components have been initialized and are ready to use here
|
595 |
+
|
596 |
+
# Here, we'll integrate the story generation, language detection, and speech synthesis logic
|
597 |
+
# Let's assume `generate_story()` is a function that generates the story based on the input text
|
598 |
+
# And `synthesize_speech()` is a function that synthesizes speech from text
|
599 |
+
story_text = generate_story(input_text, chatbot_role)
|
600 |
+
language = detect_language(story_text)
|
601 |
+
speech_audio_bytes = synthesize_speech(story_text, language)
|
602 |
+
|
603 |
+
# Convert the speech to base64 to include in the JSON response
|
604 |
+
speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
|
605 |
+
|
606 |
+
# Return the story and speech audio in base64 format
|
607 |
+
return {"text": story_text, "audio": speech_audio_base64}
|
608 |
+
|
609 |
+
# Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
|
610 |
+
demo = gr.Interface(
|
611 |
+
fn=generate_story_and_speech,
|
612 |
+
inputs=[gr.Textbox(placeholder="Enter your text here"), gr.Dropdown(choices=ROLES, label="Select Chatbot Role")],
|
613 |
+
outputs="json"
|
614 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
|
616 |
demo.queue()
|
617 |
demo.launch(debug=True)
|