Spaces:
Running
Running
Update app.py
Browse filesImage visible only when used. Soft theme. Enhanced help.
app.py
CHANGED
|
@@ -160,7 +160,7 @@ def genUsageStats(do_reset=False):
|
|
| 160 |
|
| 161 |
def new_conversation(user):
|
| 162 |
clean_up(user)
|
| 163 |
-
return [None, [], None, None]
|
| 164 |
|
| 165 |
def updatePassword(txt):
|
| 166 |
password = txt.lower().strip()
|
|
@@ -332,7 +332,7 @@ def make_image(prompt, user, pwd):
|
|
| 332 |
fpath = None
|
| 333 |
if user in unames and pwd == pwdList[unames.index(user)]:
|
| 334 |
if len(prompt.strip()) == 0:
|
| 335 |
-
return [None, 'You must provide a prompt describing image you desire']
|
| 336 |
try:
|
| 337 |
response = client.images.generate(model='dall-e-2', prompt=prompt,size='512x512',
|
| 338 |
quality='standard', response_format='b64_json')
|
|
@@ -344,11 +344,11 @@ def make_image(prompt, user, pwd):
|
|
| 344 |
fp.write('1\n')
|
| 345 |
msg = 'Image created!'
|
| 346 |
except:
|
| 347 |
-
return [None, msg]
|
| 348 |
else:
|
| 349 |
msg = 'Incorrect user name or password'
|
| 350 |
-
return [None, msg]
|
| 351 |
-
return [fpath, msg]
|
| 352 |
|
| 353 |
def show_help():
|
| 354 |
return '''
|
|
@@ -372,11 +372,14 @@ def show_help():
|
|
| 372 |
1. Better chat and image results are obtained by including detailed descriptions and instructions
|
| 373 |
in the prompt.
|
| 374 |
2. Always tap "Restart Conversation" before requesting an image or changing chat topics.
|
| 375 |
-
3. Audio input and output functions depend on the hardware capability of your device.
|
|
|
|
|
|
|
|
|
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
-
with gr.Blocks() as demo:
|
| 380 |
history = gr.State([])
|
| 381 |
password = gr.State("")
|
| 382 |
user = gr.State("unknown")
|
|
@@ -401,6 +404,11 @@ with gr.Blocks() as demo:
|
|
| 401 |
q = []
|
| 402 |
if len(txt.strip()) < 5:
|
| 403 |
return ['None', q]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
for s,x in abbrevs.items():
|
| 405 |
txt = txt.replace(s, x)
|
| 406 |
words_in = txt.replace('**', '').splitlines(False)
|
|
@@ -500,7 +508,7 @@ with gr.Blocks() as demo:
|
|
| 500 |
speak_output = gr.Button(value="Speak Dialog", visible=False)
|
| 501 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
| 502 |
output_window = gr.Textbox(label = "Dialog")
|
| 503 |
-
image_window = gr.Image()
|
| 504 |
submit_button.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
| 505 |
outputs=[history, output_window, prompt_window, model])
|
| 506 |
clear_button.click(fn=new_conversation, inputs=user_window, outputs=[prompt_window, history, output_window, image_window])
|
|
|
|
| 160 |
|
| 161 |
def new_conversation(user):
|
| 162 |
clean_up(user)
|
| 163 |
+
return [None, [], None, gr.Image(visible=False, value=None)]
|
| 164 |
|
| 165 |
def updatePassword(txt):
|
| 166 |
password = txt.lower().strip()
|
|
|
|
| 332 |
fpath = None
|
| 333 |
if user in unames and pwd == pwdList[unames.index(user)]:
|
| 334 |
if len(prompt.strip()) == 0:
|
| 335 |
+
return [gr.Image(value=None, visible=False), 'You must provide a prompt describing image you desire']
|
| 336 |
try:
|
| 337 |
response = client.images.generate(model='dall-e-2', prompt=prompt,size='512x512',
|
| 338 |
quality='standard', response_format='b64_json')
|
|
|
|
| 344 |
fp.write('1\n')
|
| 345 |
msg = 'Image created!'
|
| 346 |
except:
|
| 347 |
+
return [gr.Image(visible=False, value=None), msg]
|
| 348 |
else:
|
| 349 |
msg = 'Incorrect user name or password'
|
| 350 |
+
return [gr.Image(visible=False, value=None), msg]
|
| 351 |
+
return [gr.Image(visible=True, value=fpath), msg]
|
| 352 |
|
| 353 |
def show_help():
|
| 354 |
return '''
|
|
|
|
| 372 |
1. Better chat and image results are obtained by including detailed descriptions and instructions
|
| 373 |
in the prompt.
|
| 374 |
2. Always tap "Restart Conversation" before requesting an image or changing chat topics.
|
| 375 |
+
3. Audio input and output functions depend on the hardware capability of your device.
|
| 376 |
+
4. "Speak Dialog" will voice whatever is currently in the Dialog window. You can repeat it and you
|
| 377 |
+
can edit what's to be spoken. Except: In a chat conversation, spoken dialog will only include
|
| 378 |
+
the latest prompt/response ("YOU:/GPT:") sequence.'''
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 383 |
history = gr.State([])
|
| 384 |
password = gr.State("")
|
| 385 |
user = gr.State("unknown")
|
|
|
|
| 404 |
q = []
|
| 405 |
if len(txt.strip()) < 5:
|
| 406 |
return ['None', q]
|
| 407 |
+
try:
|
| 408 |
+
loc = txt.rindex('YOU:')
|
| 409 |
+
txt = txt[loc:]
|
| 410 |
+
except:
|
| 411 |
+
pass
|
| 412 |
for s,x in abbrevs.items():
|
| 413 |
txt = txt.replace(s, x)
|
| 414 |
words_in = txt.replace('**', '').splitlines(False)
|
|
|
|
| 508 |
speak_output = gr.Button(value="Speak Dialog", visible=False)
|
| 509 |
prompt_window = gr.Textbox(label = "Prompt or Question")
|
| 510 |
output_window = gr.Textbox(label = "Dialog")
|
| 511 |
+
image_window = gr.Image(visible=False)
|
| 512 |
submit_button.click(chat, inputs=[prompt_window, user_window, password, history, output_window, model],
|
| 513 |
outputs=[history, output_window, prompt_window, model])
|
| 514 |
clear_button.click(fn=new_conversation, inputs=user_window, outputs=[prompt_window, history, output_window, image_window])
|