Upload folder using huggingface_hub
Browse files
chat.py
CHANGED
|
@@ -31,7 +31,7 @@ def start_thread():
|
|
| 31 |
def user(text, audio, history, thread):
|
| 32 |
if audio:
|
| 33 |
text = transcribe(audio)
|
| 34 |
-
print(f"
|
| 35 |
message = client.beta.threads.messages.create(thread_id=thread.id, role="user", content=text)
|
| 36 |
return "", history + [[text, None]]
|
| 37 |
|
|
@@ -58,6 +58,7 @@ def transcribe(file):
|
|
| 58 |
|
| 59 |
def speak(history):
|
| 60 |
text = history[-1][1]
|
|
|
|
| 61 |
speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
|
| 62 |
audio = base64.b64encode(speech.read()).decode("utf-8")
|
| 63 |
src = f"data:audio/mpeg;base64,{audio}"
|
|
@@ -101,7 +102,8 @@ with gr.Blocks(title="Paitient Sim", css=css) as demo:
|
|
| 101 |
mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
|
| 102 |
lambda:None, None, mic).then(
|
| 103 |
bot, [chatbot, thread], chatbot).then(
|
| 104 |
-
speak, chatbot, audio_html
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
#demo.queue()
|
|
|
|
| 31 |
def user(text, audio, history, thread):
|
| 32 |
if audio:
|
| 33 |
text = transcribe(audio)
|
| 34 |
+
print(f"User: {text}")
|
| 35 |
message = client.beta.threads.messages.create(thread_id=thread.id, role="user", content=text)
|
| 36 |
return "", history + [[text, None]]
|
| 37 |
|
|
|
|
| 58 |
|
| 59 |
def speak(history):
|
| 60 |
text = history[-1][1]
|
| 61 |
+
print(f"Assistant: {text}")
|
| 62 |
speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
|
| 63 |
audio = base64.b64encode(speech.read()).decode("utf-8")
|
| 64 |
src = f"data:audio/mpeg;base64,{audio}"
|
|
|
|
| 102 |
mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
|
| 103 |
lambda:None, None, mic).then(
|
| 104 |
bot, [chatbot, thread], chatbot).then(
|
| 105 |
+
speak, chatbot, audio_html).then(
|
| 106 |
+
None, None, None, js=play_js
|
| 107 |
)
|
| 108 |
|
| 109 |
#demo.queue()
|