115 lines
7.5 KiB
Markdown
115 lines
7.5 KiB
Markdown
# ComfyUI_SimpleButcher
|
|
|
|
### Why is this needed:
|
|
I needed to automate the process of generating images and could not find any straightforward ready-made solutions for this purpose. Hence, I developed my own solution. The primary idea is to replicate and expand `Forge's` functionality: specifically, the `Prompts from file or textbox` script. This will allow you to easily combine pre-prepared lists of prompts, LoRA, styles, allowing you to combine texts as you wish.
|
|
The resulting images prompt in metadata must be compatible with `Forge`, ideally appearing no different than those generated by it. However, I encountered a problem because `Forge` uses the internal name from the LoRA file metadata as the LoRA's name instead of the filename. Consequently, all existing solutions failed to comprehend my templates.
|
|
I also wish for the ability to write LoRA in any order and quantity within a text file using this format: `<lora:name:1.0>` or `<lora:name:unet=1.0:te=0.75>`. This should be automatically applied without the need to create separate nodes for each LoRA. Additionally, I would like it if the `CivitAI` platform could understand metadata. As the closest solution I found was the `alexopus/ComfyUI-Image-Saver` project. However, this alternative loses LORA written in `Forge` style by using the internal name instead of the filename.
|
|
|
|

|
|
[!] You need to remove the first node with empty text, so that it does not block the execution of the chain, since the text in it does not change.
|
|
|
|
## How to install?
|
|
|
|
### Method 1: Manager (Recommended)
|
|
If you have *ComfyUI-Manager*, you can click `Install via Git URL` and install these custom nodes `https://github.com/KLL535/ComfyUI_SimpleButcher.git`.
|
|
|
|
### Method 2: Manual
|
|
In Windows:
|
|
- run `cmd`, go to the ComfyUI folder
|
|
- `cd custom_nodes`
|
|
- `git clone https://github.com/KLL535/ComfyUI_SimpleButcher.git`
|
|
- `cd ComfyUI_SimpleButcher`
|
|
- `.\..\..\..\python_embeded\python.exe -s -m pip install -r requirements.txt`
|
|
- Start/restart ComfyUI
|
|
|
|
## Node 1: Simple Load Line From Text File
|
|
Simple tool for loading prompts directly from a text file, enabling automation of the entire batch process. You can combine this nodes to generate fully randomized texts and LoRA, sourced from your own text and LORA templates.
|
|
|
|
#### Input:
|
|
- `start` - *INT* - Start position for increment or decrement methods.
|
|
- `load_file` - *BOOLEAN* - if True, load center of prompt from file.
|
|
- `file_path` - *STRING* - Path to the file from which the lines for the central part of the prompt will be taken.
|
|
- `next` - `increment` or `decrement` or `random` or `random no repetitions` - Option for enumerating lines, in case of randomness the start parameter is ignored. In the latter case, the lines will be selected randomly, but without repetitions.
|
|
- `prefix` - *STRING* - Add text to the beginning of the prompt (optional).
|
|
- `postfix` - *STRING* - Add text to the ending of the prompt (optional).
|
|
#### Output:
|
|
- `text` - *STRING* - Output text based on the principle: `prefix` + `line from file` + `postfix`.
|
|
- `batch_counter` - *INT* - Current batch counter, if you start a new batch the counter will reset to 1.
|
|
- `line_counter` - *INT* - Current line counter from file.
|
|
- `lines` - *INT* - Total lines in file. If batch is greater than lines in file, they will be read in a loop.
|
|
|
|

|
|
|
|
## Node 2: Simple Extract Lora From Text
|
|
If the input text includes LoRA written in `Forge` style, such as `<lora:name:1.0>` or `<lora:name:unet=1.0:te=0.75>`, this node automatically segregates the text into separate prompts and LoRA.
|
|
|
|
#### Input:
|
|
- `text` - *STRING* - Text with mixed lora and prompt.
|
|
#### Output:
|
|
- `lora_text` - *STRING* - The text contains only lora
|
|
- `prompt` - *STRING* - The text contains only prompt
|
|
|
|

|
|
|
|
## Node 3: Simple Lora Loader
|
|
This tool can load multiple LoRAs described in Forge style, such as `<lora:name:1.0>` or `<lora:name:unet=1.0:te=0.75>`. It recognizes both file names and internal LoRA names obtained from the metadata of `*.safetensors` files via the `ss_output_name` field.
|
|
Upon initialization, it generates a `lora_name.json` dictionary, saving it in the LoRA folder to expedite future operations. Additionally, it creates a set of LoRA templates within the `__txt` directory. The hash values for all LoRAs are computed and stored once for efficient retrieval. For updates: if you update LoRAs place, add new LoRA, simply delete these files (`lora_name.json` and the LoRA templates) and press F5 in Confy-UI to reload them.
|
|
|
|
#### Input:
|
|
- `model` - *MODEL* - The diffusion model the LoRA will be applied to.
|
|
- `clip` - *CLIP* - The CLIP model the LoRA will be applied to.
|
|
- `lora_text` - *STRING* - Multiple LoRAs discriptions in Forge style: `<lora:name:1.0>` or `<lora:name:unet=1.0:te=0.75>`
|
|
- `multiple_strength_unet` - *FLOAT* - Multiple of unet strength. If there is a lot of lore, they can spoil the model, it is possible to multiply the weight of all incoming lore by this coefficient.
|
|
- `multiple_strength_clip` - *FLOAT* - Multiple of clip strength.
|
|
- `limit_strength_unet` - *FLOAT* - Max of unet strength. If there are a lot of lore, they can spoil the model, it is possible to limit the weight of all incoming lore to this number.
|
|
- `limit_strength_clip` - *FLOAT* - Max of clip strength.
|
|
#### Output:
|
|
- `model` - *MODEL* - Output diffusion model.
|
|
- `clip` - *CLIP* - Output CLIP model.
|
|
- `civitai_lora` - *STRING* - List of loras and their weights that were applied to the model.
|
|
- `civitai_lora_hash` - *STRING* - The first 10 characters of the hash sum of the loras, needed for the civitai of the site.
|
|
|
|

|
|
|
|
## Node 4: Simple Image Saver (as Forge)
|
|
Image Saver designed for saved metadata in `Forge`-style, allowing retrieval of LoRAs' names and hashes directly from the `Simple LoRA Loader node`. This tool automatically organizes output images into subfolders based on the date. The filenames of the saved files include a sequence number and seed.
|
|
|
|
#### Input:
|
|
- `images` - *IMAGE* - image(s) to save.
|
|
- `prompt` - *STRING*.
|
|
- `output_path` - *STRING* - Path where images will be saved.
|
|
- `SEED` - *INT*.
|
|
- `modelname` - *STRING* - Use `Checkpoint Loader with Name (Image Saver)` node.
|
|
##### Optional metadata (as Forge).
|
|
If not connected these lines will be missing:
|
|
- `steps` - *INT*.
|
|
- `sampler` - *any* - use `Sampler Selector (Image Saver)` node.
|
|
- `schedule` - *any* - use `Scheduler Selector (Image Saver)` node.
|
|
- `CFG_scale` - *FLOAT*.
|
|
- `distilled_CFG_scal` - *FLOAT*.
|
|
- `width` - *INT*.
|
|
- `height` - *INT*.
|
|
- `beta_schedule_alph` - *FLOAT*.
|
|
- `beta_schedule_beta` - *FLOAT*.
|
|
- `civitai_lora` - *STRING* - Loras name from `Simple Lora Loader` node.
|
|
- `civitai_lora_hash` - *STRING* - Loras hash from `Simple Lora Loader` node.
|
|
- `negative` - *STRING*.
|
|
#### Output:
|
|
- `metadata_text` - *STRING* - Metadata written to file.
|
|
|
|

|
|
|
|
## Info in terminal
|
|
3 node `Simple Load Line From Text File` running:
|
|
|
|

|
|
|
|
Maybe it will be useful to someone.
|
|
|
|
[!] Tested on Windows only. Tested on Flux only.
|
|
|
|
[!] The code from following resources were used:
|
|
https://github.com/Suzie1/ComfyUI_Guide_To_Making_Custom_Nodes
|
|
https://github.com/alexopus/ComfyUI-Image-Saver
|
|
https://github.com/AonekoSS/ComfyUI-SimpleCounter
|