gerasdf commited on
Commit
3d38722
·
1 Parent(s): 3491ea6

button to play last answer

Browse files
Files changed (1) hide show
  1. query.py +37 -13
query.py CHANGED
@@ -8,6 +8,8 @@ from langchain_core.runnables import RunnablePassthrough, RunnableLambda
8
  from langchain_core.messages import SystemMessage, AIMessage, HumanMessage
9
  from langchain_openai import OpenAIEmbeddings, ChatOpenAI
10
 
 
 
11
  from openai import OpenAI
12
 
13
  from json import loads as json_loads
@@ -18,7 +20,7 @@ prompt_template = os.environ.get("PROMPT_TEMPLATE")
18
 
19
  prompt = ChatPromptTemplate.from_messages([('system', prompt_template)])
20
 
21
- AI = True
22
 
23
  def ai_setup():
24
  global llm, prompt_chain, oai_client
@@ -166,6 +168,18 @@ def on_audio(path, state):
166
 
167
  return (text, None)
168
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  def gr_main():
170
  theme = gr.Theme.from_hub("freddyaboulton/[email protected]")
171
  theme.set(
@@ -204,20 +218,32 @@ def gr_main():
204
  # ],
205
  additional_inputs=[state])
206
 
207
- mic = gr.Audio(
208
- sources=["microphone"],
209
- type="filepath",
210
- show_label=False,
211
- format="mp3",
212
-
213
- waveform_options=gr.WaveformOptions(sample_rate=16000))
214
- mic.change(
215
  on_audio, [mic, state], [iface.textbox, mic]
216
  ).then(
217
  lambda x:None,
218
- js='function (text){debugger; if (text) document.getElementById("submit_btn").click(); return [text]}',
219
  inputs=iface.textbox
220
  )
 
 
 
 
 
 
 
 
 
 
 
 
221
  token = gr.Textbox(visible=False)
222
  app.load(auth,
223
  [token,state],
@@ -229,6 +255,4 @@ def gr_main():
229
  if __name__ == "__main__":
230
  ai_setup()
231
  gr_main()
232
-
233
- # Autoplay audio
234
- # https://github.com/gradio-app/gradio/issues/1349
 
8
  from langchain_core.messages import SystemMessage, AIMessage, HumanMessage
9
  from langchain_openai import OpenAIEmbeddings, ChatOpenAI
10
 
11
+ from elevenlabs import VoiceSettings
12
+ from elevenlabs.client import ElevenLabs
13
  from openai import OpenAI
14
 
15
  from json import loads as json_loads
 
20
 
21
  prompt = ChatPromptTemplate.from_messages([('system', prompt_template)])
22
 
23
+ AI = False
24
 
25
  def ai_setup():
26
  global llm, prompt_chain, oai_client
 
168
 
169
  return (text, None)
170
 
171
+ def play_last(history, state):
172
+ if not_authenticated(state):
173
+ pass
174
+ else:
175
+ if len(history):
176
+ voice_id = "IINmogebEQykLiDoSkd0"
177
+ text = history[-1][1]
178
+ lab11 = ElevenLabs()
179
+ whatson=lab11.voices.get(voice_id)
180
+ response = lab11.generate(text=text, voice=whatson, stream=True)
181
+ yield from response
182
+
183
  def gr_main():
184
  theme = gr.Theme.from_hub("freddyaboulton/[email protected]")
185
  theme.set(
 
218
  # ],
219
  additional_inputs=[state])
220
 
221
+ with gr.Row():
222
+ mic = gr.Audio(
223
+ sources=["microphone"],
224
+ type="filepath",
225
+ show_label=False,
226
+ format="mp3",
227
+ waveform_options=gr.WaveformOptions(sample_rate=16000))
228
+ mic.change(
229
  on_audio, [mic, state], [iface.textbox, mic]
230
  ).then(
231
  lambda x:None,
232
+ js='function (text){if (text) document.getElementById("submit_btn").click(); return [text]}',
233
  inputs=iface.textbox
234
  )
235
+
236
+ player = gr.Audio(
237
+ show_label=False,
238
+ show_download_button=True,
239
+ visible=True,
240
+ autoplay=True,
241
+ streaming=True)
242
+
243
+ play_btn = gr.Button("Play last ")
244
+ play_btn.click(play_last, [chatbot, state], player)
245
+
246
+
247
  token = gr.Textbox(visible=False)
248
  app.load(auth,
249
  [token,state],
 
255
  if __name__ == "__main__":
256
  ai_setup()
257
  gr_main()
258
+