From: Carl Worth Date: Wed, 7 Dec 2022 19:58:07 +0000 (-0800) Subject: Limit generated filename to something not crazy X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=512d567c92efb82f14f6611739994992ecc1b9a5;hp=c46a4bbefdaa08f2724146c4fd7e93532bbdffac;p=zombocom-ai 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. --- 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):