Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -159,7 +159,7 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel):
|
|
159 |
response = f'cleaned all .wav files for {user}'
|
160 |
final_clean_up(user)
|
161 |
return [past, response, None, gptModel]
|
162 |
-
if user_window in unames and pwd_window
|
163 |
past.append({"role":"user", "content":prompt})
|
164 |
completion = client.chat.completions.create(model=gptModel,
|
165 |
messages=past)
|
@@ -231,13 +231,9 @@ def set_speak_button(txt):
|
|
231 |
return gr.Button(visible=vis)
|
232 |
|
233 |
def update_user(txt):
|
234 |
-
|
|
|
235 |
|
236 |
-
# def clean_up(q):
|
237 |
-
# for fname in q:
|
238 |
-
# if os.path.exists(fname):
|
239 |
-
# os.remove(fname)
|
240 |
-
# return []
|
241 |
|
242 |
def speech_worker(chunks=[],q=[]):
|
243 |
for chunk in chunks:
|
@@ -246,12 +242,6 @@ def speech_worker(chunks=[],q=[]):
|
|
246 |
with open(fpath, 'wb') as fp:
|
247 |
fp.write(response.content)
|
248 |
|
249 |
-
# def gen_speech_file(user):
|
250 |
-
# global speech_file_index
|
251 |
-
# speech_file_index += 1
|
252 |
-
# fname = dataDir + f'user_speech{speech_file_index}.wav'
|
253 |
-
# return fname
|
254 |
-
|
255 |
def gen_speech_file_names(user, cnt):
|
256 |
rv = []
|
257 |
for i in range(0, cnt):
|
@@ -285,6 +275,9 @@ with gr.Blocks() as demo:
|
|
285 |
def initial_audio_output(txt, user):
|
286 |
global digits
|
287 |
global abbrevs
|
|
|
|
|
|
|
288 |
q = []
|
289 |
if len(txt.strip()) < 5:
|
290 |
return ['None', q]
|
@@ -366,13 +359,13 @@ with gr.Blocks() as demo:
|
|
366 |
|
367 |
|
368 |
gr.Markdown('# GPT Chat')
|
369 |
-
gr.Markdown('Enter user name & password then enter prompt and click submit button. Restart conversation if topic changes'
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
with gr.Row():
|
374 |
user_window = gr.Textbox(label = "User Name")
|
375 |
-
user_window.blur(update_user, user_window, user)
|
376 |
pwd_window = gr.Textbox(label = "Password")
|
377 |
pwd_window.blur(updatePassword, pwd_window, [password, pwd_window])
|
378 |
with gr.Row():
|
|
|
159 |
response = f'cleaned all .wav files for {user}'
|
160 |
final_clean_up(user)
|
161 |
return [past, response, None, gptModel]
|
162 |
+
if user_window in unames and pwd_window == pwdList[unames.index(user_window)]:
|
163 |
past.append({"role":"user", "content":prompt})
|
164 |
completion = client.chat.completions.create(model=gptModel,
|
165 |
messages=past)
|
|
|
231 |
return gr.Button(visible=vis)
|
232 |
|
233 |
def update_user(txt):
|
234 |
+
user = txt.strip().lower()
|
235 |
+
return [user, user]
|
236 |
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
def speech_worker(chunks=[],q=[]):
|
239 |
for chunk in chunks:
|
|
|
242 |
with open(fpath, 'wb') as fp:
|
243 |
fp.write(response.content)
|
244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
def gen_speech_file_names(user, cnt):
|
246 |
rv = []
|
247 |
for i in range(0, cnt):
|
|
|
275 |
def initial_audio_output(txt, user):
|
276 |
global digits
|
277 |
global abbrevs
|
278 |
+
if not user in unames:
|
279 |
+
return [gr.Audio(sources=None), []]
|
280 |
+
clean_up(user)
|
281 |
q = []
|
282 |
if len(txt.strip()) < 5:
|
283 |
return ['None', q]
|
|
|
359 |
|
360 |
|
361 |
gr.Markdown('# GPT Chat')
|
362 |
+
gr.Markdown('Enter user name & password then enter prompt and click submit button. Restart conversation if topic changes. ' +
|
363 |
+
'You can enter prompts by voice. Tap "Record", speak, then tap "Stop". ' +
|
364 |
+
'Tap "Reset Voice Entry" to enter more voice. Tap "Speak Dialog" to hear dialog. ' +
|
365 |
+
'Note: first voice response may take a longer time.')
|
366 |
with gr.Row():
|
367 |
user_window = gr.Textbox(label = "User Name")
|
368 |
+
user_window.blur(fn=update_user, inputs=user_window, outputs=[user, user_window])
|
369 |
pwd_window = gr.Textbox(label = "Password")
|
370 |
pwd_window.blur(updatePassword, pwd_window, [password, pwd_window])
|
371 |
with gr.Row():
|