From 512d567c92efb82f14f6611739994992ecc1b9a5 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 7 Dec 2022 11:58:07 -0800 Subject: [PATCH] Limit generated filename to something not crazy Since otherwise, with a crazy-long prompt, we could exceed the limit of the filesystem, (which I think is 255 characters for what I'm using for the server currently). In this commit, we don't use more than 200 characters from the prompt itself, to which we could add 10 from the seed and another handful for separators and a file extension, so that should be good. --- generate-image.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/generate-image.py b/generate-image.py index 408fe21..f5502c6 100755 --- a/generate-image.py +++ b/generate-image.py @@ -27,10 +27,11 @@ def save_artifact(artifact, prompt): counter = 1 seed = artifact.seed while True: + prompt_abbrev = prompt[:200] if counter > 1: - base = "{}_{}_{}.png".format(seed, prompt, counter) + base = "{}_{}_{}.png".format(seed, prompt_abbrev, counter) else: - base = "{}_{}.png".format(seed, prompt) + base = "{}_{}.png".format(seed, prompt_abbrev) base = normalize_filename(base) filename = "{}{}/{}".format(DOCUMENT_ROOT, IMAGES_PATH, base) if not os.path.exists(filename): -- 2.43.0