chibop commited on
Commit
0b7105c
·
verified ·
1 Parent(s): 430a018

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. chat.py +7 -7
chat.py CHANGED
@@ -20,9 +20,10 @@ for a in assistants:
20
  instruction = codecs.open("instruction.txt", "r", "utf-8").read()
21
  #instruction = "You are helpful assistant. Keep your responses clear and concise."
22
  model = "gpt-4o"
23
- #model = "gpt-3.5-turbo"
24
  assistant = client.beta.assistants.create(name="Patient Sim", instructions=instruction, model=model)
25
  toggle_js = open("toggle_speech.js").read()
 
26
 
27
  def start_thread():
28
  return client.beta.threads.create()
@@ -60,7 +61,7 @@ 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
- audio_element = f'<audio src="{src}" controls autoplay></audio>'
64
  return audio_element
65
 
66
  def vote(data: gr.LikeData):
@@ -89,13 +90,12 @@ with gr.Blocks(title="Paitient Sim", css=css) as demo:
89
  speech = gr.Button("Record", size="sm", elem_id="speech")
90
  speech.click(None, js=toggle_js)
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
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
96
- bot, [chatbot, thread], chatbot
97
- ).then(
98
- speak, chatbot, audio_html
99
  )
100
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
101
  lambda:None, None, mic).then(
 
20
  instruction = codecs.open("instruction.txt", "r", "utf-8").read()
21
  #instruction = "You are helpful assistant. Keep your responses clear and concise."
22
  model = "gpt-4o"
23
+ model = "gpt-3.5-turbo"
24
  assistant = client.beta.assistants.create(name="Patient Sim", instructions=instruction, model=model)
25
  toggle_js = open("toggle_speech.js").read()
26
+ play_js = open("play.js").read()
27
 
28
  def start_thread():
29
  return client.beta.threads.create()
 
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}"
64
+ audio_element = f'<audio src="{src}"></audio>'
65
  return audio_element
66
 
67
  def vote(data: gr.LikeData):
 
90
  speech = gr.Button("Record", size="sm", elem_id="speech")
91
  speech.click(None, js=toggle_js)
92
  msg = gr.Textbox(label="Say something.", elem_id="textbox")
93
+ mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False, elem_id="recorder")
94
  thread = gr.State(start_thread)
95
+ audio_html = gr.HTML(visible=False, elem_id="player")
96
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
97
+ bot, [chatbot, thread], chatbot).then(
98
+ speak, chatbot, audio_html, js=play_js
 
99
  )
100
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
101
  lambda:None, None, mic).then(