fix prompt length check and move input labels

This commit is contained in:
Tony 2024-08-14 20:23:28 -06:00
parent 16348f0cbd
commit c8b41f6120

View File

@ -46,7 +46,9 @@ def set_dir():
def chk_prompt_len(prompt):
if len(prompt) > 370:
return "Prompt too long"
return False
else:
return True
def flux_run(prompt, height, width, num_images_per_prompt, num_inference_steps, max_sequence_length, dirpath):
# FIX: add check to make sure there isn't already one running from another source (e.g. from phone when on computer)
@ -71,6 +73,7 @@ def btn_click(btn_val):
dirpath = set_dir()
if dirpath:
if btn_val == 'Generate':
if chk_prompt_len(pin.pin.prompt):
with put_loading():
start_time = datetime.now()
put_text("Started generating images at " + start_time.strftime("%H:%M:%S"))
@ -80,6 +83,8 @@ def btn_click(btn_val):
# rt_min = run_time.minute
# rt_sec = run_time.second
put_success("Images finished generating in " + str(run_time), closable=True)
else:
put_error("Prompt too long.", closable=True)
elif btn_val == 'Portrait':
pin.pin.width = 512
pin.pin.height = 1024
@ -94,15 +99,16 @@ def btn_click(btn_val):
def main(): # PyWebIO application function
# TODO: figure out how to put the labels in line with the inputs and make the number ones smaller
put_text("Prompt:", inline=True)
pin.put_input("prompt", type="text", value=default_prompt, validate=chk_prompt_len)
put_text("width:", inline=True)
pin.put_input("width", type="number", value=default_width)
put_text("height:", inline=True)
pin.put_input("height", type="number", value=default_height)
put_text("number of images:", inline=True)
pin.put_input("numimgs", type="number", value=default_numimgs)
# put_text("Prompt:", inline=True)
pin.put_input("prompt", label="Prompt:", type="text", value=default_prompt)
# put_text("width:", inline=True)
pin.put_input("width", label="Width:", type="number", value=default_width)
# put_text("height:", inline=True)
pin.put_input("height", label="Height:", type="number", value=default_height)
# put_text("number of images:", inline=True)
pin.put_input("numimgs", label="Number of images:", type="number", value=default_numimgs)
# TODO: add the remaining parameters?
# TODO: add ability to loop for more generation in one run?
put_buttons(['Generate', 'Portrait', 'Landscape', 'Square'], onclick=btn_click)
start_server(main, port=4972, debug=True, auto_open_webbrowser=False)