refactor and add directory check, also make portable between blz and mag

This commit is contained in:
tonydero 2024-08-12 07:35:13 -06:00
parent 835c3d2b77
commit c927673e36

View File

@ -30,6 +30,18 @@ def slugify(text):
text = re.sub(r"\s+", "-", text)
return text
def set_dir():
blazar_path="/home/tonydero/remdirs/immich/"
magnetar_path="/nas/dockerdata/immich/local/"
if Path(blazar_path).exists():
dirpath = Path(blazar_path)
elif Path(magnetar_path).exists():
dirpath = Path(magnetar_path)
else:
dirpath = False
return 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)
output = pipe(
@ -50,18 +62,19 @@ def flux_run(prompt, height, width, num_images_per_prompt, num_inference_steps,
image.save(image_path)
def btn_click(btn_val):
DIR_NAME="/home/tonydero/remdirs/immich/"
dirpath = Path(DIR_NAME)
if btn_val == 'Generate':
dirpath = set_dir()
if dirpath and btn_val == 'Generate':
with put_loading():
start_time = datetime.now()
put_text("Started generating images at " + start_time.strftime("%H:%M:%S"))
flux_run(pin.pin.prompt, 720, 1280, 4, 4, 128, dirpath)
stop_time = datetime.now()
run_time = stop_time - start_time
# rt_min = run_time.minutes
# rt_sec = run_time.seconds
# rt_min = run_time.minute
# rt_sec = run_time.second
put_success("Images finished generating in " + str(run_time), closable=True)
else:
put_error("Failed to generate. Check directory location.", closable=True)
def main(): # PyWebIO application function
put_text("Prompt:", inline=True)