]> git.cworth.org Git - zombocom-ai/commitdiff
Limit generated filename to something not crazy
authorCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 19:58:07 +0000 (11:58 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 20:01:09 +0000 (12:01 -0800)
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

index 408fe21bebfe8086accbf4f373176970fa6dcaaa..f5502c6321d337ccdd8435f84e01737aeb0a3fdf 100755 (executable)
@@ -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):