chibop commited on
Commit
943acb7
·
verified ·
1 Parent(s): 430cba4

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. chat.py +4 -3
  2. play.js +7 -0
chat.py CHANGED
@@ -27,6 +27,7 @@ model = "gpt-4o"
27
  #model = "gpt-3.5-turbo"
28
  assistant = client.beta.assistants.create(name="Patient Sim", instructions=instruction, model=model)
29
  toggle_js = open("toggle_speech.js").read()
 
30
 
31
  def start_thread():
32
  print("start_thread")
@@ -95,8 +96,8 @@ def main():
95
  speech = gr.Button("Record", size="sm", elem_id="speech")
96
  speech.click(None, js=toggle_js)
97
  msg = gr.Textbox(label="Say something.", elem_id="textbox")
98
- mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
99
- player = gr.Audio(autoplay=True, editable=False, waveform_options={"show_controls": False}, visible=False)
100
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
101
  bot, [chatbot, thread], chatbot).then(
102
  speak, chatbot, player
@@ -104,7 +105,7 @@ def main():
104
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
105
  lambda:None, None, mic).then(
106
  bot, [chatbot, thread], chatbot).then(
107
- speak, chatbot, player
108
  )
109
 
110
  demo.queue()
 
27
  #model = "gpt-3.5-turbo"
28
  assistant = client.beta.assistants.create(name="Patient Sim", instructions=instruction, model=model)
29
  toggle_js = open("toggle_speech.js").read()
30
+ play_js = open("play.js").read()
31
 
32
  def start_thread():
33
  print("start_thread")
 
96
  speech = gr.Button("Record", size="sm", elem_id="speech")
97
  speech.click(None, js=toggle_js)
98
  msg = gr.Textbox(label="Say something.", elem_id="textbox")
99
+ mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False, elem_id="recorder")
100
+ player = gr.Audio(autoplay=True, editable=False, waveform_options={"show_controls": False}, visible=False, elem_id="player")
101
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
102
  bot, [chatbot, thread], chatbot).then(
103
  speak, chatbot, player
 
105
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
106
  lambda:None, None, mic).then(
107
  bot, [chatbot, thread], chatbot).then(
108
+ speak, chatbot, player, js=play_js
109
  )
110
 
111
  demo.queue()
play.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ function () {
2
+
3
+ const player = document.querySelector("#player audio");
4
+ if (player) {
5
+ player.play()
6
+ }
7
+ }