Eniola Alese commited on
Commit
6b93710
1 Parent(s): 614b0d8

update app files

Browse files
Files changed (4) hide show
  1. README.md +4 -4
  2. app.py +5 -5
  3. examples/coqui-logo.png +0 -0
  4. utils.py +2 -2
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Voice Chat With Llm
3
  emoji: 👾
4
- colorFrom: purple
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.26.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: Voice Chat With LLM
3
  emoji: 👾
4
+ colorFrom: blue
5
+ colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.48.0
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -103,7 +103,7 @@ with gr.Blocks(title="Voice chat with LLM") as demo:
103
  container=False,
104
  interactive=True,
105
  )
106
- audio_record = gr.Audio(sources=["microphone"], type="filepath", scale=4)
107
 
108
  # Define generated audio playback component
109
  with gr.Row():
@@ -121,7 +121,7 @@ with gr.Blocks(title="Voice chat with LLM") as demo:
121
  def add_text(chatbot_history, text):
122
  chatbot_history = [] if chatbot_history is None else chatbot_history
123
  chatbot_history = chatbot_history + [(text, None)]
124
- return chatbot_history, gr.Textbox(value="", interactive=False)
125
 
126
  # Will be triggered on voice submit (will transribe and send to generate_speech)
127
  def add_audio(chatbot_history, audio):
@@ -131,7 +131,7 @@ with gr.Blocks(title="Voice chat with LLM") as demo:
131
  text = list(response)[0].text.strip()
132
  print("Transcribed text:", text)
133
  chatbot_history = chatbot_history + [(text, None)]
134
- return chatbot_history, gr.Textbox(value="", interactive=False)
135
 
136
  def generate_speech(chatbot_history, chatbot_voice, initial_greeting=False):
137
  # Start by yielding an initial empty audio to set up autoplay
@@ -159,12 +159,12 @@ with gr.Blocks(title="Voice chat with LLM") as demo:
159
  txt_msg = txt_box.submit(fn=add_text, inputs=[chatbot, txt_box], outputs=[chatbot, txt_box], queue=False
160
  ).then(fn=generate_speech, inputs=[chatbot,chatbot_voice], outputs=[sentence, chatbot, audio_playback])
161
 
162
- txt_msg.then(fn=lambda: gr.Textbox(interactive=True), inputs=None, outputs=[txt_box], queue=False)
163
 
164
  audio_msg = audio_record.stop_recording(fn=add_audio, inputs=[chatbot, audio_record], outputs=[chatbot, txt_box], queue=False
165
  ).then(fn=generate_speech, inputs=[chatbot,chatbot_voice], outputs=[sentence, chatbot, audio_playback])
166
 
167
- audio_msg.then(fn=lambda: (gr.Audio(interactive=True),gr.Audio(interactive=True,value=None)), inputs=None, outputs=[txt_box, audio_record], queue=False)
168
 
169
  FOOTNOTE = """
170
  This Space demonstrates how to speak to an llm chatbot, based solely on open accessible models.
 
103
  container=False,
104
  interactive=True,
105
  )
106
+ audio_record = gr.Audio(source="microphone", type="filepath", scale=4)
107
 
108
  # Define generated audio playback component
109
  with gr.Row():
 
121
  def add_text(chatbot_history, text):
122
  chatbot_history = [] if chatbot_history is None else chatbot_history
123
  chatbot_history = chatbot_history + [(text, None)]
124
+ return chatbot_history, gr.update(value="", interactive=False)
125
 
126
  # Will be triggered on voice submit (will transribe and send to generate_speech)
127
  def add_audio(chatbot_history, audio):
 
131
  text = list(response)[0].text.strip()
132
  print("Transcribed text:", text)
133
  chatbot_history = chatbot_history + [(text, None)]
134
+ return chatbot_history, gr.update(value="", interactive=False)
135
 
136
  def generate_speech(chatbot_history, chatbot_voice, initial_greeting=False):
137
  # Start by yielding an initial empty audio to set up autoplay
 
159
  txt_msg = txt_box.submit(fn=add_text, inputs=[chatbot, txt_box], outputs=[chatbot, txt_box], queue=False
160
  ).then(fn=generate_speech, inputs=[chatbot,chatbot_voice], outputs=[sentence, chatbot, audio_playback])
161
 
162
+ txt_msg.then(fn=lambda: gr.update(interactive=True), inputs=None, outputs=[txt_box], queue=False)
163
 
164
  audio_msg = audio_record.stop_recording(fn=add_audio, inputs=[chatbot, audio_record], outputs=[chatbot, txt_box], queue=False
165
  ).then(fn=generate_speech, inputs=[chatbot,chatbot_voice], outputs=[sentence, chatbot, audio_playback])
166
 
167
+ audio_msg.then(fn=lambda: (gr.update(interactive=True),gr.update(interactive=True,value=None)), inputs=None, outputs=[txt_box, audio_record], queue=False)
168
 
169
  FOOTNOTE = """
170
  This Space demonstrates how to speak to an llm chatbot, based solely on open accessible models.
examples/coqui-logo.png DELETED
Binary file (9.76 kB)
 
utils.py CHANGED
@@ -387,9 +387,9 @@ def generate_speech_for_sentence(history, chatbot_voice, sentence, xtts_model, x
387
  f.setframerate(24000)
388
  f.writeframes(wav_bytestream)
389
 
390
- return (history , gr.Audio(value=audio_unique_filename, autoplay=True))
391
  else:
392
- return (history , gr.Audio(value=wav_bytestream, autoplay=True))
393
  except RuntimeError as e:
394
  if "device-side assert" in str(e):
395
  # cannot do anything on cuda device side error, need tor estart
 
387
  f.setframerate(24000)
388
  f.writeframes(wav_bytestream)
389
 
390
+ return (history , gr.Audio.update(value=audio_unique_filename, autoplay=True))
391
  else:
392
+ return (history , gr.Audio.update(value=wav_bytestream, autoplay=True))
393
  except RuntimeError as e:
394
  if "device-side assert" in str(e):
395
  # cannot do anything on cuda device side error, need tor estart