diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-09-12 16:13:03 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-09-12 16:13:03 +0000 |
commit | 095830e1e8a99276b3055c720981e89fc6af853d (patch) | |
tree | 1444b661b33a6d83f06323b77b3e2e3603d97ab0 /scripts | |
parent | 482a6ce8cbdde82fecfabd4a47a7720b54676a54 (diff) | |
download | stable-diffusion-webui-gfx803-095830e1e8a99276b3055c720981e89fc6af853d.tar.gz stable-diffusion-webui-gfx803-095830e1e8a99276b3055c720981e89fc6af853d.tar.bz2 stable-diffusion-webui-gfx803-095830e1e8a99276b3055c720981e89fc6af853d.zip |
Prompts from file. How to? #248
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/prompts_from_file.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/prompts_from_file.py b/scripts/prompts_from_file.py new file mode 100644 index 00000000..da2ddd54 --- /dev/null +++ b/scripts/prompts_from_file.py @@ -0,0 +1,42 @@ +import math
+import os
+import sys
+import traceback
+
+import modules.scripts as scripts
+import gradio as gr
+
+from modules.processing import Processed, process_images
+from PIL import Image
+from modules.shared import opts, cmd_opts, state
+
+
+class Script(scripts.Script):
+ def title(self):
+ return "Prompts from file"
+
+ def ui(self, is_img2img):
+ file = gr.File(label="File with inputs", type='bytes')
+
+ return [file]
+
+ def run(self, p, data: bytes):
+ lines = [x.strip() for x in data.decode('utf8', errors='ignore').split("\n")]
+ lines = [x for x in lines if len(x) > 0]
+
+ batch_count = math.ceil(len(lines) / p.batch_size)
+ print(f"Will process {len(lines)} images in {batch_count} batches.")
+
+ p.batch_count = 1
+ p.do_not_save_grid = True
+
+ state.job_count = batch_count
+
+ images = []
+ for batch_no in range(batch_count):
+ state.job = f"{batch_no} out of {batch_count}"
+ p.prompt = lines[batch_no*p.batch_size:(batch_no+1)*p.batch_size]
+ proc = process_images(p)
+ images += proc.images
+
+ return Processed(p, images, p.seed, "")
|