Add an image gallery feature - #14
Conversation
run generate with `--gallery <dir>` to automatically save generated images in the specified directory. This also enables loading of the saved images at startup. Because generation parameters - prompt, sampling, loras, etc - are saved in the PNG metadata, it can also be reloaded into the UI. if gallery is not enabled, images are not saved to or loaded from disk, and no gallery element is present in the UI. Fixes lemonade-sdk#12
|
Derp. Forgot to document that in README. |
| _UI_DIR = os.path.join(os.path.dirname(__file__), "ui") | ||
|
|
||
|
|
||
| def _parse_gen_data(pnginfo: Any) -> dict | None: |
There was a problem hiding this comment.
metadata must be handled client-side. This already happens in the current webui so there is no reason to read all images and cache them
|
|
||
| def __init__(self, gallery_dir: str) -> None: | ||
| self.gallery_dir = gallery_dir | ||
| self._cache: dict[str, dict] = {} |
There was a problem hiding this comment.
this must also be removed, it is unbound
| # -- list ------------------------------------------------------------------ | ||
|
|
||
| def list_images(self) -> list[dict]: | ||
| """Return list of {filename, url, meta} dicts, newest first.""" |
There was a problem hiding this comment.
requires pagination as this can grow to literally any size
| | `--host` | `127.0.0.1` | Bind host | | ||
| | `--port` | `8000` | Bind port | | ||
| | `--upscaler-dir` | — | Directory containing pixel upscaler `.safetensors` files (e.g. Real-ESRGAN); selected per-request via `pixel_upscaler` | | ||
| | `--gallery` | — | Directory to use as a persistent image store. If enabled, it also displays previously saved images | |
| ) | ||
| else: | ||
| fname = ( | ||
| f"{datetime.now(timezone.utc).timestamp():010.3f}_" |
There was a problem hiding this comment.
let's add a prefix like "thenoise". The timestamp can be added as a decimal, I don't really think the 4 digit random number is necessary but it doesn't hurt I guess
There was a problem hiding this comment.
thenoise_YYmmdd_HHMMSSsss.png? I don't think too many people will be creating two images at exactly the same milliscone.
| if not self.active: | ||
| return None | ||
| pnginfo = getattr(image, "_pnginfo", None) | ||
| meta = _parse_gen_data(pnginfo) if pnginfo else None |
run generate with
--gallery <dir>to automatically save generated images in the specified directory. This also enables loading of the saved images at startup. Because generation parameters - prompt, sampling, loras, etc - are saved in the PNG metadata, it can also be reloaded into the UI.This also creates a gallery API to fetch the list of images in the gallery directory.
If gallery is not enabled, images are not saved to or loaded from disk, and no gallery element is present in the UI.
Fixes #12
Example:
./thenoise.sh serve --dit ./models/anima/split_files/diffusion_models/anima-turbo-v1.0.safetensors --vae ./models/anima/split_files/vae/qwen_image_vae.safetensors --text-encoder ./models/anima/split_files/text_encoders/qwen_3_06b_base.safetensors --host 127.0.0.1 --port 19000 --gallery images