aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-08-28 16:38:59 +0300
committerAUTOMATIC <16777216c@gmail.com>2022-08-28 16:38:59 +0300
commit93e7dbaa7164c3b7d1dcb6907d5908cc3fa29d30 (patch)
treef55c64d7fbdb051d84d0f0ebdba1da5cf69c134f /README.md
parentd5266c07f9e9b343884337a524ab0cb6e1033c6b (diff)
support for running custom code (primarily to generate various labeled grids)
export for 4chan option
Diffstat (limited to 'README.md')
-rw-r--r--README.md43
1 files changed, 43 insertions, 0 deletions
diff --git a/README.md b/README.md
index a3d722c8..8e40dc68 100644
--- a/README.md
+++ b/README.md
@@ -205,3 +205,46 @@ image will be upscaled to twice the original width and height, while width and h
will specify the size of individual tiles. At the moment this method does not support batch size.
![](images/sd-upscale.jpg)
+
+### User scripts
+If the program is launched with `--allow-code` option, an extra text input field for script code
+is available in txt2img interface. It allows you to input python code that will do the work with
+image. If this field is not empty, the processing that would happen normally is skipped.
+
+In code, access parameters from web UI using the `p` variable, and provide outputs for web UI
+using the `display(images, seed, info)` function. All globals from script are also accessible.
+
+As an example, here is a script that draws a chart seen below (and also saves it as `test/gnomeplot/gnome5.png`):
+
+```python
+steps = [4, 8,12,16, 20]
+cfg_scales = [5.0,10.0,15.0]
+
+def cell(x, y, p=p):
+ p.steps = x
+ p.cfg_scale = y
+ return process_images(p).images[0]
+
+images = [draw_xy_grid(
+ xs = steps,
+ ys = cfg_scales,
+ x_label = lambda x: f'Steps = {x}',
+ y_label = lambda y: f'CFG = {y}',
+ cell = cell
+)]
+
+save_image(images[0], 'test/gnomeplot', 'gnome5')
+display(images)
+```
+
+![](images/scripting.jpg)
+
+A more simple script that would just process the image and output it normally:
+
+```python
+processed = process_images(p)
+
+print("Seed was: " + str(processed.seed))
+
+display(processed.images, processed.seed, processed.info)
+```