Upload folder using huggingface_hub
Browse files
chat.py
CHANGED
@@ -60,8 +60,8 @@ def speak(history):
|
|
60 |
speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
|
61 |
audio = base64.b64encode(speech.read()).decode("utf-8")
|
62 |
src = f"data:audio/mpeg;base64,{audio}"
|
63 |
-
|
64 |
-
return
|
65 |
|
66 |
def vote(data: gr.LikeData):
|
67 |
if data.liked:
|
@@ -91,17 +91,17 @@ with gr.Blocks(title="Paitient Sim", css=css) as demo:
|
|
91 |
msg = gr.Textbox(label="Say something.", elem_id="textbox")
|
92 |
mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
|
93 |
thread = gr.State(start_thread)
|
94 |
-
audio_html = gr.HTML()
|
95 |
audio_html.visible = False
|
96 |
msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot], queue=False).then(
|
97 |
bot, [chatbot, thread], chatbot
|
98 |
).then(
|
99 |
-
speak, chatbot,
|
100 |
)
|
101 |
mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot], queue=False).then(
|
102 |
lambda:None, None, mic, queue=False).then(
|
103 |
bot, [chatbot, thread], chatbot).then(
|
104 |
-
speak, chatbot,
|
105 |
)
|
106 |
|
107 |
demo.queue()
|
|
|
60 |
speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
|
61 |
audio = base64.b64encode(speech.read()).decode("utf-8")
|
62 |
src = f"data:audio/mpeg;base64,{audio}"
|
63 |
+
audio_element = f'<audio src="{src}" autoplay></audio>'
|
64 |
+
return audio_element
|
65 |
|
66 |
def vote(data: gr.LikeData):
|
67 |
if data.liked:
|
|
|
91 |
msg = gr.Textbox(label="Say something.", elem_id="textbox")
|
92 |
mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
|
93 |
thread = gr.State(start_thread)
|
94 |
+
audio_html = gr.HTML(visible=False)
|
95 |
audio_html.visible = False
|
96 |
msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot], queue=False).then(
|
97 |
bot, [chatbot, thread], chatbot
|
98 |
).then(
|
99 |
+
speak, chatbot, audio_html
|
100 |
)
|
101 |
mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot], queue=False).then(
|
102 |
lambda:None, None, mic, queue=False).then(
|
103 |
bot, [chatbot, thread], chatbot).then(
|
104 |
+
speak, chatbot, audio_html
|
105 |
)
|
106 |
|
107 |
demo.queue()
|