gerasdf
commited on
Commit
·
db9a221
1
Parent(s):
4313577
no more record contorl, just a start-stop button
Browse files
query.py
CHANGED
|
@@ -21,7 +21,7 @@ prompt_template = os.environ.get("PROMPT_TEMPLATE")
|
|
| 21 |
|
| 22 |
prompt = ChatPromptTemplate.from_messages([('system', prompt_template)])
|
| 23 |
|
| 24 |
-
AI =
|
| 25 |
|
| 26 |
def ai_setup():
|
| 27 |
global llm, prompt_chain, oai_client
|
|
@@ -228,7 +228,10 @@ def play_last(history, state):
|
|
| 228 |
whatson=lab11.voices.get(voice_id)
|
| 229 |
response = lab11.generate(text=text, voice=whatson, stream=True)
|
| 230 |
yield from response
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
| 232 |
def gr_main():
|
| 233 |
theme = gr.Theme.from_hub("freddyaboulton/dracula_revamped@0.3.9")
|
| 234 |
theme.set(
|
|
@@ -269,42 +272,61 @@ def gr_main():
|
|
| 269 |
additional_inputs=[state])
|
| 270 |
|
| 271 |
with gr.Row():
|
| 272 |
-
mic = gr.Audio(
|
| 273 |
-
sources=["microphone"],
|
| 274 |
-
type="filepath",
|
| 275 |
-
show_label=False,
|
| 276 |
-
format="mp3",
|
| 277 |
-
waveform_options=gr.WaveformOptions(sample_rate=16000))
|
| 278 |
player = gr.Audio(
|
|
|
|
| 279 |
show_label=False,
|
| 280 |
show_download_button=False,
|
| 281 |
show_share_button=False,
|
| 282 |
-
visible=True,
|
| 283 |
autoplay=True,
|
| 284 |
streaming=True,
|
| 285 |
interactive=False)
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
)
|
|
|
|
|
|
|
| 297 |
play_btn.click(
|
| 298 |
play_last,
|
| 299 |
[chatbot, state], player)
|
| 300 |
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
token = gr.Textbox(visible=False)
|
|
|
|
| 303 |
app.load(auth,
|
| 304 |
[token,state],
|
| 305 |
[token,state],
|
| 306 |
js=AUTH_JS)
|
| 307 |
-
|
| 308 |
app.queue(default_concurrency_limit=None, api_open=False)
|
| 309 |
app.launch(show_api=False)
|
| 310 |
|
|
|
|
| 21 |
|
| 22 |
prompt = ChatPromptTemplate.from_messages([('system', prompt_template)])
|
| 23 |
|
| 24 |
+
AI = False
|
| 25 |
|
| 26 |
def ai_setup():
|
| 27 |
global llm, prompt_chain, oai_client
|
|
|
|
| 228 |
whatson=lab11.voices.get(voice_id)
|
| 229 |
response = lab11.generate(text=text, voice=whatson, stream=True)
|
| 230 |
yield from response
|
| 231 |
+
|
| 232 |
+
TEXT_TALK = "🎤 Talk"
|
| 233 |
+
TEXT_STOP = "⏹ Stop"
|
| 234 |
+
|
| 235 |
def gr_main():
|
| 236 |
theme = gr.Theme.from_hub("freddyaboulton/dracula_revamped@0.3.9")
|
| 237 |
theme.set(
|
|
|
|
| 272 |
additional_inputs=[state])
|
| 273 |
|
| 274 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
player = gr.Audio(
|
| 276 |
+
visible=False,
|
| 277 |
show_label=False,
|
| 278 |
show_download_button=False,
|
| 279 |
show_share_button=False,
|
|
|
|
| 280 |
autoplay=True,
|
| 281 |
streaming=True,
|
| 282 |
interactive=False)
|
| 283 |
+
|
| 284 |
+
mic = gr.Audio(
|
| 285 |
+
sources=["microphone"],
|
| 286 |
+
type="filepath",
|
| 287 |
+
show_label=False,
|
| 288 |
+
format="mp3",
|
| 289 |
+
elem_id="microphone",
|
| 290 |
+
visible=False,
|
| 291 |
+
waveform_options=gr.WaveformOptions(sample_rate=16000, show_recording_waveform=False))
|
| 292 |
+
|
| 293 |
+
start_stop_rec = gr.Button(TEXT_TALK)
|
| 294 |
+
play_btn = gr.Button("Play last") #, enabled=False)
|
| 295 |
+
|
| 296 |
play_btn.click(
|
| 297 |
play_last,
|
| 298 |
[chatbot, state], player)
|
| 299 |
|
| 300 |
|
| 301 |
+
start_stop_rec.click(
|
| 302 |
+
lambda x:x,
|
| 303 |
+
inputs=start_stop_rec,
|
| 304 |
+
outputs=start_stop_rec,
|
| 305 |
+
js=f'''function (text) {{
|
| 306 |
+
if (text == "{TEXT_TALK}") {{
|
| 307 |
+
document.getElementById("microphone").querySelector(".record-button").click()
|
| 308 |
+
return ["{TEXT_STOP}"]
|
| 309 |
+
}} else {{
|
| 310 |
+
document.getElementById("microphone").querySelector(".stop-button").click()
|
| 311 |
+
return ["{TEXT_TALK}"]
|
| 312 |
+
}}
|
| 313 |
+
}}'''
|
| 314 |
+
)
|
| 315 |
+
mic.change(
|
| 316 |
+
on_audio, [mic, state], [iface.textbox, mic]
|
| 317 |
+
).then(
|
| 318 |
+
lambda x:None,
|
| 319 |
+
inputs=iface.textbox,
|
| 320 |
+
js='function (text){if (text) document.getElementById("submit_btn").click(); return [text]}'
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
token = gr.Textbox(visible=False)
|
| 324 |
+
|
| 325 |
app.load(auth,
|
| 326 |
[token,state],
|
| 327 |
[token,state],
|
| 328 |
js=AUTH_JS)
|
| 329 |
+
|
| 330 |
app.queue(default_concurrency_limit=None, api_open=False)
|
| 331 |
app.launch(show_api=False)
|
| 332 |
|