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