├── tests ├── __init__.py ├── wildcards │ ├── testwc │ │ ├── test3.yaml │ │ └── test2.yaml │ ├── _invalid.txt │ ├── test.json │ └── test.yaml ├── wildcards2 │ └── text │ │ ├── wildcard1.txt │ │ ├── wildcard2.txt │ │ └── wildcard3.txt └── enmappings │ └── mappings.yaml ├── requirements.txt ├── ppp_icon.png ├── .markdownlint.jsonc ├── workflows ├── PPP example.jpg └── PPP example.json ├── .gitignore ├── images ├── prompt-postprocessor-icon.ai ├── prompt-postprocessor-icon.png └── prompt-postprocessor-icon.svg ├── metadata.ini ├── .vscode ├── settings.json └── launch.json ├── ppp_hosts.py ├── install.py ├── ppp_utils.py ├── pyproject.toml ├── .github ├── workflows │ └── publish.yml ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── pull_request_template.md ├── __init__.py ├── LICENSE.txt ├── ppp_cache.py ├── ppp_logging.py ├── README.md ├── .pylintrc ├── docs ├── CONFIG.md └── SYNTAX.md ├── grammar.lark ├── ppp_enmappings.py ├── ppp_wildcards.py ├── ppp_comfyui.py └── scripts └── ppp_script.py /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | lark 2 | numpy 3 | pyyaml -------------------------------------------------------------------------------- /tests/wildcards/testwc/test3.yaml: -------------------------------------------------------------------------------- 1 | one choice -------------------------------------------------------------------------------- /tests/wildcards/testwc/test2.yaml: -------------------------------------------------------------------------------- 1 | - one 2 | - 2 3 | - three -------------------------------------------------------------------------------- /tests/wildcards/_invalid.txt: -------------------------------------------------------------------------------- 1 | # invalid wildcard name 2 | choice1 3 | choice2 -------------------------------------------------------------------------------- /tests/wildcards2/text/wildcard1.txt: -------------------------------------------------------------------------------- 1 | # wildcard1 2 | choice1 3 | choice2 4 | choice3 -------------------------------------------------------------------------------- /ppp_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acorderob/sd-webui-prompt-postprocessor/HEAD/ppp_icon.png -------------------------------------------------------------------------------- /.markdownlint.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "MD013": false, 4 | "MD024": false, 5 | "MD033": false 6 | } -------------------------------------------------------------------------------- /workflows/PPP example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acorderob/sd-webui-prompt-postprocessor/HEAD/workflows/PPP example.jpg -------------------------------------------------------------------------------- /tests/wildcards2/text/wildcard2.txt: -------------------------------------------------------------------------------- 1 | # wildcard2 2 | r2-3$$-$$ 3 | 4::choice1 4 | 3:: choice2 5 | 2::choice3 6 | 5 if _is_sd1::choice4 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | 3 | .vscode/**/* 4 | !.vscode/settings.json 5 | !.vscode/launch.json 6 | 7 | tests/tests_local.py 8 | tests/logs 9 | -------------------------------------------------------------------------------- /images/prompt-postprocessor-icon.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acorderob/sd-webui-prompt-postprocessor/HEAD/images/prompt-postprocessor-icon.ai -------------------------------------------------------------------------------- /images/prompt-postprocessor-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acorderob/sd-webui-prompt-postprocessor/HEAD/images/prompt-postprocessor-icon.png -------------------------------------------------------------------------------- /tests/wildcards2/text/wildcard3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acorderob/sd-webui-prompt-postprocessor/HEAD/tests/wildcards2/text/wildcard3.txt -------------------------------------------------------------------------------- /metadata.ini: -------------------------------------------------------------------------------- 1 | [Extension] 2 | Name = sd-webui-prompt-postprocessor 3 | 4 | [Scripts] 5 | After = sd-dynamic-prompts, stable-diffusion-webui-wildcards 6 | -------------------------------------------------------------------------------- /tests/wildcards/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "json": { 3 | "wildcard1": [ 4 | "choice1", 5 | "choice2", 6 | "choice3" 7 | ], 8 | "wildcard2": [ 9 | "r2-3$$-$$", 10 | "4::choice1", 11 | "3:: choice2 ", 12 | "2::choice3", 13 | "5 if _is_sd1::choice4" 14 | ], 15 | "wildcard3": [ 16 | "__2$$,$$json/wildcard2__" 17 | ] 18 | } 19 | } -------------------------------------------------------------------------------- /tests/enmappings/mappings.yaml: -------------------------------------------------------------------------------- 1 | lora: 2 | lora1: 3 | - condition: _is_pony 4 | name: lorapony 5 | parameters: 0.8 6 | triggers: ["triggerpony1", "triggerpony2"] 7 | - condition: _is_illustrious 8 | name: loraillustrious 9 | parameters: "0.9:0.8" 10 | triggers: ["triggerillustrious1", "triggerillustrious2"] 11 | - triggers: ["triggergeneric1", "triggergeneric2", "{one|two}"] 12 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.analysis.extraPaths": ["../.."], 3 | "python.testing.unittestArgs": [ 4 | "-v", 5 | "-s", 6 | "./tests", 7 | "-p", 8 | "test*.py" 9 | ], 10 | "python.testing.pytestEnabled": false, 11 | "python.testing.unittestEnabled": true, 12 | "python.analysis.typeCheckingMode": "off", 13 | "black-formatter.args": [ 14 | "--line-length=120" 15 | ] 16 | } -------------------------------------------------------------------------------- /ppp_hosts.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | 3 | 4 | class SUPPORTED_APPS(Enum): 5 | comfyui = "comfyui" 6 | a1111 = "a1111" 7 | forge = "forge" 8 | reforge = "reforge" 9 | sdnext = "sdnext" 10 | 11 | SUPPORTED_APPS_NAMES = { 12 | SUPPORTED_APPS.comfyui: "ComfyUI", 13 | SUPPORTED_APPS.sdnext: "SD.Next", 14 | SUPPORTED_APPS.forge: "Forge", 15 | SUPPORTED_APPS.reforge: "reForge", 16 | SUPPORTED_APPS.a1111: "A1111 (or compatible)", 17 | } 18 | -------------------------------------------------------------------------------- /install.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | requirements_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.txt") 4 | 5 | try: 6 | from modules.launch_utils import requirements_met, run_pip # A1111 7 | 8 | if not requirements_met(requirements_filename): 9 | run_pip(f'install -r "{requirements_filename}"', "requirements for Prompt Post-Processor") 10 | except ImportError: 11 | import launch 12 | 13 | launch.run_pip(f'install -r "{requirements_filename}"', "requirements for Prompt Post-Processor") 14 | -------------------------------------------------------------------------------- /ppp_utils.py: -------------------------------------------------------------------------------- 1 | def deep_freeze(obj): 2 | """ 3 | Deep freeze an object. 4 | 5 | Args: 6 | obj (object): The object to freeze. 7 | 8 | Returns: 9 | object: The frozen object. 10 | """ 11 | if isinstance(obj, dict): 12 | return tuple((k, deep_freeze(v)) for k, v in sorted(obj.items())) 13 | if isinstance(obj, list): 14 | return tuple(deep_freeze(i) for i in obj) 15 | if isinstance(obj, set): 16 | return tuple(deep_freeze(i) for i in sorted(obj)) 17 | return obj 18 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "sd-webui-prompt-postprocessor" 3 | description = "Stable Diffusion WebUI & ComfyUI extension to post-process the prompt, including sending content from the prompt to the negative prompt and wildcards." 4 | version = "2.13.1" 5 | license = { file = "LICENSE.txt" } 6 | dependencies = ["lark", "numpy", "pyyaml"] 7 | 8 | [project.urls] 9 | Repository = "https://github.com/acorderob/sd-webui-prompt-postprocessor" 10 | # Used by Comfy Registry https://comfyregistry.org 11 | 12 | [tool.comfy] 13 | PublisherId = "acorderob" 14 | DisplayName = "sd-webui-prompt-postprocessor" 15 | Icon = "ppp_icon.png" 16 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Comfy registry 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | paths: 9 | - "pyproject.toml" 10 | 11 | permissions: 12 | issues: write 13 | 14 | jobs: 15 | publish-node: 16 | name: Publish Custom Node to registry 17 | runs-on: ubuntu-latest 18 | if: ${{ github.repository_owner == 'acorderob' }} 19 | steps: 20 | - name: Check out code 21 | uses: actions/checkout@v4 22 | - name: Publish Custom Node 23 | uses: Comfy-Org/publish-node-action@v1 24 | with: 25 | ## Add your own personal access token to your Github Repository secrets and reference it here. 26 | personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }} 27 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python Debugger: Attach using Process Id", 9 | "type": "debugpy", 10 | "request": "attach", 11 | "processId": "${command:pickProcess}" 12 | }, 13 | { 14 | "name": "Tests", 15 | "type": "debugpy", 16 | "request": "launch", 17 | "program": "tests/tests.py", 18 | "console": "integratedTerminal", 19 | "justMyCode": true 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[Request]" 5 | assignees: acorderob 6 | 7 | --- 8 | 9 | ## Prerequisites 10 | 11 | Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.** 12 | 13 | - [ ] I am running the latest version 14 | - [ ] I checked the documentation and found no answer 15 | - [ ] I checked to make sure that this issue has not already been filed 16 | - [ ] I'm reporting the issue to the correct repository (for multi-repository projects) 17 | 18 | ## Description 19 | 20 | A clear and concise description of the feature that you want. 21 | 22 | ## Additional context 23 | 24 | Add any other context or screenshots about the feature request here. 25 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: ACB 3 | @title: Prompt Post Processor 4 | @nickname: ACB PPP 5 | @description: Node for processing prompts. Includes the following options: send to negative prompt, set variables, if/elif/else command for conditional content, wildcards and choices. 6 | """ 7 | 8 | import sys 9 | import os 10 | 11 | sys.path.append(os.path.dirname(os.path.abspath(__file__))) 12 | 13 | from .ppp_comfyui import PromptPostProcessorComfyUINode, PromptPostProcessorSelectVariableComfyUINode 14 | 15 | NODE_CLASS_MAPPINGS = { 16 | "ACBPromptPostProcessor": PromptPostProcessorComfyUINode, 17 | "ACBPPPSelectVariable": PromptPostProcessorSelectVariableComfyUINode, 18 | } 19 | NODE_DISPLAY_NAME_MAPPINGS = { 20 | "ACBPromptPostProcessor": "ACB Prompt Post Processor", 21 | "ACBPPPSelectVariable": "ACB PPP Select Variable", 22 | } 23 | 24 | __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] 25 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 Antonio Cordero Balcazar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ppp_cache.py: -------------------------------------------------------------------------------- 1 | from collections import OrderedDict 2 | from logging import Logger 3 | from typing import Tuple 4 | 5 | from ppp_logging import DEBUG_LEVEL # pylint: disable=import-error 6 | 7 | 8 | class PPPLRUCache: 9 | 10 | ProcessInput = Tuple[int, int, str, str] # (seed, wildcards_hash, positive_prompt, negative_prompt) 11 | ProcessResult = Tuple[str, str] # (positive_prompt, negative_prompt) 12 | 13 | def __init__(self, capacity: int, logger: Logger = None, debug_level: DEBUG_LEVEL = DEBUG_LEVEL.none): 14 | self.cache = OrderedDict() 15 | self.capacity = capacity 16 | self._logger = logger 17 | self._debug_level = debug_level 18 | 19 | def get(self, key: ProcessInput) -> ProcessResult: 20 | if key not in self.cache: 21 | return None 22 | self.cache.move_to_end(key) 23 | return self.cache[key] 24 | 25 | def put(self, key: ProcessInput, value: ProcessResult) -> None: 26 | self.cache[key] = value 27 | self.cache.move_to_end(key) 28 | if len(self.cache) > self.capacity: 29 | self.cache.popitem(last=False) 30 | # if self._logger is not None and self._debug_level != DEBUG_LEVEL.none: 31 | # self._logger.debug(f"Cache size: {self.cache.__sizeof__()}") 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Issue report 3 | about: Create a report to help us improve 4 | title: "[Issue] " 5 | assignees: acorderob 6 | 7 | --- 8 | 9 | ## Prerequisites 10 | 11 | Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.** 12 | 13 | - [ ] I am running the latest version 14 | - [ ] I checked the documentation and found no answer 15 | - [ ] I checked to make sure that this issue has not already been filed 16 | - [ ] I'm reporting the issue to the correct repository (for multi-repository projects) 17 | 18 | ## Current Behavior 19 | 20 | What is the current behavior? 21 | 22 | ## Expected Behavior 23 | 24 | Please describe the behavior you are expecting 25 | 26 | ## Failure Information (for bugs) 27 | 28 | Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template. 29 | 30 | ## Steps to Reproduce 31 | 32 | Please provide detailed steps for reproducing the issue. 33 | 34 | 1. step 1 35 | 2. step 2 36 | 3. you get it... 37 | 38 | ## Context 39 | 40 | Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. 41 | 42 | - WebUI used and version: 43 | 44 | ## Failure Logs 45 | 46 | Please include any relevant log snippets or files here. 47 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Pull Request 2 | 3 | ## Description 4 | 5 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 6 | 7 | Fixes # (issue) 8 | 9 | ## Type of change 10 | 11 | Please delete options that are not relevant. 12 | 13 | - [ ] Bug fix (non-breaking change which fixes an issue) 14 | - [ ] New feature (non-breaking change which adds functionality) 15 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 16 | - [ ] This change requires a documentation update 17 | 18 | ## How Has This Been Tested? 19 | 20 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration 21 | 22 | - [ ] Test A 23 | - [ ] Test B 24 | 25 | **Test Configuration**: 26 | 27 | - WebUI used and version: 28 | 29 | ## Checklist 30 | 31 | - [ ] My code follows the style guidelines of this project 32 | - [ ] I have performed a self-review of my own code 33 | - [ ] I have commented my code, particularly in hard-to-understand areas 34 | - [ ] I have made corresponding changes to the documentation 35 | - [ ] My changes generate no new warnings 36 | - [ ] I have added tests that prove my fix is effective or that my feature works 37 | - [ ] New and existing unit tests pass locally with my changes 38 | - [ ] Any dependent changes have been merged and published in downstream modules 39 | - [ ] I have checked my code and corrected any misspellings 40 | -------------------------------------------------------------------------------- /tests/wildcards/test.yaml: -------------------------------------------------------------------------------- 1 | yaml: 2 | wildcard1: 3 | - choice1 4 | - choice2 5 | - choice3 6 | 7 | wildcard2: 8 | - ~r2-3$$-$$ 9 | - "'label1,label2'4::choice1" 10 | - "3:: choice2 " 11 | - { labels: ["label1", "label3"], weight: 2, content: choice3 } 12 | - 5 if _is_sd1::choice4 13 | 14 | wildcard2bis: 15 | - __1$$yaml/wildcard2'^yaml/wildcard2bis'__bis 16 | 17 | wildcard2bisbis: 18 | - __1$$yaml/wildcard2bis'#^yaml/wildcard2bisbis'__bis 19 | 20 | wildcard3: 21 | - __2$$,$$yaml/wildcard2__ 22 | 23 | wildcard4: inline text 24 | 25 | wildcard5: inline ${var:default} 26 | 27 | wildcard6: 28 | - { weight: 2, text: choice1 } 29 | - { weight: 3, content: choice2 } 30 | - { text: choice3 } 31 | - { weight: 4, if: _is_ssd, text: choice4 } 32 | 33 | wildcard7: 34 | - 35 | - 36 | - 37 | 38 | wildcardPS: 39 | - { 40 | sampler: "~", 41 | repeating: false, 42 | optional: false, 43 | count: 2, 44 | prefix: "prefix-", 45 | suffix: "-suffix", 46 | separator: "/", 47 | } 48 | - { weight: 3, text: choice1 } 49 | - { weight: 2, text: choice2 } 50 | - { weight: 1, text: choice3 } 51 | 52 | more_nested: 53 | even_more_nested: # this would be __yaml/more_nested/even_more_nested__ 54 | - one 55 | - two 56 | 57 | anonwildcards: 58 | - one 59 | - two 60 | - # choice without options and anonymous wildcard 61 | - three 62 | - four 63 | - 3 if _is_sdxl: # choice with options and anonymous wildcard 64 | - five 65 | - six 66 | - { weight: 1, text: [seven, eight] } # anonymous wildcard used in a choice in object format 67 | - # choice without options and anonymous wildcard with parameters 68 | - { count: 2, prefix: "#" } 69 | - nine 70 | - ten 71 | 72 | empty_wildcard: 73 | - o$$ # parameters: optional 74 | - if false::1 75 | - if false::2 76 | - if false::3 77 | - if _sd in ("test1", "test2")::4 78 | - if (false or false)::5 79 | 80 | circular1: 81 | - 5::__yaml/circular2__ 82 | - choice1 83 | - choice2 84 | 85 | circular2: 86 | - choice3 87 | - choice4 88 | - 5::__yaml/circular1__ 89 | 90 | including: 91 | - "%0.5::include yaml/wildcard1" 92 | - choice4 93 | - choice5 94 | - "%0.2::include yaml/wildcard7" 95 | 96 | including1: 97 | - choice1 98 | - choice2 99 | - "%5::include yaml/including2" 100 | 101 | including2: 102 | - choice3 103 | - choice4 104 | - "%5::include yaml/including1" 105 | -------------------------------------------------------------------------------- /ppp_logging.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | import logging 3 | import sys 4 | import copy 5 | from ppp_hosts import SUPPORTED_APPS # pylint: disable=import-error 6 | 7 | 8 | class DEBUG_LEVEL(Enum): 9 | none = "none" 10 | minimal = "minimal" 11 | full = "full" 12 | 13 | 14 | class PromptPostProcessorLogFactory: # pylint: disable=too-few-public-methods 15 | """ 16 | Factory class for creating loggers for the PromptPostProcessor module. 17 | """ 18 | 19 | class ColoredFormatter(logging.Formatter): 20 | """ 21 | A custom logging formatter that adds color to log records based on their level. 22 | 23 | Attributes: 24 | COLORS (dict): A dictionary mapping log levels to ANSI escape codes for colors. 25 | 26 | Methods: 27 | format(record): Formats the log record with color based on its level. 28 | 29 | """ 30 | 31 | COLORS = { 32 | "DEBUG": "\033[0;36m", # CYAN 33 | "INFO": "\033[0;32m", # GREEN 34 | "WARNING": "\033[0;33m", # YELLOW 35 | "ERROR": "\033[0;31m", # RED 36 | "CRITICAL": "\033[0;37;41m", # WHITE ON RED 37 | "RESET": "\033[0m", # RESET COLOR 38 | } 39 | 40 | def format(self, record): 41 | """ 42 | Formats the log record with color based on the log level. 43 | 44 | Args: 45 | record (LogRecord): The log record to be formatted. 46 | 47 | Returns: 48 | str: The formatted log record. 49 | """ 50 | colored_record = copy.copy(record) 51 | levelname = colored_record.levelname 52 | seq = self.COLORS.get(levelname, self.COLORS["RESET"]) 53 | colored_record.levelname = f"{seq}{levelname:8s}{self.COLORS['RESET']}" 54 | return super().format(colored_record) 55 | 56 | def __init__(self, app: SUPPORTED_APPS = None, filename = None): # pylint: disable=unused-argument 57 | """ 58 | Initializes the PromptPostProcessor class. 59 | 60 | This method sets up the logger for the PromptPostProcessor class and configures its log level and handlers. 61 | 62 | Args: 63 | filename (str, optional): The name of the file to log to. Defaults to None. 64 | app (SUPPORTED_APPS): The application for which the logger is being created. 65 | 66 | Returns: 67 | None 68 | """ 69 | ppplog = logging.getLogger("PromptPostProcessor") 70 | ppplog.propagate = False 71 | if not ppplog.handlers: 72 | handler = logging.StreamHandler(sys.stdout) 73 | handler.setFormatter(self.ColoredFormatter("%(asctime)s %(levelname)s %(message)s")) 74 | ppplog.addHandler(handler) 75 | if filename is not None: 76 | file_handler = logging.FileHandler(filename, encoding="utf-8") 77 | file_handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s")) 78 | ppplog.addHandler(file_handler) 79 | ppplog.setLevel(logging.DEBUG) 80 | self.log = PromptPostProcessorLogCustomAdapter(ppplog) 81 | 82 | 83 | class PromptPostProcessorLogCustomAdapter(logging.LoggerAdapter): 84 | """ 85 | Custom logger adapter for the PromptPostProcessor. 86 | This adapter adds a prefix to log messages to indicate that they are related to the PromptPostProcessor. 87 | """ 88 | 89 | def process(self, msg, kwargs): 90 | """ 91 | Process the log message and keyword arguments. 92 | Args: 93 | msg (str): The log message. 94 | kwargs (dict): The keyword arguments. 95 | Returns: 96 | tuple: A tuple containing the processed log message and keyword arguments. 97 | """ 98 | return f"[PPP] {msg}", kwargs 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prompt PostProcessor for Stable Diffusion WebUI and ComfyUI 2 | 3 | The Prompt PostProcessor (PPP), formerly known as "sd-webui-sendtonegative", is an extension designed to process the prompt, possibly after other extensions have modified it. This extension is compatible with: 4 | 5 | * [ComfyUI](https://github.com/comfyanonymous/ComfyUI) 6 | * [AUTOMATIC1111 Stable Diffusion WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 7 | * [Forge](https://github.com/lllyasviel/stable-diffusion-webui-forge) 8 | * [reForge](https://github.com/Panchovix/stable-diffusion-webui-reForge) 9 | * ...and probably other forks 10 | 11 | Currently this extension has these functions: 12 | 13 | * Sending parts of the prompt to the negative prompt. This allows for useful tricks when using wildcards since you can add negative content from choices made in the positive prompt. 14 | * Set and modify local variables. 15 | * Filter content based on the loaded SD model or a variable. 16 | * Process wildcards. Compatible with Dynamic Prompts formats. Can also detect invalid wildcards and act as you choose. 17 | * Map extranetworks (LoRAs) depending on conditions (like the loaded model variant). 18 | * Clean up the prompt and negative prompt. 19 | 20 | Note: when used in an *A1111* compatible webui, the extension must be loaded after any other extension that modifies the prompt (like another wildcards extension). Usually extensions load by their folder name in alphanumeric order, so if the extensions are not loading in the correct order just rename this extension's folder so the ordering works out. When in doubt, just rename this extension's folder with a "z" in front (for example) so that it is the last one to load, or manually set such folder name when installing it. 21 | 22 | If the extension runs before others, like Dynamic Prompts, and the "Process wildcards" is enabled, the wildcards will be processed by PPP and those extensions will not get them. If you disable processing the wildcards, and intend another extension to process them, you should keep the "What to do with remaining wildcards?" option as "ignore". 23 | 24 | Notes: 25 | 26 | 1. Other than its own commands, it only recognizes regular *A1111* prompt formats. So: 27 | 28 | * **Attention**: `[prompt] (prompt) (prompt:weight)` 29 | * **Alternation**: `[prompt1|prompt2|...]` 30 | * **Scheduling**: `[prompt1:prompt2:step]` 31 | * **Extra networks**: `` 32 | * **BREAK**: `prompt1 BREAK prompt2` 33 | * **Composable Diffusion**: `prompt1:weight1 AND prompt2:weight2` 34 | 35 | In *SD.Next* that means only the *A1111* or *Full* parsers. It will warn you if you use the *Compel* parser. 36 | 37 | Does not recognize tokenizer separators like `TE2:` and `TE3:`, so sending to negative prompt from those sections of the prompt will not add them in the corresponding section of the negative prompt. 38 | 39 | *ComfyUI* only supports natively the attention using parenthesis, so the ones with the braces will be converted. The other constructs are not natively supported but some custom nodes implement them. 40 | 2. It recognizes wildcards in the `__wildcard__` and {choice|choice} formats (and almost everything that [Dynamic Prompts](https://github.com/adieyal/sd-dynamic-prompts) supports). 41 | 3. It does not create *AND/BREAK* constructs when moving content to the negative prompt. 42 | 43 | ## Installation 44 | 45 | On *A1111* compatible webuis: 46 | 47 | 1. Go to Extensions > Install from URL 48 | 2. Paste in the URL for extension's git repository text field 49 | 3. Click the Install button 50 | 4. Restart the webui 51 | 52 | On *SD.Next* I recommend you to disable the native wildcard processing and use the old UI. 53 | 54 | On *ComfyUI*: 55 | 56 | 1. Go to Manager > Custom Nodes Manager 57 | 2. Search for "Prompt PostProcessor" and install or click Install via Git URL and enter 58 | 3. Restart 59 | 60 | ## Usage 61 | 62 | See the [syntax documentation](docs/SYNTAX.md). 63 | 64 | ## Configuration 65 | 66 | See the [configuration documentation](docs/CONFIG.md). 67 | 68 | ## License 69 | 70 | MIT 71 | 72 | ## Contact 73 | 74 | If you have any questions or concerns, please leave an issue, or start a thread in the discussions. 75 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MAIN] 2 | 3 | [BASIC] 4 | argument-naming-style=snake_case 5 | attr-naming-style=snake_case 6 | class-attribute-naming-style=any 7 | class-const-naming-style=UPPER_CASE 8 | class-naming-style=PascalCase 9 | const-naming-style=snake_case 10 | docstring-min-length=-1 11 | function-naming-style=snake_case 12 | good-names=i,j,k,e,ex,ok,p 13 | good-names-rgxs= 14 | include-naming-hint=no 15 | inlinevar-naming-style=any 16 | method-naming-style=snake_case 17 | module-naming-style=snake_case 18 | name-group= 19 | no-docstring-rgx=^_ 20 | property-classes=abc.abstractproperty 21 | variable-naming-style=snake_case 22 | 23 | [CLASSES] 24 | check-protected-access-in-special-methods=no 25 | defining-attr-methods=__init__, 26 | __new__, 27 | setUp, 28 | asyncSetUp, 29 | __post_init__ 30 | exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit 31 | valid-classmethod-first-arg=cls 32 | valid-metaclass-classmethod-first-arg=mcs 33 | 34 | [DESIGN] 35 | exclude-too-few-public-methods= 36 | ignored-parents= 37 | max-args=10 38 | max-attributes=7 39 | max-bool-expr=5 40 | max-branches=12 41 | max-locals=15 42 | max-parents=7 43 | max-public-methods=20 44 | max-returns=6 45 | max-statements=50 46 | min-public-methods=2 47 | 48 | [EXCEPTIONS] 49 | overgeneral-exceptions=builtins.BaseException,builtins.Exception 50 | 51 | [FORMAT] 52 | expected-line-ending-format= 53 | ignore-long-lines=^\s*(# )??$ 54 | indent-after-paren=4 55 | indent-string=' ' 56 | max-line-length=200 57 | max-module-lines=9999 58 | single-line-class-stmt=no 59 | single-line-if-stmt=no 60 | 61 | [IMPORTS] 62 | allow-any-import-level= 63 | allow-reexport-from-package=no 64 | allow-wildcard-with-all=no 65 | deprecated-modules= 66 | ext-import-graph= 67 | import-graph= 68 | int-import-graph= 69 | known-standard-library= 70 | known-third-party=enchant 71 | preferred-modules= 72 | 73 | [LOGGING] 74 | logging-format-style=new 75 | logging-modules=logging 76 | 77 | [MESSAGES CONTROL] 78 | confidence=HIGH, 79 | CONTROL_FLOW, 80 | INFERENCE, 81 | INFERENCE_FAILURE, 82 | UNDEFINED 83 | # disable=C,R,W 84 | disable=raw-checker-failed, 85 | bad-inline-option, 86 | locally-disabled, 87 | file-ignored, 88 | suppressed-message, 89 | useless-suppression, 90 | deprecated-pragma, 91 | use-symbolic-message-instead, 92 | line-too-long, 93 | missing-function-docstring, 94 | missing-module-docstring, 95 | missing-class-docstring, 96 | logging-fstring-interpolation, 97 | import-outside-toplevel, 98 | consider-iterating-dictionary, 99 | wrong-import-position, 100 | unnecessary-lambda, 101 | consider-using-dict-items, 102 | dangerous-default-value, 103 | unnecessary-dunder-call, 104 | invalid-name, 105 | R0801, 106 | enable=c-extension-no-member 107 | 108 | [METHOD_ARGS] 109 | timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request 110 | 111 | [MISCELLANEOUS] 112 | notes=FIXME, 113 | XXX, 114 | TODO 115 | notes-rgx= 116 | 117 | [REFACTORING] 118 | max-nested-blocks=5 119 | never-returning-functions=sys.exit,argparse.parse_error 120 | 121 | [REPORTS] 122 | evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) 123 | msg-template= 124 | #output-format= 125 | reports=no 126 | score=no 127 | 128 | [SIMILARITIES] 129 | ignore-comments=yes 130 | ignore-docstrings=yes 131 | ignore-imports=yes 132 | ignore-signatures=yes 133 | min-similarity-lines=4 134 | 135 | [SPELLING] 136 | max-spelling-suggestions=4 137 | spelling-dict= 138 | spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: 139 | spelling-ignore-words= 140 | spelling-private-dict-file= 141 | spelling-store-unknown-words=no 142 | 143 | [STRING] 144 | check-quote-consistency=no 145 | check-str-concat-over-line-jumps=no 146 | 147 | [TYPECHECK] 148 | contextmanager-decorators=contextlib.contextmanager 149 | generated-members=numpy.*,torch.*,cv2.* 150 | ignore-none=yes 151 | ignore-on-opaque-inference=yes 152 | ignored-checks-for-mixins=no-member, 153 | not-async-context-manager, 154 | not-context-manager, 155 | attribute-defined-outside-init 156 | ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace 157 | missing-member-hint=yes 158 | missing-member-hint-distance=1 159 | missing-member-max-choices=1 160 | mixin-class-rgx=.*[Mm]ixin 161 | signature-mutators= 162 | 163 | [VARIABLES] 164 | additional-builtins= 165 | allow-global-unused-variables=yes 166 | allowed-redefined-builtins= 167 | callbacks=cb_, 168 | dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ 169 | ignored-argument-names=_.*|^ignored_|^unused_ 170 | init-import=no 171 | redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io 172 | -------------------------------------------------------------------------------- /docs/CONFIG.md: -------------------------------------------------------------------------------- 1 | # Prompt PostProcessor configuration 2 | 3 | ## ComfyUI specific (ACB Prompt Post Processor node) 4 | 5 | ### Inputs 6 | 7 | * **model**: Connect here the MODEL or a string with the model class name used by *ComfyUI*. Needed for the model kind system variables. 8 | * **modelname**: Name of the model. Needed for the model name system variables and detection of pony (this also requieres for the model to be SDXL). 9 | * **seed**: Connect here the seed used. By default it is -1 (random). 10 | * **pos_prompt**: Connect here the prompt text, or fill it as a widget. 11 | * **neg_prompt**: Connect here the negative prompt text, or fill it as a widget. 12 | * **wc_wildcards_input**: Wildcards definitions (in yaml or json format). Direct input added to the ones found in the wildcards folders. Allows wildcards to be included in the workflow. 13 | * **en_mappings_input**: Extranetwork Mappings definitions (in yaml format). Direct input added to the ones found in the extranetwork mappings folders. Allows the mappings to be included in the workflow. 14 | 15 | Other common settings (see [below](#common-settings)) also appear as inputs or widgets. 16 | 17 | ### Outputs 18 | 19 | The outputs are the final positive and negative prompt and a variables dictionary. 20 | 21 | You can use the "**ACB PPP Select Variable**" node to choose one and output its value. You can use this to send only part of the prompt to, for example, a detailer node. For example: 22 | 23 | With this prompt: `__quality__, 1girl, ${head:__eyes__, __hair__, __expression__}, __body__, __clothes__, __background__, __style__` then you extract the `head` variable and send that as prompt for the head/face detailer. 24 | 25 | ## A1111 (and compatible UIs) panel options 26 | 27 | * **Force equal seeds**: Changes the image seeds and variation seeds to be equal to the first of the batch. This allows using the same values for all the images in a batch. 28 | * **Unlink seed**: Uses the specified seed for the prompt generation instead of the one from the image. This seed is only used for wildcards and choices. 29 | * **Prompt seed**: The seed to use for the prompt generation. If -1 a random one will be used. 30 | * **Incremental seed**: When using a batch you can use this to set the rest of the prompt seeds with consecutive values. 31 | 32 | ## Common settings 33 | 34 | ### General settings 35 | 36 | * **Debug level**: what to write to the console. Note: in *SD.Next* debug messages only show if you launch it with the `--debug` argument. 37 | * **What to do on invalid content warnings?**: warn on the console or stop the generation. 38 | * **Model variant definitions**: definitions for model variants to be recognized based on strings found in the full filename. 39 | 40 | The format for each line is (with *kind* being one of the base model identifiers or not defined): 41 | 42 | ```name(kind)=comma separated list of substrings (case insensitive)``` 43 | 44 | The default value defines strings for *Pony* and *Illustrious* models. 45 | * **Apply in img2img**: check if you want to do the processing in img2img processes (*does not apply to the ComfyUI node*). 46 | * **Add original prompts to metadata**: adds original prompts to the metadata if they have changed (*does not apply to the ComfyUI node*). 47 | * **Extranetwork Mappings folders**: you can enter multiple folders separated by commas. In *ComfyUI* you can leave it empty and add a `ppp_extranetworkmappings` entry in the **extra_model_paths.yaml** file. 48 | 49 | ### Wildcard settings 50 | 51 | * **Process wildcards**: you can choose to process wildcards and choices with this extension or use a different one. 52 | * **Wildcards folders**: you can enter multiple folders separated by commas. In *ComfyUI* you can leave it empty and add a `ppp_wildcards` or `wildcards` entry in the **extra_model_paths.yaml** file. 53 | * **What to do with remaining wildcards?**: select what do you want to do with any found wildcards/choices (when process wildcards is off or after the processing). 54 | * **Ignore**: do not try to detect wildcards. 55 | * **Remove**: detect wildcards and remove them. 56 | * **Add visible warning**: detect wildcards and add a warning text to the prompt, that hopefully produces a noticeable generation. 57 | * **Stop the generation**: detect wildcards and stop the generation. 58 | * **Default separator used when adding multiple choices**: what do you want to use by default to separate multiple choices when the options allow it (by default it's ", "). 59 | * **Keep the order of selected choices**: if checked, a multiple choice construct will return them in the order they are in the construct. 60 | 61 | ### Send to negative prompt settings 62 | 63 | * **Separator used when adding to the negative prompt**: you can specify the separator used when adding to the negative prompt (by default it's ", "). 64 | * **Ignore repeated content**: it ignores repeated content to avoid repetitions in the negative prompt. 65 | 66 | ### Clean up settings 67 | 68 | * **Remove empty constructs**: removes attention/scheduling/alternation constructs when they are invalid. 69 | * **Remove extra separators**: removes unnecessary separators. This applies to the configured separator and regular commas. 70 | * **Remove additional extra separators**: removes unnecessary separators at start or end of lines. This applies to the configured separator and regular commas. 71 | * **The extra separators options also remove EOLs**: in the previous two options it also removes EOLs attached to the separators. 72 | * **Clean up around BREAKs**: removes consecutive BREAKs and unnecessary commas and space around them. 73 | * **Use EOL instead of Space before BREAKs**: add a newline before BREAKs. 74 | * **Clean up around ANDs**: removes consecutive ANDs and unnecessary commas and space around them. 75 | * **Use EOL instead of Space before ANDs**: add a newline before ANDs. 76 | * **Clean up around extra network tags**: removes spaces around them. 77 | * **Merge attention modifiers (weights) when possible**: it merges attention modifiers when possible (merges into one, multiplying their values). Only merges individually nested modifiers. 78 | * **Remove extra spaces**: removes other unnecessary spaces. 79 | 80 | Please note that *ComfyUI* does not natively support the `BREAK` and `AND` constructs, but the related settings are kept in that UI. 81 | 82 | ### Content removal settings 83 | 84 | * **Remove extra network tags**: removes all extra network tags. 85 | -------------------------------------------------------------------------------- /grammar.lark: -------------------------------------------------------------------------------- 1 | %import common (LETTER, DIGIT, INT, CNAME, SIGNED_NUMBER, NUMBER) 2 | 3 | _WHITESPACE: /\s+/ 4 | STRING: /("(?!"").*?(?${]|\\.)+/s // exclude only the starting ones 14 | ?plain_choice: /((?!__|\bAND\b|\${|\$\$)[^\\()\[\]:<>${|}~@]|\\.)+/s // add the specific internal choice ones 15 | ?plain_alternate: /((?!__|\bAND\b|\${)[^\\()\[\]:<>${|]|\\.)+/s // add the specific internal alternate ones 16 | ?plain_var: /((?!__|\bAND\b|\${)[^\\()\[\]:<>${}]|\\.)+/s // add the specific internal var ones 17 | ?specialchars: /[_{()\[\]:<>]|\$(?![{$])/ // include only the starting ones 18 | ?specialchars_negtag: /[_{()\[\]:<>!|}]|\$(?![{$])/ // add the internal negtag ones 19 | ?specialchars_alternate: /[_{()\[\]:<>|]|\$(?![{$])/ // add the internal alternate ones 20 | ?specialchars_choice: /[_{()\[\]:<>|}]|\$(?![{$])/ // add the internal choice ones 21 | ?specialchars_var: /[_{()\[\]:<>}]|\$(?![{$])/ // add the internal var ones 22 | ?numpar: _WHITESPACE? SIGNED_NUMBER _WHITESPACE? 23 | 24 | start: promptcomp | content 25 | 26 | // prompt composition with AND 27 | promptcomp.4: promptcomppart ( [ ":" numpar ] ( /\bAND\b/ promptcomppart [ ":" numpar ] )+ )+ 28 | promptcomppart: content 29 | 30 | // simple prompts 31 | 32 | ?old_content.2: ( attention | scheduled | alternate | extranetworktag )+ 33 | //#if ALLOW_NEW_CONTENT 34 | ?content.2: ( old_content | new_content | plain | specialchars )* 35 | ?content_choice.2: ( old_content | new_content | plain_choice | specialchars_choice )* 36 | ?content_var.2: ( old_content | new_content | plain_var | specialchars_var )* 37 | ?content_negtag.2: ( old_content | new_content_negtag | plain | specialchars_negtag )* 38 | ?content_alternate.2: ( old_content | new_content | plain_alternate | specialchars_alternate )* 39 | ?content_en.2: (new_content_en | plain | specialchars )* 40 | //#if ALLOW_WILDCARDS ALLOW_CHOICES ALLOW_COMMVARS 41 | ?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | wildcard | choices )+ 42 | ?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | wildcard | choices )+ 43 | ?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+ 44 | //#elif ALLOW_WILDCARDS !ALLOW_CHOICES ALLOW_COMMVARS 45 | ?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | wildcard )+ 46 | ?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | wildcard )+ 47 | ?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif )+ 48 | //#elif !ALLOW_WILDCARDS ALLOW_CHOICES ALLOW_COMMVARS 49 | ?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | choices )+ 50 | ?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext | choices )+ 51 | ?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+ 52 | //#elif ALLOW_WILDCARDS ALLOW_CHOICES !ALLOW_COMMVARS 53 | ?new_content.3: ( wildcard | choices )+ 54 | ?new_content_negtag.3: ( wildcard | choices )+ 55 | ?new_content_en.3: ( choices )+ 56 | //#elif ALLOW_WILDCARDS !ALLOW_CHOICES !ALLOW_COMMVARS 57 | ?new_content.3: ( wildcard )+ 58 | ?new_content_negtag.3: ( wildcard )+ 59 | ?new_content_en.3: /(?!)./ // never matches 60 | //#elif !ALLOW_WILDCARDS ALLOW_CHOICES !ALLOW_COMMVARS 61 | ?new_content.3: ( choices )+ 62 | ?new_content_negtag.3: ( choices )+ 63 | ?new_content_en.3: ( choices )+ 64 | //#elif !ALLOW_WILDCARDS !ALLOW_CHOICES ALLOW_COMMVARS 65 | ?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext )+ 66 | ?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | commandext )+ 67 | ?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif )+ 68 | //#else 69 | ?new_content.3: ( variableset | variableuse | commandstn | commandstni | commandset | commandecho | commandif | commandext | wildcard | choices )+ 70 | ?new_content_negtag.3: ( variableset | variableuse | commandset | commandecho | commandif | wildcard | commandext | choices )+ 71 | ?new_content_en.3: ( variableset | variableuse | commandset | commandecho | commandif | choices )+ 72 | //#endif 73 | //#else 74 | ?content.2: ( old_content | plain | specialchars )* 75 | ?content_choice.2: ( old_content | plain_choice | specialchars_choice )* 76 | ?content_var.2: ( old_content | plain_var | specialchars_var )* 77 | ?content_negtag.2: ( old_content | plain | specialchars_negtag )* 78 | ?content_alternate.2: ( old_content | plain_alternate | specialchars_alternate )* 79 | ?content_en.2: (plain | specialchars )* 80 | //#endif 81 | 82 | // attention modifiers 83 | attention: ( "(" content [ ":" numpar ] ")" ) | ( "[" content "]" ) 84 | 85 | // prompt scheduling and alternation 86 | alternate: "[" alternateoption ( "|" alternateoption )+ "]" 87 | alternateoption: content_alternate 88 | scheduled: "[" [ content ":" ] content ":" numpar "]" 89 | 90 | // extra network tags 91 | extranetworktag: "<" /(?!ppp:)\w+:/ encontent ">" 92 | ?encontent.3: content_en 93 | 94 | // command: stn (send to negative) 95 | commandstn: "" content_negtag "" 96 | commandstni: "" | ">" ) 97 | 98 | // command: if 99 | commandif.2: commandif_if commandif_elif* commandif_else? "" 100 | commandif_if: "" ifvalue 101 | commandif_elif: "" ifvalue 102 | commandif_else: "" ifvalue 103 | ifvalue.3: content 104 | 105 | // conditions 106 | ?condition: grouped_condition | ungrouped_condition 107 | ?ungrouped_condition: operation | basic_condition 108 | ?grouped_condition.8: "(" _WHITESPACE? condition _WHITESPACE? ")" 109 | ?basic_condition: comparison_simple_value | comparison_list_value | truthy_operand 110 | ?operation: operation_not | operation_and | operation_or 111 | operation_and: condition _WHITESPACE "and" _WHITESPACE condition 112 | operation_or: condition _WHITESPACE "or" _WHITESPACE condition 113 | operation_not: "not" ( ( _WHITESPACE ungrouped_condition ) | ( _WHITESPACE? grouped_condition ) ) 114 | truthy_operand: IDENTIFIER 115 | comparison_simple_value: IDENTIFIER _WHITESPACE ( /not/ _WHITESPACE )? /eq|ne|gt|lt|ge|le|contains/ _WHITESPACE SIMPLEVALUE 116 | comparison_list_value: IDENTIFIER _WHITESPACE ( /not/ _WHITESPACE )? /contains|in/ _WHITESPACE listvalue 117 | listvalue.9: "(" _WHITESPACE? SIMPLEVALUE ( _WHITESPACE? "," _WHITESPACE? SIMPLEVALUE )* _WHITESPACE? ")" 118 | 119 | // command: set 120 | commandset: "" commandsetcontent "" 121 | commandsetmodifiers: (_WHITESPACE /evaluate|ifundefined|add/ )+ 122 | ?commandsetcontent.3: content 123 | 124 | // command: echo 125 | commandecho: "" [ commandechodefault "" ] | "/>" ) 126 | ?commandechodefault.3: content 127 | 128 | // command: ext 129 | commandext: "" [ commandexttriggers "" ] | "/>" ) 130 | commandexttype: [/\$/] IDENTIFIER 131 | ?commandextid: STRING | CNAME 132 | ?commandextparams: STRING | SIGNED_NUMBER 133 | ?commandextif: "if" _WHITESPACE condition 134 | ?commandexttriggers.3: content 135 | 136 | // variable set 137 | variableset.2: "${" _WHITESPACE? IDENTIFIER [ variablesetmodifiers ] _WHITESPACE? "=" [ /!/ ] varvalue "}" 138 | variablesetmodifiers: /[+?!]+/ 139 | 140 | // variable use 141 | variableuse.2: "${" _WHITESPACE? IDENTIFIER _WHITESPACE? [ ":" varvalue ] "}" 142 | varvalue: content_var 143 | 144 | // wildcards 145 | wildcard.2: "__" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] wildcard_name [ wc_filter ] [ wildcardvar ] "__" 146 | wildcard_name.2: ( WC_NAME_PLAIN_START | variableuse | commandecho ) ( WC_NAME_PLAIN | variableuse | commandecho )* 147 | wc_filter: /["']/ ( [ /#/ ] wc_filter_or | ( /#?\^/ wildcard_name ) ) /["']/ 148 | wc_filter_or: wc_filter_and ( _WHITESPACE? "," _WHITESPACE? wc_filter_and )* 149 | wc_filter_and: INDEX ( _WHITESPACE? "+" _WHITESPACE? INDEX )* 150 | wildcardvar.7: "(" _WHITESPACE? IDENTIFIER _WHITESPACE? "=" varvalue ")" 151 | 152 | // choices 153 | choices.2: "{" [ choicesoptions_sampler | ( choicesoptions _WHITESPACE? "$$" ) ] choice ( "|" choice )* "}" 154 | 155 | choicesoptions: [ choicesoptions_sampler ] [ _WHITESPACE? choicesoptions_flags ] ( ( [ _WHITESPACE? choicesoptions_from ] "-" [ _WHITESPACE? choicesoptions_to ] ) | [ _WHITESPACE? choicesoptions_num ] ) [ _WHITESPACE? choicesoptions_sep ] 156 | choicesoptions_sampler: /[~@]/ // ~ for random, @ for cyclical 157 | choicesoptions_flags: /[ro]{1,2}/ // r for repeating, o for optional 158 | choicesoptions_num: INT 159 | choicesoptions_from: INT 160 | choicesoptions_to: INT 161 | choicesoptions_sep: "$$" plain 162 | 163 | choice: [ [ _WHITESPACE? choiceiscmd ] [ _WHITESPACE? choicelabels ] [ _WHITESPACE? choiceweight ] [ _WHITESPACE? choiceif ] _WHITESPACE? "::" ] choicevalue 164 | choiceiscmd: /%/ // the option text is a special command 165 | choicelabels: /["']/ IDENTIFIER ( _WHITESPACE? "," _WHITESPACE? IDENTIFIER )* /["']/ 166 | choiceweight: NUMBER 167 | choiceif: "if" _WHITESPACE condition 168 | choicevalue: content_choice 169 | 170 | -------------------------------------------------------------------------------- /workflows/PPP example.json: -------------------------------------------------------------------------------- 1 | {"id":"0f75c56e-adb4-41f6-b957-81b6772cb8b5","revision":0,"last_node_id":39,"last_link_id":100,"nodes":[{"id":17,"type":"PrimitiveInt","pos":[0,-480],"size":[315,82],"flags":{},"order":0,"mode":0,"inputs":[{"localized_name":"value","name":"value","type":"INT","widget":{"name":"value"},"link":null}],"outputs":[{"localized_name":"INT","name":"INT","type":"INT","links":[24,94]}],"title":"Seed","properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"PrimitiveInt"},"widgets_values":[189718398195680,"randomize"]},{"id":5,"type":"EmptyLatentImage","pos":[0,-840],"size":[315,106],"flags":{},"order":1,"mode":0,"inputs":[{"localized_name":"width","name":"width","type":"INT","widget":{"name":"width"},"link":null},{"localized_name":"height","name":"height","type":"INT","widget":{"name":"height"},"link":null},{"localized_name":"batch_size","name":"batch_size","type":"INT","widget":{"name":"batch_size"},"link":null}],"outputs":[{"localized_name":"LATENT","name":"LATENT","type":"LATENT","slot_index":0,"links":[2]}],"properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"EmptyLatentImage"},"widgets_values":[1024,1024,1]},{"id":27,"type":"PrimitiveStringMultiline","pos":[-100,-20],"size":[400,200],"flags":{},"order":2,"mode":0,"inputs":[{"localized_name":"value","name":"value","type":"STRING","widget":{"name":"value"},"link":null}],"outputs":[{"localized_name":"STRING","name":"STRING","type":"STRING","links":[95]}],"title":"wildcards","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PrimitiveStringMultiline"},"widgets_values":["color:\n - red\n - blonde\n - brunette\naction:\n - running\n - sleeping"]},{"id":9,"type":"SaveImage","pos":[1880,-820],"size":[210,270],"flags":{},"order":15,"mode":0,"inputs":[{"localized_name":"images","name":"images","type":"IMAGE","link":9},{"localized_name":"filename_prefix","name":"filename_prefix","type":"STRING","widget":{"name":"filename_prefix"},"link":null}],"outputs":[],"properties":{"cnr_id":"comfy-core","ver":"0.3.27"},"widgets_values":["ComfyUI"]},{"id":6,"type":"CLIPTextEncode","pos":[940,-520],"size":[240,88],"flags":{"collapsed":true},"order":7,"mode":0,"inputs":[{"localized_name":"clip","name":"clip","type":"CLIP","link":19},{"localized_name":"text","name":"text","type":"STRING","widget":{"name":"text"},"link":96}],"outputs":[{"localized_name":"CONDITIONING","name":"CONDITIONING","type":"CONDITIONING","slot_index":0,"links":[4]}],"properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"CLIPTextEncode"},"widgets_values":[""]},{"id":7,"type":"CLIPTextEncode","pos":[940,-460],"size":[220,88],"flags":{"collapsed":true},"order":9,"mode":0,"inputs":[{"localized_name":"clip","name":"clip","type":"CLIP","link":45},{"localized_name":"text","name":"text","type":"STRING","widget":{"name":"text"},"link":98}],"outputs":[{"localized_name":"CONDITIONING","name":"CONDITIONING","type":"CONDITIONING","slot_index":0,"links":[6]}],"properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"CLIPTextEncode"},"widgets_values":[""]},{"id":8,"type":"VAEDecode","pos":[1700,-800],"size":[210,46],"flags":{"collapsed":true},"order":14,"mode":0,"inputs":[{"localized_name":"samples","name":"samples","type":"LATENT","link":7},{"localized_name":"vae","name":"vae","type":"VAE","link":20}],"outputs":[{"localized_name":"IMAGE","name":"IMAGE","type":"IMAGE","slot_index":0,"links":[9]}],"properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"VAEDecode"},"widgets_values":[]},{"id":3,"type":"KSampler","pos":[1320,-740],"size":[315,571],"flags":{},"order":12,"mode":0,"inputs":[{"localized_name":"model","name":"model","type":"MODEL","link":16},{"localized_name":"positive","name":"positive","type":"CONDITIONING","link":4},{"localized_name":"negative","name":"negative","type":"CONDITIONING","link":6},{"localized_name":"latent_image","name":"latent_image","type":"LATENT","link":2},{"localized_name":"seed","name":"seed","type":"INT","widget":{"name":"seed"},"link":24},{"localized_name":"steps","name":"steps","type":"INT","widget":{"name":"steps"},"link":null},{"localized_name":"cfg","name":"cfg","type":"FLOAT","widget":{"name":"cfg"},"link":null},{"localized_name":"sampler_name","name":"sampler_name","type":"COMBO","widget":{"name":"sampler_name"},"link":null},{"localized_name":"scheduler","name":"scheduler","type":"COMBO","widget":{"name":"scheduler"},"link":null},{"localized_name":"denoise","name":"denoise","type":"FLOAT","widget":{"name":"denoise"},"link":null}],"outputs":[{"localized_name":"LATENT","name":"LATENT","type":"LATENT","slot_index":0,"links":[7]}],"properties":{"cnr_id":"comfy-core","ver":"0.3.27","Node name for S&R":"KSampler"},"widgets_values":[982251382500348,"randomize",20,8,"euler","normal",1]},{"id":25,"type":"PrimitiveStringMultiline","pos":[-100,-320],"size":[400,100],"flags":{},"order":3,"mode":0,"inputs":[{"localized_name":"value","name":"value","type":"STRING","widget":{"name":"value"},"link":null}],"outputs":[{"localized_name":"STRING","name":"STRING","type":"STRING","links":[91]}],"title":"positive input","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PrimitiveStringMultiline"},"widgets_values":["score_9, score_8_up, score_7_up, score_6_up, woman with __color__ hair, __action__"]},{"id":26,"type":"PrimitiveStringMultiline","pos":[-100,-160],"size":[400,88],"flags":{},"order":4,"mode":0,"inputs":[{"localized_name":"value","name":"value","type":"STRING","widget":{"name":"value"},"link":null}],"outputs":[{"localized_name":"STRING","name":"STRING","type":"STRING","links":[92]}],"title":"negative input","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PrimitiveStringMultiline"},"widgets_values":["score_4, score_5"]},{"id":35,"type":"PreviewAny","pos":[940,-400],"size":[320,120],"flags":{},"order":8,"mode":0,"inputs":[{"localized_name":"source","name":"source","type":"*","link":97}],"outputs":[],"title":"positive result","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PreviewAny"},"widgets_values":[]},{"id":36,"type":"PreviewAny","pos":[940,-240],"size":[320,120],"flags":{},"order":10,"mode":0,"inputs":[{"localized_name":"source","name":"source","type":"*","link":99}],"outputs":[],"title":"negative result","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PreviewAny"},"widgets_values":[]},{"id":20,"type":"ACBPPPSelectVariable","pos":[900,-20],"size":[220,60],"flags":{},"order":11,"mode":0,"inputs":[{"localized_name":"variables","name":"variables","type":"PPP_DICT","link":100},{"localized_name":"name","name":"name","shape":7,"type":"STRING","widget":{"name":"name"},"link":null}],"outputs":[{"localized_name":"value","name":"value","type":"STRING","links":[87]}],"properties":{"cnr_id":"sd-webui-prompt-postprocessor","ver":"5e3c8cbc44bacd3b4da2ef33588f152a571775dd","Node name for S&R":"ACBPPPSelectVariable"},"widgets_values":[""]},{"id":37,"type":"PreviewAny","pos":[1180,-60],"size":[440,520],"flags":{},"order":13,"mode":0,"inputs":[{"localized_name":"source","name":"source","type":"*","link":87}],"outputs":[],"title":"variables result","properties":{"cnr_id":"comfy-core","ver":"0.3.34","Node name for S&R":"PreviewAny"},"widgets_values":[]},{"id":16,"type":"Checkpoint Loader with Name (Image Saver)","pos":[-200,-660],"size":[516.5999755859375,118],"flags":{},"order":5,"mode":0,"inputs":[{"localized_name":"ckpt_name","name":"ckpt_name","type":"COMBO","widget":{"name":"ckpt_name"},"link":null}],"outputs":[{"localized_name":"MODEL","name":"MODEL","type":"MODEL","links":[16,90]},{"localized_name":"CLIP","name":"CLIP","type":"CLIP","links":[19,45]},{"localized_name":"VAE","name":"VAE","type":"VAE","links":[20]},{"localized_name":"model_name","name":"model_name","type":"STRING","links":[93]}],"properties":{"cnr_id":"comfyui-image-saver","ver":"f8520bcfe5339ba7b4bb64ba96f6ed03da87fb89","Node name for S&R":"Checkpoint Loader with Name (Image Saver)"},"widgets_values":["PDXL\\ponyDiffusionV6XL_v6StartWithThisOne.safetensors"]},{"id":39,"type":"ACBPromptPostProcessor","pos":[420,-380],"size":[400,866],"flags":{},"order":6,"mode":0,"inputs":[{"localized_name":"model","name":"model","shape":7,"type":"MODEL,STRING","link":90},{"localized_name":"pos_prompt","name":"pos_prompt","type":"STRING","widget":{"name":"pos_prompt"},"link":91},{"localized_name":"neg_prompt","name":"neg_prompt","type":"STRING","widget":{"name":"neg_prompt"},"link":92},{"localized_name":"modelname","name":"modelname","shape":7,"type":"STRING","widget":{"name":"modelname"},"link":93},{"localized_name":"seed","name":"seed","shape":7,"type":"INT","widget":{"name":"seed"},"link":94},{"localized_name":"debug_level","name":"debug_level","shape":7,"type":"COMBO","widget":{"name":"debug_level"},"link":null},{"localized_name":"on_warnings","name":"on_warnings","shape":7,"type":"COMBO","widget":{"name":"on_warnings"},"link":null},{"localized_name":"variants_definitions","name":"variants_definitions","shape":7,"type":"STRING","widget":{"name":"variants_definitions"},"link":null},{"localized_name":"wc_process_wildcards","name":"wc_process_wildcards","shape":7,"type":"BOOLEAN","widget":{"name":"wc_process_wildcards"},"link":null},{"localized_name":"wc_wildcards_folders","name":"wc_wildcards_folders","shape":7,"type":"STRING","widget":{"name":"wc_wildcards_folders"},"link":null},{"localized_name":"wc_wildcards_input","name":"wc_wildcards_input","shape":7,"type":"STRING","widget":{"name":"wc_wildcards_input"},"link":95},{"localized_name":"wc_if_wildcards","name":"wc_if_wildcards","shape":7,"type":"COMBO","widget":{"name":"wc_if_wildcards"},"link":null},{"localized_name":"wc_choice_separator","name":"wc_choice_separator","shape":7,"type":"STRING","widget":{"name":"wc_choice_separator"},"link":null},{"localized_name":"wc_keep_choices_order","name":"wc_keep_choices_order","shape":7,"type":"BOOLEAN","widget":{"name":"wc_keep_choices_order"},"link":null},{"localized_name":"stn_separator","name":"stn_separator","shape":7,"type":"STRING","widget":{"name":"stn_separator"},"link":null},{"localized_name":"stn_ignore_repeats","name":"stn_ignore_repeats","shape":7,"type":"BOOLEAN","widget":{"name":"stn_ignore_repeats"},"link":null},{"localized_name":"cleanup_extra_spaces","name":"cleanup_extra_spaces","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_extra_spaces"},"link":null},{"localized_name":"cleanup_empty_constructs","name":"cleanup_empty_constructs","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_empty_constructs"},"link":null},{"localized_name":"cleanup_extra_separators","name":"cleanup_extra_separators","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_extra_separators"},"link":null},{"localized_name":"cleanup_extra_separators2","name":"cleanup_extra_separators2","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_extra_separators2"},"link":null},{"localized_name":"cleanup_extra_separators_include_eol","name":"cleanup_extra_separators_include_eol","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_extra_separators_include_eol"},"link":null},{"localized_name":"cleanup_breaks","name":"cleanup_breaks","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_breaks"},"link":null},{"localized_name":"cleanup_breaks_eol","name":"cleanup_breaks_eol","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_breaks_eol"},"link":null},{"localized_name":"cleanup_ands","name":"cleanup_ands","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_ands"},"link":null},{"localized_name":"cleanup_ands_eol","name":"cleanup_ands_eol","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_ands_eol"},"link":null},{"localized_name":"cleanup_extranetwork_tags","name":"cleanup_extranetwork_tags","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_extranetwork_tags"},"link":null},{"localized_name":"cleanup_merge_attention","name":"cleanup_merge_attention","shape":7,"type":"BOOLEAN","widget":{"name":"cleanup_merge_attention"},"link":null},{"localized_name":"remove_extranetwork_tags","name":"remove_extranetwork_tags","shape":7,"type":"BOOLEAN","widget":{"name":"remove_extranetwork_tags"},"link":null}],"outputs":[{"localized_name":"pos_prompt","name":"pos_prompt","type":"STRING","links":[96,97]},{"localized_name":"neg_prompt","name":"neg_prompt","type":"STRING","links":[98,99]},{"localized_name":"variables","name":"variables","type":"PPP_DICT","links":[100]}],"properties":{"cnr_id":"sd-webui-prompt-postprocessor","ver":"8f7957c4ae814cfb56515c9fc5adeea3cd75e630","Node name for S&R":"ACBPromptPostProcessor"},"widgets_values":["","","",1019,"randomize","minimal","stop","pony(sdxl)=pony,pny,pdxl\nillustrious(sdxl)=illustrious,illust,ilxl",true,"","true","stop",", ",true,", ",true,true,true,true,true,true,true,true,true,true,true,true,true]}],"links":[[2,5,0,3,3,"LATENT"],[4,6,0,3,1,"CONDITIONING"],[6,7,0,3,2,"CONDITIONING"],[7,3,0,8,0,"LATENT"],[9,8,0,9,0,"IMAGE"],[16,16,0,3,0,"MODEL"],[19,16,1,6,0,"CLIP"],[20,16,2,8,1,"VAE"],[24,17,0,3,4,"INT"],[45,16,1,7,0,"CLIP"],[87,20,0,37,0,"*"],[90,16,0,39,0,"MODEL,STRING"],[91,25,0,39,1,"STRING"],[92,26,0,39,2,"STRING"],[93,16,3,39,3,"STRING"],[94,17,0,39,4,"INT"],[95,27,0,39,10,"STRING"],[96,39,0,6,1,"STRING"],[97,39,0,35,0,"*"],[98,39,1,7,1,"STRING"],[99,39,1,36,0,"*"],[100,39,2,20,0,"PPP_DICT"]],"groups":[],"config":{},"extra":{"ds":{"scale":0.8580000000000002,"offset":[526.5913159217441,989.5715392146044]},"frontendVersion":"1.16.8","reroutes":[{"id":2,"pos":[1280,-820],"linkIds":[20]},{"id":3,"pos":[780,-500],"linkIds":[19,45]},{"id":4,"pos":[580,-720],"linkIds":[16]}],"VHS_latentpreview":true,"VHS_latentpreviewrate":0,"VHS_MetadataImage":true,"VHS_KeepIntermediate":true,"linkExtensions":[{"id":16,"parentId":4},{"id":19,"parentId":3},{"id":20,"parentId":2},{"id":45,"parentId":3}]},"version":0.4} -------------------------------------------------------------------------------- /ppp_enmappings.py: -------------------------------------------------------------------------------- 1 | import os 2 | from typing import Optional 3 | import logging 4 | import yaml 5 | 6 | from ppp_logging import DEBUG_LEVEL # pylint: disable=import-error 7 | from ppp_utils import deep_freeze # pylint: disable=import-error 8 | 9 | 10 | class PPPENMappingVariant: 11 | """ 12 | A class to represent a variant of an extra network mapping. 13 | 14 | Attributes: 15 | condition (str): The condition for the variant. 16 | name (str): The name of the variant. 17 | parameters (float|str): The parameters for the variant. 18 | triggers (list[str]): The triggers for the variant. 19 | weight (float): The weight for the variant when multiple variants apply. 20 | """ 21 | 22 | def __init__(self, condition: str, name: str, parameters: float | str, triggers: list[str], weight: float): 23 | self.condition: str = condition 24 | self.name: str = name 25 | self.parameters: float | str = parameters 26 | self.triggers: list[str] = triggers 27 | self.weight: float = weight 28 | 29 | 30 | class PPPENMapping: 31 | """ 32 | A extra network mapping object. 33 | 34 | Attributes: 35 | kind (str): The kind of the extra network. 36 | name (str): The name of the extra network mapping. 37 | file (str): The path to the file where the extranetwork mapping is defined. 38 | variants (list[PPPENMappingVariant]): The processed variants of the extranetwork mapping. 39 | """ 40 | 41 | def __init__(self, fullpath: str, kind: str, name: str, variants: list[dict]): 42 | self.file: str = fullpath 43 | self.kind: str = kind 44 | self.name: str = name 45 | self.variants: list[PPPENMappingVariant] = [ 46 | PPPENMappingVariant( 47 | **{**{"condition": None, "name": None, "parameters": None, "triggers": None, "weight": 1.0}, **v} 48 | ) 49 | for v in variants 50 | ] 51 | 52 | def __hash__(self) -> int: 53 | t = (self.kind, self.name, deep_freeze(self.variants)) 54 | return hash(t) 55 | 56 | def __sizeof__(self): 57 | return self.kind.__sizeof__() + self.name.__sizeof__() + self.file.__sizeof__() + self.variants.__sizeof__() 58 | 59 | 60 | class PPPExtraNetworkMappings: 61 | """ 62 | A class to manage extra network mappings. 63 | 64 | Attributes: 65 | extranetwork_maps (dict[str, PPPENMapping]): The extra network mappings. 66 | """ 67 | 68 | DEFAULT_ENMAPPINGS_FOLDER = "extranetworkmappings" 69 | LOCALINPUT_FILENAME = "#INPUT" 70 | 71 | def __init__(self, logger): 72 | self.__logger: logging.Logger = logger 73 | self.__debug_level = DEBUG_LEVEL.none 74 | self.__enmappings_folders = [] 75 | self.__enmappings_files = {} 76 | self.extranetwork_mappings: dict[str, PPPENMapping] = {} 77 | self.cached_mappings = {} 78 | 79 | def __hash__(self) -> int: 80 | return hash(deep_freeze(self.extranetwork_mappings)) 81 | 82 | def __sizeof__(self): 83 | return ( 84 | self.extranetwork_mappings.__sizeof__() 85 | + self.__enmappings_folders.__sizeof__() 86 | + self.__enmappings_files.__sizeof__() 87 | + self.cached_mappings.__sizeof__() 88 | ) 89 | 90 | def refresh_extranetwork_mappings( 91 | self, debug_level: DEBUG_LEVEL, enmappings_folders: Optional[list[str]], enmappings_input: str = None 92 | ): 93 | """ 94 | Initialize the extra network mappings. 95 | """ 96 | self.__debug_level = debug_level 97 | self.__enmappings_folders = enmappings_folders or [] 98 | # if self.__debug_level != DEBUG_LEVEL.none: 99 | # self.__logger.info("Refreshing extra network mappings...") 100 | # t1 = time.monotonic_ns() 101 | self.cached_mappings = {} 102 | for fullpath in list(self.__enmappings_files.keys()): 103 | if fullpath != self.LOCALINPUT_FILENAME: 104 | path = os.path.dirname(fullpath) 105 | if not os.path.exists(fullpath) or not any( 106 | os.path.commonpath([path, folder]) == folder for folder in self.__enmappings_folders 107 | ): 108 | self.__remove_extranetwork_mappings_from_path(fullpath) 109 | elif enmappings_input is None: 110 | self.__remove_extranetwork_mappings_from_path(fullpath) 111 | if enmappings_folders is not None or enmappings_input is not None: 112 | if enmappings_folders is not None: 113 | for f in self.__enmappings_folders: 114 | self.__get_extranetwork_mappings_in_directory(f) 115 | if enmappings_input is not None: 116 | self.__get_extranetwork_mappings_in_input(enmappings_input) 117 | else: 118 | self.extranetwork_mappings = {} 119 | self.__enmappings_files = {} 120 | # t2 = time.monotonic_ns() 121 | # if self.__debug_level != DEBUG_LEVEL.none: 122 | # self.__logger.info(f"Extra network mappings refresh time: {(t2 - t1) / 1_000_000_000:.3f} seconds") 123 | 124 | # def get_extranetwork_mappings(self, key: str) -> list[PPPENMapping]: 125 | # """ 126 | # Get all extra network mappings that match a key. 127 | # 128 | # Args: 129 | # key (str): The key to match (kind:name). 130 | # 131 | # Returns: 132 | # list: A list of all extra network mappings that match the key. 133 | # """ 134 | # keys = sorted(fnmatch.filter(self.extranetwork_mappings.keys(), key)) 135 | # return [self.extranetwork_mappings[k] for k in keys] 136 | 137 | def __remove_extranetwork_mappings_from_path(self, full_path: str, debug=True): 138 | """ 139 | Clear all extra network mappings in a file. 140 | 141 | Args: 142 | full_path (str): The path to the file. 143 | debug (bool): Whether to print debug messages or not. 144 | """ 145 | last_modified_cached = self.__enmappings_files.get(full_path, None) # a time or a hash 146 | if debug and last_modified_cached is not None and self.__debug_level != DEBUG_LEVEL.none: 147 | if full_path == self.LOCALINPUT_FILENAME: 148 | self.__logger.debug("Removing extra network mappings from input") 149 | else: 150 | self.__logger.debug(f"Removing extra network mappings from file: {full_path}") 151 | if full_path in self.__enmappings_files.keys(): 152 | del self.__enmappings_files[full_path] 153 | for key in list(self.extranetwork_mappings.keys()): 154 | if self.extranetwork_mappings[key].file == full_path: 155 | del self.extranetwork_mappings[key] 156 | 157 | def __get_extranetwork_mappings_in_file(self, full_path: str): 158 | """ 159 | Get all extra network mappings in a file. 160 | 161 | Args: 162 | full_path (str): The path to the file. 163 | """ 164 | last_modified = os.path.getmtime(full_path) 165 | last_modified_cached = self.__enmappings_files.get(full_path, None) 166 | if last_modified_cached is not None and last_modified == self.__enmappings_files[full_path]: 167 | return 168 | filename = os.path.basename(full_path) 169 | _, extension = os.path.splitext(filename) 170 | if extension not in (".yaml", ".yml", ".json"): 171 | return 172 | self.__remove_extranetwork_mappings_from_path(full_path, False) 173 | if last_modified_cached is not None and self.__debug_level != DEBUG_LEVEL.none: 174 | self.__logger.debug(f"Updating extra network mappings from file: {full_path}") 175 | self.__get_extranetwork_mappings_in_structured_file(full_path) 176 | self.__enmappings_files[full_path] = last_modified 177 | 178 | def __get_extranetwork_mappings_in_input(self, enmappings_input: str): 179 | """ 180 | Get all extra network mappings in the string. 181 | 182 | Args: 183 | enmappings_input (str): The input string containing extra network mappings in yaml format. 184 | """ 185 | new_h = hash(enmappings_input) 186 | h = self.__enmappings_files.get(self.LOCALINPUT_FILENAME, None) 187 | if h == new_h: 188 | return 189 | self.__remove_extranetwork_mappings_from_path(self.LOCALINPUT_FILENAME, False) 190 | if h is not None and self.__debug_level != DEBUG_LEVEL.none: 191 | self.__logger.debug("Updating extra network mappings from input") 192 | enmappings_input = enmappings_input.strip() 193 | if enmappings_input != "": 194 | try: 195 | content = yaml.safe_load(enmappings_input) 196 | except yaml.YAMLError as e: 197 | self.__logger.warning(f"Invalid format for input extra network mappings: {e}") 198 | return 199 | if content is not None: 200 | self.__add_extranetwork_mapping(content, self.LOCALINPUT_FILENAME) 201 | self.__enmappings_files[self.LOCALINPUT_FILENAME] = new_h 202 | 203 | def __add_extranetwork_mapping(self, content: dict[str, dict[str, list[dict]]], full_path: str): 204 | """ 205 | Add an extra network mapping to the extra network mappings dictionary. 206 | 207 | Args: 208 | content (object): The content of the extra network mapping. 209 | full_path (str): The path to the file that contains it. 210 | """ 211 | if not isinstance(content, dict): 212 | self.__logger.warning(f"Invalid extra network mapping in file '{full_path}'!") 213 | return 214 | for kind, maps in content.items(): 215 | if not isinstance(maps, dict): 216 | self.__logger.warning(f"Invalid extra network mapping definition for '{kind}:*' in file '{full_path}'!") 217 | else: 218 | for name, variants in maps.items(): 219 | key = f"{kind}:{name}" 220 | if not isinstance(variants, list): 221 | self.__logger.warning( 222 | f"Invalid extra network mapping definition for '{key}' in file '{full_path}'!" 223 | ) 224 | elif self.extranetwork_mappings.get(key, None) is not None: 225 | self.__logger.warning( 226 | f"Duplicate extra network mapping '{key}' in file '{full_path}' and '{self.extranetwork_mappings[key].file}'!" 227 | ) 228 | elif not isinstance(variants, list) or not all(isinstance(v, dict) for v in variants): 229 | self.__logger.warning( 230 | f"Invalid extra network mapping definition for '{key}' in file '{full_path}'!" 231 | ) 232 | else: 233 | self.extranetwork_mappings[key] = PPPENMapping(full_path, kind, name, variants) 234 | 235 | def __get_extranetwork_mappings_in_structured_file(self, full_path): 236 | """ 237 | Get all extra network mappings in a structured file. 238 | 239 | Args: 240 | full_path (str): The path to the file. 241 | base (str): The base path for the extra network mappings. 242 | """ 243 | try: 244 | try: 245 | with open(full_path, "r", encoding="utf-8") as file: 246 | content = yaml.safe_load(file) 247 | except: # pylint: disable=bare-except 248 | self.__logger.warning(f"Could not read file '{full_path}' with utf-8 encoding, trying windows-1252...") 249 | with open(full_path, "r", encoding="windows-1252") as file: 250 | content = yaml.safe_load(file) 251 | self.__add_extranetwork_mapping(content, full_path) 252 | except Exception as e: # pylint: disable=broad-except 253 | self.__logger.error(f"Error reading extra network mappings from file '{full_path}': {e}") 254 | 255 | def __get_extranetwork_mappings_in_directory(self, directory: str): 256 | """ 257 | Get all extra network mappings in a directory. 258 | 259 | Args: 260 | directory (str): The path to the directory. 261 | """ 262 | if not os.path.exists(directory): 263 | self.__logger.warning(f"Extra network mappings directory '{directory}' does not exist!") 264 | return 265 | for filename in os.listdir(directory): 266 | full_path = os.path.abspath(os.path.join(directory, filename)) 267 | if os.path.basename(full_path).startswith("."): 268 | continue 269 | if os.path.isdir(full_path): 270 | self.__get_extranetwork_mappings_in_directory(full_path) 271 | elif os.path.isfile(full_path): 272 | self.__get_extranetwork_mappings_in_file(full_path) 273 | -------------------------------------------------------------------------------- /images/prompt-postprocessor-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | AAA0RGp1bWIAAAAeanVtZGMycGEAEQAQgAAAqgA4m3EDYzJwYQAAADQeanVtYgAAAEdqdW1kYzJtYQARABCAAACqADibcQN1cm46dXVpZDpjYmJmNGVmZC01MmJmLTQwZDYtOTllOC0xZjU0NjE5NWI3YTkAAAABtGp1bWIAAAApanVtZGMyYXMAEQAQgAAAqgA4m3EDYzJwYS5hc3NlcnRpb25zAAAAANdqdW1iAAAAJmp1bWRjYm9yABEAEIAAAKoAOJtxA2MycGEuYWN0aW9ucwAAAACpY2JvcqFnYWN0aW9uc4GjZmFjdGlvbmtjMnBhLmVkaXRlZG1zb2Z0d2FyZUFnZW50bUFkb2JlIEZpcmVmbHlxZGlnaXRhbFNvdXJjZVR5cGV4U2h0dHA6Ly9jdi5pcHRjLm9yZy9uZXdzY29kZXMvZGlnaXRhbHNvdXJjZXR5cGUvY29tcG9zaXRlV2l0aFRyYWluZWRBbGdvcml0aG1pY01lZGlhAAAArGp1bWIAAAAoanVtZGNib3IAEQAQgAAAqgA4m3EDYzJwYS5oYXNoLmRhdGEAAAAAfGNib3KlamV4Y2x1c2lvbnOBomVzdGFydBi/Zmxlbmd0aBlFsGRuYW1lbmp1bWJmIG1hbmlmZXN0Y2FsZ2ZzaGEyNTZkaGFzaFggUTM/POppFr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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPZZAQAVOkt2cIMJ0rhD/xzZAz3LNpo0i+hbYVc+Jvi47NmwLcw3PHFLV1XKzdEepOj0n/lGaIa+4TIJvxvlkvChWAWx4Lmb1xw7PYPWDa0fGHDFboIaHbYlXLQydQqExGapSfDKl2GH8fc8iBtiQGPxguO6zeRcuFN++liFrygRgQrN+XslGWD0OmB7AjS7Hgybch2MteEZJQnf8XVqoQM0aNv5pIsV7AT3/z9Dc7MsgnqY8mnaQPwSHVknfvIy2gyS34lVeNXJlBZ90rvXTeTC89WieM+SR7Bun57OIH5d7El1MVxf8d9TayRc5dmjcYyZ8etoz5CsMjomGbH7LEXEy3Au 3 | 4 | 5 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /ppp_wildcards.py: -------------------------------------------------------------------------------- 1 | import fnmatch 2 | import os 3 | from typing import Optional 4 | import logging 5 | import yaml 6 | 7 | from ppp_logging import DEBUG_LEVEL # pylint: disable=import-error 8 | from ppp_utils import deep_freeze # pylint: disable=import-error 9 | 10 | 11 | class PPPWildcard: 12 | """ 13 | A wildcard object. 14 | 15 | Attributes: 16 | key (str): The key of the wildcard. 17 | file (str): The path to the file where the wildcard is defined. 18 | unprocessed_choices (list[str]): The unprocessed choices of the wildcard. 19 | choices (list[dict]): The processed choices of the wildcard. 20 | options (dict): The options of the wildcard. 21 | """ 22 | 23 | def __init__(self, fullpath: str, key: str, choices: list[str]): 24 | self.key: str = key 25 | self.file: str = fullpath 26 | self.unprocessed_choices: list[str] = choices 27 | self.choices: list[dict] = None 28 | self.options: dict = None 29 | 30 | def __hash__(self) -> int: 31 | t = (self.key, deep_freeze(self.unprocessed_choices)) 32 | return hash(t) 33 | 34 | def __sizeof__(self): 35 | return ( 36 | self.key.__sizeof__() 37 | + self.file.__sizeof__() 38 | + self.unprocessed_choices.__sizeof__() 39 | + self.choices.__sizeof__() 40 | + self.options.__sizeof__() 41 | ) 42 | 43 | 44 | class PPPWildcards: 45 | """ 46 | A class to manage wildcards. 47 | 48 | Attributes: 49 | wildcards (dict[str, PPPWildcard]): The wildcards. 50 | """ 51 | 52 | DEFAULT_WILDCARDS_FOLDER = "wildcards" 53 | LOCALINPUT_FILENAME = "#INPUT" 54 | 55 | def __init__(self, logger): 56 | self.__logger: logging.Logger = logger 57 | self.__debug_level = DEBUG_LEVEL.none 58 | self.__wildcards_folders = [] 59 | self.__wildcard_files = {} 60 | self.wildcards: dict[str, PPPWildcard] = {} 61 | 62 | def __hash__(self) -> int: 63 | return hash(deep_freeze(self.wildcards)) 64 | 65 | def __sizeof__(self): 66 | return self.wildcards.__sizeof__() + self.__wildcards_folders.__sizeof__() + self.__wildcard_files.__sizeof__() 67 | 68 | def refresh_wildcards( 69 | self, 70 | debug_level: DEBUG_LEVEL, 71 | wildcards_folders: Optional[list[str]], 72 | wildcards_input: str = None, 73 | ): 74 | """ 75 | Initialize the wildcards. 76 | """ 77 | self.__debug_level = debug_level 78 | self.__wildcards_folders = wildcards_folders or [] 79 | # if self.__debug_level != DEBUG_LEVEL.none: 80 | # self.__logger.info("Refreshing wildcards...") 81 | # t1 = time.monotonic_ns() 82 | for fullpath in list(self.__wildcard_files.keys()): 83 | if fullpath != self.LOCALINPUT_FILENAME: 84 | path = os.path.dirname(fullpath) 85 | if not os.path.exists(fullpath): 86 | self.__remove_wildcards_from_path(fullpath) 87 | else: 88 | a = False 89 | for folder in self.__wildcards_folders: 90 | try: 91 | if os.path.commonpath([folder, path]) == folder: 92 | a = True 93 | break 94 | except ValueError: 95 | pass 96 | if not a: 97 | self.__remove_wildcards_from_path(fullpath) 98 | elif wildcards_input is None: 99 | self.__remove_wildcards_from_path(fullpath) 100 | if wildcards_folders is not None or wildcards_input is not None: 101 | if wildcards_folders is not None: 102 | for f in self.__wildcards_folders: 103 | self.__get_wildcards_in_directory(f, f) 104 | if wildcards_input is not None: 105 | self.__get_wildcards_in_input(wildcards_input) 106 | else: 107 | self.wildcards = {} 108 | self.__wildcard_files = {} 109 | # t2 = time.monotonic_ns() 110 | # if self.__debug_level != DEBUG_LEVEL.none: 111 | # self.__logger.info(f"Wildcards refresh time: {(t2 - t1) / 1_000_000_000:.3f} seconds") 112 | 113 | def get_wildcards(self, key: str) -> list[PPPWildcard]: 114 | """ 115 | Get all wildcards that match a key. 116 | 117 | Args: 118 | key (str): The key to match. 119 | 120 | Returns: 121 | list: A list of all wildcards that match the key. 122 | """ 123 | keys = sorted(fnmatch.filter(self.wildcards.keys(), key)) 124 | return [self.wildcards[k] for k in keys] 125 | 126 | def __get_keys_in_dict(self, dictionary: dict, prefix="") -> list[str]: 127 | """ 128 | Get all keys in a dictionary. 129 | 130 | Args: 131 | dictionary (dict): The dictionary to check. 132 | prefix (str): The prefix for the current key. 133 | 134 | Returns: 135 | list: A list of all keys in the dictionary, including nested keys. 136 | """ 137 | keys = [] 138 | for key in dictionary.keys(): 139 | if isinstance(dictionary[key], dict): 140 | keys.extend(self.__get_keys_in_dict(dictionary[key], prefix + key + "/")) 141 | else: 142 | keys.append(prefix + str(key)) 143 | return keys 144 | 145 | def __get_nested(self, dictionary: dict, keys: str) -> object: 146 | """ 147 | Get a nested value from a dictionary. 148 | 149 | Args: 150 | dictionary (dict): The dictionary to check. 151 | keys (str): The keys to get the value from. 152 | 153 | Returns: 154 | object: The value of the nested keys in the dictionary. 155 | """ 156 | keys = keys.split("/") 157 | current_dict = dictionary 158 | for key in keys: 159 | current_dict = current_dict.get(key) 160 | if current_dict is None: 161 | return None 162 | return current_dict 163 | 164 | def __remove_wildcards_from_path(self, full_path: str, debug=True): 165 | """ 166 | Clear all wildcards in a file. 167 | 168 | Args: 169 | full_path (str): The path to the file. 170 | debug (bool): Whether to print debug messages or not. 171 | """ 172 | last_modified_cached = self.__wildcard_files.get(full_path, None) # a time or a hash 173 | if debug and last_modified_cached is not None and self.__debug_level != DEBUG_LEVEL.none: 174 | if full_path == self.LOCALINPUT_FILENAME: 175 | self.__logger.debug("Removing from memory wildcards from input") 176 | else: 177 | self.__logger.debug(f"Removing from memory wildcards from file: {full_path}") 178 | if full_path in self.__wildcard_files.keys(): 179 | del self.__wildcard_files[full_path] 180 | for key in list(self.wildcards.keys()): 181 | if self.wildcards[key].file == full_path: 182 | del self.wildcards[key] 183 | 184 | def __get_wildcards_in_file(self, base, full_path: str): 185 | """ 186 | Get all wildcards in a file. 187 | 188 | Args: 189 | base (str): The base path for the wildcards. 190 | full_path (str): The path to the file. 191 | """ 192 | try: 193 | last_modified = os.path.getmtime(full_path) 194 | last_modified_cached = self.__wildcard_files.get(full_path, None) 195 | if last_modified_cached is not None and last_modified == self.__wildcard_files[full_path]: 196 | return 197 | filename = os.path.basename(full_path) 198 | _, extension = os.path.splitext(filename) 199 | if extension not in (".txt", ".json", ".yaml", ".yml"): 200 | return 201 | self.__remove_wildcards_from_path(full_path, False) 202 | if last_modified_cached is not None and self.__debug_level != DEBUG_LEVEL.none: 203 | self.__logger.debug(f"Updating wildcards from file: {full_path}") 204 | if extension == ".txt": 205 | self.__get_wildcards_in_text_file(full_path, base) 206 | elif extension in (".json", ".yaml", ".yml"): 207 | self.__get_wildcards_in_structured_file(full_path, base) 208 | self.__wildcard_files[full_path] = last_modified 209 | except Exception as e: # pylint: disable=broad-except 210 | self.__logger.error(f"Error reading wildcard file '{full_path}': {e}") 211 | 212 | def __get_wildcards_in_input(self, wildcards_input: str): 213 | """ 214 | Get all wildcards in the string. 215 | 216 | Args: 217 | wildcards_input (str): The input string containing wildcards in json or yaml format. 218 | """ 219 | try: 220 | new_h = hash(wildcards_input) 221 | h = self.__wildcard_files.get(self.LOCALINPUT_FILENAME, None) 222 | if h == new_h: 223 | return 224 | self.__remove_wildcards_from_path(self.LOCALINPUT_FILENAME, False) 225 | if h is not None and self.__debug_level != DEBUG_LEVEL.none: 226 | self.__logger.debug("Updating wildcards from input") 227 | wildcards_input = wildcards_input.strip() 228 | if wildcards_input != "": 229 | try: 230 | content = yaml.safe_load(wildcards_input) 231 | except yaml.YAMLError as e: 232 | self.__logger.warning(f"Invalid format for input wildcards: {e}") 233 | return 234 | if content is not None: 235 | self.__add_wildcard(content, self.LOCALINPUT_FILENAME, [self.LOCALINPUT_FILENAME]) 236 | self.__wildcard_files[self.LOCALINPUT_FILENAME] = new_h 237 | except Exception as e: # pylint: disable=broad-except 238 | self.__logger.error(f"Error reading wildcards input: {e}") 239 | 240 | def is_dict_choices_options(self, d: dict) -> bool: 241 | """ 242 | Check if a dictionary is a valid choices options dictionary. 243 | 244 | Args: 245 | d (dict): The dictionary to check. 246 | 247 | Returns: 248 | bool: Whether the dictionary is a valid choices options dictionary or not. 249 | """ 250 | return all( 251 | k in ["sampler", "repeating", "optional", "count", "from", "to", "prefix", "suffix", "separator"] 252 | for k in d.keys() 253 | ) 254 | 255 | def is_dict_choice_options(self, d: dict) -> bool: 256 | """ 257 | Check if a dictionary is a valid choice options dictionary. 258 | 259 | Args: 260 | d (dict): The dictionary to check. 261 | 262 | Returns: 263 | bool: Whether the dictionary is a valid choice options dictionary or not. 264 | """ 265 | return all(k in ["command", "labels", "weight", "if", "content", "text"] for k in d.keys()) 266 | 267 | def __get_choices(self, obj: object, full_path: str, key_parts: list[str]) -> list: 268 | """ 269 | We process the choices in the object and return them as a list. 270 | 271 | Args: 272 | obj (object): the value of a wildcard 273 | full_path (str): path to the file where the wildcard is defined 274 | key_parts (list[str]): parts of the key for the wildcard 275 | 276 | Returns: 277 | list: list of choices 278 | """ 279 | if obj is None: 280 | return None 281 | if isinstance(obj, (str, dict)): 282 | return [obj] 283 | if isinstance(obj, (int, float, bool)): 284 | return [str(obj)] 285 | if not isinstance(obj, list) or len(obj) == 0: 286 | self.__logger.warning(f"Invalid format in wildcard '{'/'.join(key_parts)}' in file '{full_path}'!") 287 | return None 288 | choices = [] 289 | for i, c in enumerate(obj): 290 | if isinstance(c, (str, int, float, bool)): 291 | choices.append(str(c)) 292 | elif isinstance(c, list): 293 | # we create an anonymous wildcard 294 | choices.append(self.__create_anonymous_wildcard(full_path, key_parts, i, c)) 295 | elif isinstance(c, dict): 296 | choices.append(self.__process_dict_choice(c, full_path, key_parts, i)) 297 | else: 298 | self.__logger.warning( 299 | f"Invalid choice {i+1} in wildcard '{'/'.join(key_parts)}' in file '{full_path}'!" 300 | ) 301 | return choices 302 | 303 | def __process_dict_choice(self, c: dict, full_path: str, key_parts: list[str], i: int) -> dict: 304 | """ 305 | Process a dictionary choice. 306 | 307 | Args: 308 | c (dict): The dictionary choice. 309 | full_path (str): The path to the file. 310 | key_parts (list[str]): The parts of the key. 311 | i (int): The index of the choice. 312 | 313 | Returns: 314 | dict: The processed choice. 315 | """ 316 | if self.is_dict_choices_options(c) or self.is_dict_choice_options(c): 317 | # we assume it is a choice or wildcard parameters in object format 318 | choice = c 319 | choice_content = choice.get("content", choice.get("text", None)) 320 | if choice_content is not None and isinstance(choice_content, list): 321 | # we create an anonymous wildcard 322 | choice["content"] = self.__create_anonymous_wildcard(full_path, key_parts, i, choice_content) 323 | if "text" in choice: 324 | del choice["text"] 325 | return choice 326 | if len(c) == 1: 327 | # we assume it is an anonymous wildcard with options 328 | firstkey = list(c.keys())[0] 329 | return self.__create_anonymous_wildcard(full_path, key_parts, i, c[firstkey], firstkey) 330 | self.__logger.warning(f"Invalid choice {i+1} in wildcard '{'/'.join(key_parts)}' in file '{full_path}'!") 331 | return None 332 | 333 | def __create_anonymous_wildcard(self, full_path, key_parts, i, content, options=None): 334 | """ 335 | Create an anonymous wildcard. 336 | 337 | Args: 338 | full_path (str): The path to the file that contains it. 339 | key_parts (list[str]): The parts of the key. 340 | i (int): The index of the wildcard. 341 | content (object): The content of the wildcard. 342 | options (str): The options for the choice where the wildcard is defined. 343 | 344 | Returns: 345 | str: The resulting value for the choice. 346 | """ 347 | new_parts = key_parts + [f"#ANON_{i}"] 348 | self.__add_wildcard(content, full_path, new_parts) 349 | value = f"__{'/'.join(new_parts)}__" 350 | if options is not None: 351 | value = f"{options}::{value}" 352 | return value 353 | 354 | def __add_wildcard(self, content: object, full_path: str, external_key_parts: list[str]): 355 | """ 356 | Add a wildcard to the wildcards dictionary. 357 | 358 | Args: 359 | content (object): The content of the wildcard. 360 | full_path (str): The path to the file that contains it. 361 | external_key_parts (list[str]): The parts of the key. 362 | """ 363 | key_parts = external_key_parts.copy() 364 | if isinstance(content, dict): 365 | key_parts.pop() 366 | keys = self.__get_keys_in_dict(content) 367 | for key in keys: 368 | tmp_key_parts = key_parts.copy() 369 | tmp_key_parts.extend(key.split("/")) 370 | fullkey = "/".join(tmp_key_parts) 371 | if self.wildcards.get(fullkey, None) is not None: 372 | self.__logger.warning( 373 | f"Duplicate wildcard '{fullkey}' in file '{full_path}' and '{self.wildcards[fullkey].file}'!" 374 | ) 375 | else: 376 | obj = self.__get_nested(content, key) 377 | choices = self.__get_choices(obj, full_path, tmp_key_parts) 378 | if choices is None: 379 | self.__logger.warning(f"Invalid wildcard '{fullkey}' in file '{full_path}'!") 380 | elif fullkey.startswith("_"): 381 | self.__logger.warning(f"Invalid wildcard name '{fullkey}' in file '{full_path}'! (cannot start with underscore)") 382 | else: 383 | self.wildcards[fullkey] = PPPWildcard(full_path, fullkey, choices) 384 | return 385 | if isinstance(content, str): 386 | content = [content] 387 | elif isinstance(content, (int, float, bool)): 388 | content = [str(content)] 389 | if not isinstance(content, list): 390 | self.__logger.warning(f"Invalid wildcard in file '{full_path}'!") 391 | return 392 | fullkey = "/".join(key_parts) 393 | if self.wildcards.get(fullkey, None) is not None: 394 | self.__logger.warning( 395 | f"Duplicate wildcard '{fullkey}' in file '{full_path}' and '{self.wildcards[fullkey].file}'!" 396 | ) 397 | else: 398 | choices = self.__get_choices(content, full_path, key_parts) 399 | if choices is None: 400 | self.__logger.warning(f"Invalid wildcard '{fullkey}' in file '{full_path}'!") 401 | elif fullkey.startswith("_"): 402 | self.__logger.warning(f"Invalid wildcard name '{fullkey}' in file '{full_path}'! (cannot start with underscore)") 403 | else: 404 | self.wildcards[fullkey] = PPPWildcard(full_path, fullkey, choices) 405 | 406 | def __get_wildcards_in_structured_file(self, full_path, base): 407 | """ 408 | Get all wildcards in a structured file. 409 | 410 | Args: 411 | full_path (str): The path to the file. 412 | base (str): The base path for the wildcards. 413 | """ 414 | external_key: str = os.path.relpath(os.path.splitext(full_path)[0], base) 415 | external_key_parts = external_key.split(os.sep) 416 | try: 417 | with open(full_path, "r", encoding="utf-8") as file: 418 | content = yaml.safe_load(file) 419 | except: # pylint: disable=bare-except 420 | self.__logger.warning(f"Could not read file '{full_path}' with utf-8 encoding, trying windows-1252...") 421 | with open(full_path, "r", encoding="windows-1252") as file: 422 | content = yaml.safe_load(file) 423 | self.__add_wildcard(content, full_path, external_key_parts) 424 | 425 | def __get_wildcards_in_text_file(self, full_path, base): 426 | """ 427 | Get all wildcards in a text file. 428 | 429 | Args: 430 | full_path (str): The path to the file. 431 | base (str): The base path for the wildcards. 432 | """ 433 | external_key: str = os.path.relpath(os.path.splitext(full_path)[0], base) 434 | external_key_parts = external_key.split(os.sep) 435 | try: 436 | with open(full_path, "r", encoding="utf-8") as file: 437 | text_content = map(lambda x: x.strip("\n\r"), file.readlines()) 438 | except: # pylint: disable=bare-except 439 | self.__logger.warning(f"Could not read file '{full_path}' with utf-8 encoding, trying windows-1252...") 440 | with open(full_path, "r", encoding="windows-1252") as file: 441 | text_content = map(lambda x: x.strip("\n\r"), file.readlines()) 442 | text_content = list(filter(lambda x: x.strip() != "" and not x.strip().startswith("#"), text_content)) 443 | text_content = [x.split("#")[0].rstrip() if len(x.split("#")) > 1 else x for x in text_content] 444 | self.__add_wildcard(text_content, full_path, external_key_parts) 445 | 446 | def __get_wildcards_in_directory(self, base: str, directory: str): 447 | """ 448 | Get all wildcards in a directory. 449 | 450 | Args: 451 | base (str): The base path for the wildcards. 452 | directory (str): The path to the directory. 453 | """ 454 | if not os.path.exists(directory): 455 | self.__logger.warning(f"Wildcard directory '{directory}' does not exist!") 456 | return 457 | for filename in os.listdir(directory): 458 | full_path = os.path.abspath(os.path.join(directory, filename)) 459 | if os.path.basename(full_path).startswith("."): 460 | continue 461 | if os.path.isdir(full_path): 462 | self.__get_wildcards_in_directory(base, full_path) 463 | elif os.path.isfile(full_path): 464 | self.__get_wildcards_in_file(base, full_path) 465 | -------------------------------------------------------------------------------- /docs/SYNTAX.md: -------------------------------------------------------------------------------- 1 | # Prompt PostProcessor syntax 2 | 3 | ## Commands 4 | 5 | The extension uses a format for its commands similar to an extranetwork, but it has a "ppp:" prefix followed by the command, and then a space and any parameters (if any). 6 | 7 | `` 8 | 9 | When a command is associated with any content, it will be between an opening and a closing command: 10 | 11 | `content` 12 | 13 | For wildcards and choices it uses the formats from the *Dynamic Prompts* extension, but sometimes with some additional options for extra functionality. 14 | 15 | ## Choices 16 | 17 | The generic format is: `{parameters$$opt1::choice1|opt2::choice2|opt3::choice3}` 18 | 19 | Both the construct parameters (up to the `$$`) and the individual choice options (up to the '::') are optional. 20 | 21 | There is also a format where instead of `parameters$$` you just put the sampler, for compatibility with *Dynamic Prompts*. 22 | 23 | The construct parameters can be written with the following options (all are optional): 24 | 25 | * "**~**" or "**@**": sampler (for compatibility with *Dynamic Prompts*), but only "**~**" (random) is supported. 26 | * "**r**": means it allows repetition of the choices. 27 | * "**o**": means it is "optional", and no error will be raised if there are no choices to select from. 28 | * "**n**" or "**n-m**" or "**n-**" or "**-m**": number or range of choices to select. Allows zero as the start of a range. Default is 1. 29 | * "**$$sep**": separator when multiple choices are selected. Default is set in settings. 30 | * "**$$**": end of the parameters (not optional if any parameters). 31 | 32 | Regarding the "optional" flag, consider this scenario: due to their conditions no choice is available. It will raise an error. If you add the `o` then it will just return an empty string. This is only necessary if all choices have conditions and they could all be false. It is not the same as setting a range starting at 0, because that would be an allowed number of returned choices. If you do this and no choices are available, no error is raised. 33 | 34 | The choice options are as follows: 35 | 36 | * "**%**": indicates that the content of the choice is a command 37 | * "**'identifiers'**": comma separated labels for the choice (optional, quotes can be single or double). Only makes sense inside a wildcard definition. Can be used when specifying the wildcard to select this specific choice. It's case insensitive. 38 | * "**n**": weight of the choice (optional, default 1). 39 | * "**if condition**": filters out the choice if the condition is false (optional; this is an extension to the *Dynamic Prompts* syntax). Same conditions as in the `if` command. 40 | * "**::**": end of choice options (not optional if any options) 41 | 42 | Whitespace is allowed between parameters/options. 43 | 44 | The only command available is `include wildcard`, which will include the choices of the specified wildcard in place of this choice. This allows composing choices from multiple wildcards. It also works in the choices of a wildcard, but note that in yaml you cannot start an array element with "%" and you will have to put the full choice in quotes, or use the object format. 45 | 46 | These are examples of formats you can use to insert a choice construct: 47 | 48 | | Construct | Result | 49 | | --------- | ------ | 50 | | `{choice1\|5::choice2\|3::choice3}` | select 1 choice, two of them have weights | 51 | | `{3$$choice1\|5 if _is_sd1::choice2\|choice3}` | select 3 choices, one has a weight and a condition | 52 | | `{2-3$$2::choice1\|choice2\|choice3}` | select 2 to 3 choices, one of them has a weight | 53 | | `{r2-3$$choice1\|choice2\|choice3}` | select 2 to 3 choices allowing repetition | 54 | | `{2-3$$ / $$choice1\|choice2\|choice3}` | select 2 to 3 choices with separator " / " | 55 | | `{o$$if _is_sd1::choice1\|if _is_sd2::choice2}`| select 1 choice, both have conditions, if none matches it is allowed because we indicate that it is optional | 56 | | `{choice1\|choice2\|%0.5::path/wildcard}` | select 1 choice from the two specified and the ones inside the path/wildcard wildcard, which will be weighted with half their weights | 57 | 58 | Notes: 59 | 60 | * The *Dynamic Prompts* format `{2$$__flavours__}` does not work as expected because the wildcard is considered only one possible choice (it will only output one value). You can write it instead as a wildcard with parameters `__2$$flavours__`. 61 | * Whitespace around the choices is not ignored like in *Dynamic Prompts*, but will be cleaned up if the appropriate cleaning settings are selected. 62 | 63 | ## Wildcards 64 | 65 | The generic format is: `__parameters$$wildcard'filter'(var=value)__` 66 | 67 | The parameters, the filter, and the setting of a variable are optional. The parameters follow the same format as for the choices. 68 | 69 | Wildcards cannot be used inside an extranetwork tag (because some lora names contain double underscores). If you need to choose from multiple loras put the whole extranetwork tag inside a wildcard, or use choices. 70 | 71 | ### Identifier 72 | 73 | * Allowed characters are letters, numbers, underscore (`_`), dash (`-`), dot (`.`), and the path separators (`/` and `\`). It cannot start with an underscore because it would be ambiguous whether it's part of the name or just precedes the wildcard. 74 | * Can have a relative path and contain globbing formatting, to read multiple wildcards and merge their choices. Note that if there are no parameters specified, the globbing will use the ones from the first wildcard that matches and have parameters (sorted by keys), so if you don't want that you might want to specify them. Also note that, unlike with *Dynamic Prompts*, the wildcard name has to be specified with its full path (unless you use globbing). 75 | * You can use variables, with the `${name}`, `${name:default}`, `` or `defaultecho>` formats, to build a dynamic identifier. 76 | 77 | ### Filter 78 | 79 | The filter can be used to filter specific choices from the wildcard. The filtering works before applying the choice conditions (if any). The surrounding quotes can be single or double. 80 | 81 | The filter is a comma separated list of an integer (positional choice index, zero-based) or choice label. You can also compound them with `+`. That is, the comma separated items act as an OR and the `+` inside them as an AND. Using labels can simplify the definitions of complex wildcards where you want to have direct access to specific choices on occasion (you don't need to create wildcards for each individual choice). There are some additional formats when using filters. You can specify `^wildcard` as a filter to use the filter of a previous wildcard in the chain. You can start the filter (regular or inherited) with `#` and it will not be applied to the current wildcard choices, but the filter will remain in memory to use by other descendant wildcards. You use `#` and `^` when you want to pass a filter to inner wildcards (see the test files). 82 | 83 | ### Variable 84 | 85 | The variable value only applies during the evaluation of the selected choices and is discarded afterward (the variable keeps its original value if there was one). 86 | 87 | ### Examples 88 | 89 | These are examples of formats you can use to insert a wildcard: 90 | 91 | | Construct | Result | 92 | | --------- | ------ | 93 | | `__wildcard__` | select 1 choice | 94 | | `__path/wildcard'0'__` | select the first choice | 95 | | `__path/wildcard'label'__` | select the choices with label "label" | 96 | | `__path/wildcard'0,label1,label2'__` | select the first choice and those with labels "label1" or "label2" | 97 | | `__path/wildcard'0,label1+label2'__` | select the first choice and those with both labels "label1" and "label2" | 98 | | `__3$$path/wildcard__` | select 3 choices | 99 | | `__2-3$$path/wildcard__` | select 2 to 3 choices | 100 | | `__r2-3$$path/wildcard__` | select 2 to 3 choices allowing repetition | 101 | | `__2-3$$ / $$path/wildcard__` | select 2 to 3 choices with separator " / " | 102 | | `__path/wildcard(var=value)__` | select 1 choice using the specified variable value in the evaluation. | 103 | 104 | ### Wildcard definitions 105 | 106 | A wildcard definition can be: 107 | 108 | * A txt file. The wildcard name will be the relative path of the file, without the extension. Each line will be a choice. Lines starting with `#` or empty are ignored. Doesn't support nesting. 109 | * An array or scalar value inside a json or yaml file. The wildcard name includes the relative folder path of the file, without the extension, but also the path of the value inside the file (if there is one). If the file contains a dictionary, the filename part is not used for the wildcard name. Supports nesting by having dictionaries inside dictionaries. 110 | 111 | The best format is a yaml file with a dictionary of wildcards inside. An editor supporting yaml syntax and linting is recommended (f.e. vscode). 112 | 113 | In a choice, the content after a `#` is ignored. 114 | 115 | If the first choice follows the format of wildcard parameters (*including the final `$$`*), it will be used as default parameters for that wildcard (see examples in the tests folder). The choices of the wildcard follow the same format as in the choices construct, or the object format of *Dynamic Prompts* (only in structured files). If using the object format for a choice you can use a new `if` property for the condition, and the `labels` property (an array of strings) and `command` property (a boolean) in addition to the standard `weight` and `text`/`content`. 116 | 117 | ```yaml 118 | { command: false, labels: ["some_label"], weight: 2, if: "_is_pony", content: "the text" } # "text" property can be used instead of "content" 119 | ``` 120 | 121 | Wildcard parameters in a json/yaml file can also be in object format, and support two additional properties, prefix and suffix: 122 | 123 | ```yaml 124 | { sampler: "~", repeating: false, optional: false, count: 2, prefix: "prefix-", suffix: "-suffix", separator: "/" } 125 | { sampler: "~", repeating: false, optional: false, from: 2, to: 3, prefix: "prefix-", suffix: "-suffix", separator: "/" } 126 | ``` 127 | 128 | The prefix and suffix are added to the result along with the selected choices and separators. They can contain other constructs, but the separator can't. 129 | 130 | It is recommended to use the object format for the wildcard parameters and for choices with complex options. 131 | 132 | Wildcards can contain just one choice. In json and yaml formats this allows the use of a string value for the keys, rather than an array. 133 | 134 | A choice inside a wildcard can also be a list or a dictionary of one element containing a list. These are considered anonymous wildcards. With a list it will be an anonymous wildcard with no choice options, and with a dictionary the key will be the options for the choice containing the anonymous wildcard and the value the choices of the anonymous wildcard. Anonymous wildcards can help formatting complex choice values that are used in only one place and thus creating a regular wildcard is not necessary. See test.yaml for examples. 135 | 136 | Remember you can use the include command on choices to compose a wildcard from other wildcards' choices. 137 | 138 | Note: the files should have UTF-8 encoding. The extension will also try with windows-1252 if that fails. 139 | 140 | Wildcard definitions are reloaded automatically on each generation if they change. 141 | 142 | ### Detection of remaining wildcards 143 | 144 | This extension should run after any other wildcard extensions, so if you don't use the internal wildcards processing, any remaining wildcards present in the prompt or negative_prompt at this point must be invalid. Usually you might not notice this problem until you check the image metadata, so this option gives you some ways to detect and treat the problem. 145 | 146 | ## Set command 147 | 148 | This command sets the value of a variable that can be checked later. 149 | 150 | The format is: `value` 151 | 152 | These are the available optional modifiers: 153 | 154 | * `evaluate`: the value of the variable is evaluated at this moment, instead of when it is used. 155 | * `add`: the value is added to the current value of the variable. It does not force an immediate evaluation of the old nor the added value. 156 | * `ifundefined`: the value will only be set if the variable is undefined. 157 | 158 | The `add` and `ifundefined` modifiers are mutually exclusive and cannot be used together. 159 | 160 | The *Dynamic Prompts* format also works: 161 | 162 | | Construct | Meaning | 163 | | --------- | ------- | 164 | | `${var=value}` | regular evaluation | 165 | | `${var=!value}` | immediate evaluation | 166 | 167 | If also supports the addition and undefined check as an extension of the *Dynamic Prompts* format: 168 | 169 | | Construct | Meaning | 170 | | --------- | ------- | 171 | | `${var+=value}` | equivalent to "add" | 172 | | `${var+=!value}` | equivalent to "evaluate add" | 173 | | `${var?=value}` | equivalent to "ifundefined" | 174 | | `${var?=!value}` | equivalent to "evaluate ifundefined" | 175 | 176 | ## Echo command 177 | 178 | This command prints the value of a variable, or the specified default if it doesn't exist. 179 | 180 | The format is: 181 | 182 | | Construct | 183 | | --------- | 184 | | `` | 185 | | `default` | 186 | 187 | The *Dynamic Prompts* format is: 188 | 189 | | Construct | 190 | | --------- | 191 | | `${varname}` | 192 | | `${varname:default}` | 193 | 194 | ## If command 195 | 196 | This command allows you to filter content based on conditions. 197 | 198 | The full format is: 199 | 200 | `content onecontent twoother content` 201 | 202 | Any `elif`s (there can be multiple) and the `else` are optional. 203 | 204 | The `conditionN` can be: 205 | 206 | | Construct | Meaning | 207 | | --------- | ------- | 208 | | `variable` | check truthyness of the variable | 209 | | `variable [not] operation value` | check the variable against a value | 210 | | `variable [not] operation (value1,value2,...)` | check the variable against a list of values | 211 | 212 | For a simple value the allowed operations are `eq`, `ne`, `gt`, `lt`, `ge`, `le`, `contains` and the value can be a quoted string or an integer. For a list of values the allowed operations are `contains`, `in` and the value of the variable is checked against all the elements of the list until one matches. The operation can be preceded by `not` for readability, instead of using it in the front. 213 | 214 | You can also build complex conditions joining them with boolean operators and/or/not and parentheses. 215 | 216 | The variable can be one set with the `set` or `add` commands (user variables) or you can use system variables like these (names starting with an underscore are reserved for system variables): 217 | 218 | | System variable | Value | 219 | | --------------- | ----- | 220 | | `_model` | the loaded model identifier (`"sd1"`, `"sd2"`, `"sdxl"`, `"sd3"`, `"flux"`, `"auraflow"`). `_sd` also works but is deprecated. | 221 | | `_modelname` | the loaded model filename (without path). `_sdname` also works but is deprecated. | 222 | | `_modelfullname` | the loaded model filename (with path). `_sdfullname` also works but is deprecated. | 223 | | `_modelclass` | the class used for the model. Note that this is dependent on the webui. In A1111 all SD versions use the same class. Can be used for new models that are not supported yet with the `_is_*` variables. The debug setting will show all system variables when generating in case you need to see which one to use for a certain model. | 224 | | `_is_sd` | true if the loaded model version is any version of SD | 225 | | `_is_sd1` | true if the loaded model version is SD 1.x | 226 | | `_is_sd2` | true if the loaded model version is SD 2.x | 227 | | `_is_sdxl` | true if the loaded model version is SDXL (includes Pony models) | 228 | | `_is_sd3` | true if the loaded model version is SD 3.x | 229 | | `_is_flux` | true if the loaded model is Flux | 230 | | `_is_auraflow` | true if the loaded model is AuraFlow | 231 | | `_is_ssd` | true if the loaded model version is SSD (Segmind Stable Diffusion 1B). Note that for an SSD model `_is_sdxl` will also be true. | 232 | | `_is_sdxl_no_ssd` | true if the loaded model version is SDXL and not an SSD model. | 233 | | `_is_sdxl_no_pony` | true if the loaded model version is SDXL and not a Pony model (the "pony" variant must be defined in settings). Kept to maintain compatibility with previous versions. | 234 | | `_is_vvvv` | true if the loaded model matches the *vvvv* model variant definition (based on its filename). Note that the corresponding variable for the model kind will also be true. | 235 | | `_is_pure_kkkk` | true if the loaded model is of kind *kkkk* (f.e. sdxl) and not a variant. | 236 | | `_is_variant_kkkk` | true if the loaded model version is any variant of model kind *kkkk* and not the pure version. Note that the corresponding variable for the model kind will also be true.| 237 | 238 | ### Example 239 | 240 | (multiline to be easier to read) 241 | 242 | ```text 243 | test sd1x 244 | test pony 245 | test sdxl 246 | unknown model 247 | 248 | ``` 249 | 250 | Only one of the options will end up in the prompt, depending on the loaded model. 251 | 252 | ## ExtraNetwork command 253 | 254 | This command is a shortcut to add an extranetwork (usually a lora), and its triggers, with conditions. More legible and sometimes shorter than adding regular extranetworks inside if commands. 255 | 256 | The full format is: 257 | 258 | `[triggers]` 259 | `` 260 | 261 | The `type` is the kind of extranetwork, like `lora` or `hypernet`. 262 | 263 | The `name` is the extranetwork identifier. If it is not a regular identifier (i.e. starts with a number or contains spaces or symbols) it should be inside quotes. 264 | 265 | The `parameters` is optional and its format depends on the extranetwork type. With loras or hypernets it is usually a single weight number, so if the type is one of those and there are no parameters it will default to `1`. If it is not a number it should go inside quotes. 266 | 267 | The `condition` uses the same format as in the `if` command, and it is also optional. 268 | 269 | The `triggers` are also optional, and can be any content. If there are no triggers the command ending can be omitted. 270 | 271 | If the condition passes (or if there is no condition) the extranetwork tag will be built and added to the result along with any triggers. 272 | 273 | ### Examples 274 | 275 | (multiline to be easier to read) 276 | 277 | ```text 278 | test sd1x 279 | test pony 280 | 281 | test sdxl 282 | ``` 283 | 284 | Will turn into one of these (or none) depending on the model: 285 | 286 | * `test sd1x` 287 | * `test pony` 288 | * `` 289 | * `test sdxl` 290 | 291 | ### Extranetworks mappings 292 | 293 | The extranetwork command supports specifying mappings of extranetworks (like LoRAs), so, for example, a different one can be used depending on the loaded model. 294 | 295 | If the type of extranetwork is prefixed with a `$` the command will look for a mapping. 296 | 297 | The mappings are configured in yaml files in any of the configured extranetwork mappings folders. The format is like this: 298 | 299 | ```yaml 300 | extnettype: 301 | mappingname: 302 | - condition: "" 303 | name: "" 304 | parameters: "" 305 | triggers: [] 306 | weight: 1.0 307 | ... 308 | ``` 309 | 310 | Used like this: 311 | 312 | ```text 313 | 314 | inline triggers 315 | ``` 316 | 317 | Each mapping can have any number of elements in its list of mappings. There are no mandatory properties for a mapping. The properties mean the following: 318 | 319 | * `extnettype`: the kind of extranetwork, for example `lora`. 320 | * `mappingname`: the name you want to give to the mapping, to be referenced in the command. 321 | * `condition`: the condition to check for this mapping to be used (usually it should be one of the `_is_*` variables). If the conditions of multiple mappings evaluate to True, one will be chosen randomly. If the condition is missing it is considered True, to be used in the last mapping to catch as an "else" condition, and will be used if no other mapping applies. 322 | * `name`: name of the real extranetwork. If it is missing no extranetwork tag will be added. 323 | * `parameters`: parameters for the real extranetwork. If it is missing it is assumed "1" for loras and hypernets. If both this parameter and the parameter in the ext command are numbers they are multiplied for the result. In other case the parameter of the ext command, if it exists, is used. 324 | * `triggers`: list of trigger strings. If it is missing, only the inline triggers in the ext command will be added. 325 | * `weight`: weight for this variant, in case multiple of them apply, to choose one. Default is 1. 326 | 327 | See the file in the tests folder as an example. 328 | 329 | ## Sending content to the negative prompt 330 | 331 | The new format for this command is like this: 332 | 333 | | Construct | Meaning | 334 | | --------- | ------- | 335 | | `content` | send to negative prompt | 336 | | `` | insertion point to be used in the negative prompt as destination for the pN position | 337 | 338 | Where position is optional (defaults to the start) and can be: 339 | 340 | * **s**: at the start of the negative prompt 341 | * **e**: at the end of the negative prompt 342 | * **pN**: at the position of the insertion point in the negative prompt with N being 0-9. If the insertion point is not found it inserts at the start. 343 | 344 | ### Example 345 | 346 | You have a wildcard for hair colors (`__haircolors__`) with one being strawberry blonde, but you don't want strawberries. So in that option you add a command to add to the negative prompt, like so: 347 | 348 | ```text 349 | blonde 350 | strawberry blonde strawberry 351 | brunette 352 | ``` 353 | 354 | Then, if that option is chosen this extension will process it later and move that part to the negative prompt. 355 | 356 | ### Old format 357 | 358 | The old format (``) is not supported anymore. 359 | 360 | ### Notes 361 | 362 | Positional insertion commands have less priority that start/end commands, so even if they are at the start or end of the negative prompt, they will end up inside any start/end (and default position) commands. 363 | 364 | The content of the negative commands is not processed and is copied as-is to the negative prompt. Other modifiers around the commands are processed in the following way. 365 | 366 | ### Attention modifiers (weights) 367 | 368 | They will be translated to the negative prompt. For example: 369 | 370 | * `(redsquare:1.5)` will end up as `(square:1.5)` in the negative prompt 371 | * `(red[square]:1.5)` will end up as `(square:1.35)` in the negative prompt (weight=1.5*0.9) if the merge attention option is enabled or `([square]:1.5)` otherwise. 372 | * However `(red[square]:1.5)` will end up as `([square]:1.5)` in the negative prompt. The content of the negative tag is copied as is, and is not merged with the surrounding modifier because the insertions happen after the attention merging. 373 | 374 | ### Prompt editing constructs (alternation and scheduling) 375 | 376 | Negative commands inside such constructs will copy the construct to the negative prompt, but separating its elements. For example: 377 | 378 | * **Alternation**: `[redsquare|bluecircle]` will end up as `[square|], [|circle]` in the negative prompt, instead of `[square|circle]` 379 | * **Scheduling**: `[redsquare:bluecircle:0.5]` will end up as `[square::0.5], [:circle:0.5]` instead of `[square:circle:0.5]` 380 | 381 | This should still work as intended, and the only negative point i see is the unnecessary separators. 382 | -------------------------------------------------------------------------------- /ppp_comfyui.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # pylint: disable=import-error 4 | import folder_paths # type: ignore 5 | import nodes # type: ignore 6 | 7 | from .ppp import PromptPostProcessor 8 | from .ppp_hosts import SUPPORTED_APPS 9 | from .ppp_logging import DEBUG_LEVEL, PromptPostProcessorLogFactory 10 | from .ppp_wildcards import PPPWildcards 11 | from .ppp_enmappings import PPPExtraNetworkMappings 12 | 13 | if __name__ == "__main__": 14 | raise SystemExit("This script must be run from ComfyUI") 15 | 16 | 17 | class PromptPostProcessorComfyUINode: 18 | """ 19 | Node for processing prompts. 20 | """ 21 | 22 | logger = None 23 | 24 | def __init__(self): 25 | lf = PromptPostProcessorLogFactory(SUPPORTED_APPS.comfyui) 26 | self.logger = lf.log 27 | grammar_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "grammar.lark") 28 | with open(grammar_filename, "r", encoding="utf-8") as file: 29 | self.grammar_content = file.read() 30 | self.wildcards_obj = PPPWildcards(lf.log) 31 | self.extranetwork_mappings_obj = PPPExtraNetworkMappings(lf.log) 32 | self.logger.info(f"{PromptPostProcessor.NAME} {PromptPostProcessor.VERSION} initialized") 33 | 34 | class SmartType(str): 35 | def __ne__(self, other): 36 | if self == "*" or other == "*": 37 | return False 38 | selfset = set(self.split(",")) 39 | otherset = set(other.split(",")) 40 | return not otherset.issubset(selfset) 41 | 42 | @classmethod 43 | def INPUT_TYPES(cls): 44 | return { 45 | "required": { 46 | "pos_prompt": ( 47 | "STRING", 48 | { 49 | "multiline": True, 50 | "default": "", 51 | "dynamicPrompts": False, 52 | }, 53 | ), 54 | "neg_prompt": ( 55 | "STRING", 56 | { 57 | "multiline": True, 58 | "default": "", 59 | "dynamicPrompts": False, 60 | }, 61 | ), 62 | }, 63 | "optional": { 64 | "model": ( 65 | cls.SmartType("MODEL,STRING"), 66 | { 67 | "default": "", 68 | "placeholder": "internal model class name", 69 | "forceInput": True, 70 | }, 71 | ), 72 | "modelname": ( 73 | "STRING", 74 | { 75 | "default": "", 76 | "placeholder": "full path of the model", 77 | "dynamicPrompts": False, 78 | }, 79 | ), 80 | "seed": ( 81 | "INT", 82 | { 83 | "default": -1, 84 | }, 85 | ), 86 | "debug_level": ( 87 | [e.value for e in DEBUG_LEVEL], 88 | { 89 | "default": DEBUG_LEVEL.minimal.value, 90 | "tooltip": "Debug level", 91 | }, 92 | ), 93 | "on_warnings": ( 94 | [e.value for e in PromptPostProcessor.ONWARNING_CHOICES], 95 | { 96 | "default": PromptPostProcessor.ONWARNING_CHOICES.warn.value, 97 | "tooltip": "How to handle invalid content warnings", 98 | }, 99 | ), 100 | "variants_definitions": ( 101 | "STRING", 102 | { 103 | "default": PromptPostProcessor.DEFAULT_VARIANTS_DEFINITIONS, 104 | "multiline": True, 105 | "placeholder": "", 106 | "tooltip": "Definitions for variant models to be recognized based on strings found in the full filename. Format for each line is: 'name(kind)=comma separated list of substrings (case insensitive)' with kind being one of the base model types or not specified", 107 | "dynamicPrompts": False, 108 | }, 109 | ), 110 | "wc_process_wildcards": ( 111 | "BOOLEAN", 112 | { 113 | "default": True, 114 | "tooltip": "Process wildcards in the prompt", 115 | "label_on": "Yes", 116 | "label_off": "No", 117 | }, 118 | ), 119 | "wc_wildcards_folders": ( 120 | "STRING", 121 | { 122 | "default": "", 123 | "tooltip": "Comma separated list of wildcards folders", 124 | "dynamicPrompts": False, 125 | }, 126 | ), 127 | "wc_wildcards_input": ( 128 | "STRING", 129 | { 130 | "default": "", 131 | "multiline": True, 132 | "placeholder": "wildcards definitions", 133 | "tooltip": "Wildcards definitions in yaml/json format", 134 | "dynamicPrompts": False, 135 | }, 136 | ), 137 | "wc_if_wildcards": ( 138 | [e.value for e in PromptPostProcessor.IFWILDCARDS_CHOICES], 139 | { 140 | "default": PromptPostProcessor.IFWILDCARDS_CHOICES.stop.value, 141 | "tooltip": "How to handle invalid wildcards in the prompt", 142 | }, 143 | ), 144 | "wc_choice_separator": ( 145 | "STRING", 146 | { 147 | "default": PromptPostProcessor.DEFAULT_CHOICE_SEPARATOR, 148 | "tooltip": "Default separator for selected choices", 149 | "dynamicPrompts": False, 150 | }, 151 | ), 152 | "wc_keep_choices_order": ( 153 | "BOOLEAN", 154 | { 155 | "default": True, 156 | "tooltip": "Keep the order of the choices in the prompt", 157 | "label_on": "Yes", 158 | "label_off": "No", 159 | }, 160 | ), 161 | "stn_separator": ( 162 | "STRING", 163 | { 164 | "default": PromptPostProcessor.DEFAULT_STN_SEPARATOR, 165 | "tooltip": "Separator for the content added to the negative prompt", 166 | "dynamicPrompts": False, 167 | }, 168 | ), 169 | "stn_ignore_repeats": ( 170 | "BOOLEAN", 171 | { 172 | "default": True, 173 | "tooltip": "Ignore repeated content added to the negative prompt", 174 | "label_on": "Yes", 175 | "label_off": "No", 176 | }, 177 | ), 178 | "cleanup_extra_spaces": ( 179 | "BOOLEAN", 180 | { 181 | "default": True, 182 | "tooltip": "Remove extra spaces", 183 | "label_on": "Yes", 184 | "label_off": "No", 185 | }, 186 | ), 187 | "cleanup_empty_constructs": ( 188 | "BOOLEAN", 189 | { 190 | "default": True, 191 | "tooltip": "Remove empty constructs", 192 | "label_on": "Yes", 193 | "label_off": "No", 194 | }, 195 | ), 196 | "cleanup_extra_separators": ( 197 | "BOOLEAN", 198 | { 199 | "default": True, 200 | "tooltip": "Remove extra separators", 201 | "label_on": "Yes", 202 | "label_off": "No", 203 | }, 204 | ), 205 | "cleanup_extra_separators2": ( 206 | "BOOLEAN", 207 | { 208 | "default": True, 209 | "tooltip": "Remove extra separators (additional cases)", 210 | "label_on": "Yes", 211 | "label_off": "No", 212 | }, 213 | ), 214 | "cleanup_extra_separators_include_eol": ( 215 | "BOOLEAN", 216 | { 217 | "default": False, 218 | "tooltip": "Extra separators options also remove EOLs", 219 | "label_on": "Yes", 220 | "label_off": "No", 221 | }, 222 | ), 223 | "cleanup_breaks": ( 224 | "BOOLEAN", 225 | { 226 | "default": False, 227 | "tooltip": "Cleanup around BREAKs", 228 | "label_on": "Yes", 229 | "label_off": "No", 230 | }, 231 | ), 232 | "cleanup_breaks_eol": ( 233 | "BOOLEAN", 234 | { 235 | "default": False, 236 | "tooltip": "Set BREAKs in their own line", 237 | "label_on": "Yes", 238 | "label_off": "No", 239 | }, 240 | ), 241 | "cleanup_ands": ( 242 | "BOOLEAN", 243 | { 244 | "default": False, 245 | "tooltip": "Cleanup around ANDs", 246 | "label_on": "Yes", 247 | "label_off": "No", 248 | }, 249 | ), 250 | "cleanup_ands_eol": ( 251 | "BOOLEAN", 252 | { 253 | "default": False, 254 | "tooltip": "Set ANDs in their own line", 255 | "label_on": "Yes", 256 | "label_off": "No", 257 | }, 258 | ), 259 | "cleanup_extranetwork_tags": ( 260 | "BOOLEAN", 261 | { 262 | "default": False, 263 | "tooltip": "Clean up around extra network tags", 264 | "label_on": "Yes", 265 | "label_off": "No", 266 | }, 267 | ), 268 | "cleanup_merge_attention": ( 269 | "BOOLEAN", 270 | { 271 | "default": True, 272 | "tooltip": "Merge nested attention constructs", 273 | "label_on": "Yes", 274 | "label_off": "No", 275 | }, 276 | ), 277 | "remove_extranetwork_tags": ( 278 | "BOOLEAN", 279 | { 280 | "default": False, 281 | "tooltip": "Remove extra network tags", 282 | "label_on": "Yes", 283 | "label_off": "No", 284 | }, 285 | ), 286 | "en_mappings_folders": ( 287 | "STRING", 288 | { 289 | "default": "", 290 | "tooltip": "Comma separated list of extranetwork mappings folders", 291 | "dynamicPrompts": False, 292 | }, 293 | ), 294 | "en_mappings_input": ( 295 | "STRING", 296 | { 297 | "default": "", 298 | "multiline": True, 299 | "placeholder": "extranetwork mappings definitions", 300 | "tooltip": "Extranetwork mappings definitions in yaml format", 301 | "dynamicPrompts": False, 302 | }, 303 | ), 304 | }, 305 | } 306 | 307 | @classmethod 308 | def VALIDATE_INPUTS(cls, input_types: dict[str, str]): 309 | it = cls.INPUT_TYPES() 310 | expected = { 311 | k: cls.SmartType("COMBO,STRING") if isinstance(v[0], list) else v[0] # we allow string for combos 312 | for k, v in {**it["required"], **it["optional"]}.items() 313 | } 314 | for input_name, input_type in input_types.items(): 315 | t = expected[input_name] 316 | if input_type != t: 317 | return f"Invalid type for input '{input_name}': {input_type} (expected {t})" 318 | return True 319 | 320 | RETURN_TYPES = ( 321 | "STRING", 322 | "STRING", 323 | "PPP_DICT", 324 | ) 325 | RETURN_NAMES = ( 326 | "pos_prompt", 327 | "neg_prompt", 328 | "variables", 329 | ) 330 | 331 | FUNCTION = "process" 332 | 333 | CATEGORY = "ACB" 334 | 335 | @classmethod 336 | def IS_CHANGED( 337 | cls, 338 | model, 339 | modelname, 340 | pos_prompt, 341 | neg_prompt, 342 | seed, 343 | debug_level, # pylint: disable=unused-argument 344 | on_warnings, 345 | variants_definitions, 346 | wc_process_wildcards, 347 | wc_wildcards_folders, 348 | wc_wildcards_input, 349 | wc_if_wildcards, 350 | wc_choice_separator, 351 | wc_keep_choices_order, 352 | stn_separator, 353 | stn_ignore_repeats, 354 | cleanup_extra_spaces, 355 | cleanup_empty_constructs, 356 | cleanup_extra_separators, 357 | cleanup_extra_separators2, 358 | cleanup_extra_separators_include_eol, 359 | cleanup_breaks, 360 | cleanup_breaks_eol, 361 | cleanup_ands, 362 | cleanup_ands_eol, 363 | cleanup_extranetwork_tags, 364 | cleanup_merge_attention, 365 | remove_extranetwork_tags, 366 | en_mappings_folders, 367 | en_mappings_input, 368 | ): 369 | if wc_process_wildcards: 370 | return float( 371 | "NaN" 372 | ) # since we can't detect changes in wildcards we assume they are always changed when enabled 373 | new_run = { # everything except debug_level 374 | "model": model, 375 | "modelname": modelname, 376 | "pos_prompt": pos_prompt, 377 | "neg_prompt": neg_prompt, 378 | "seed": seed, 379 | "on_warnings": on_warnings, 380 | "variants_definitions": variants_definitions, 381 | "process_wildcards": wc_process_wildcards, 382 | "wildcards_folders": wc_wildcards_folders, 383 | "wildcards_input": wc_wildcards_input, 384 | "if_wildcards": wc_if_wildcards, 385 | "choice_separator": wc_choice_separator, 386 | "keep_choices_order": wc_keep_choices_order, 387 | "stn_separator": stn_separator, 388 | "stn_ignore_repeats": stn_ignore_repeats, 389 | "cleanup_extra_spaces": cleanup_extra_spaces, 390 | "cleanup_empty_constructs": cleanup_empty_constructs, 391 | "cleanup_extra_separators": cleanup_extra_separators, 392 | "cleanup_extra_separators2": cleanup_extra_separators2, 393 | "cleanup_extra_separators_include_eol": cleanup_extra_separators_include_eol, 394 | "cleanup_breaks": cleanup_breaks, 395 | "cleanup_breaks_eol": cleanup_breaks_eol, 396 | "cleanup_ands": cleanup_ands, 397 | "cleanup_ands_eol": cleanup_ands_eol, 398 | "cleanup_extranetwork_tags": cleanup_extranetwork_tags, 399 | "cleanup_merge_attention": cleanup_merge_attention, 400 | "remove_extranetwork_tags": remove_extranetwork_tags, 401 | "en_mappings_folders": en_mappings_folders, 402 | "en_mappings_input": en_mappings_input, 403 | } 404 | return new_run.__hash__ 405 | # return float("NaN") 406 | 407 | def process( 408 | self, 409 | model, 410 | modelname, 411 | pos_prompt, 412 | neg_prompt, 413 | seed, 414 | debug_level, 415 | on_warnings, 416 | variants_definitions, 417 | wc_process_wildcards, 418 | wc_wildcards_folders, 419 | wc_wildcards_input, 420 | wc_if_wildcards, 421 | wc_choice_separator, 422 | wc_keep_choices_order, 423 | stn_separator, 424 | stn_ignore_repeats, 425 | cleanup_extra_spaces, 426 | cleanup_empty_constructs, 427 | cleanup_extra_separators, 428 | cleanup_extra_separators2, 429 | cleanup_extra_separators_include_eol, 430 | cleanup_breaks, 431 | cleanup_breaks_eol, 432 | cleanup_ands, 433 | cleanup_ands_eol, 434 | cleanup_extranetwork_tags, 435 | cleanup_merge_attention, 436 | remove_extranetwork_tags, 437 | en_mappings_folders, 438 | en_mappings_input, 439 | ): 440 | modelclass = ( 441 | model.model.model_config.__class__.__name__ if model is not None and not isinstance(model, str) else model 442 | ) or "" 443 | if modelclass == "": 444 | self.logger.warning("Model class is not provided. System variables might not be properly set.") 445 | if modelname == "": 446 | self.logger.warning("Modelname is not provided. System variables will not be properly set.") 447 | # model class values in ComfyUI\comfy\supported_models.py 448 | env_info = { 449 | "app": SUPPORTED_APPS.comfyui.value, 450 | "models_path": folder_paths.models_dir, 451 | "model_filename": modelname or "", # path is relative to checkpoints folder 452 | "model_class": modelclass, 453 | "is_sd1": modelclass in ("SD15", "SD15_instructpix2pix"), 454 | "is_sd2": modelclass in ("SD20", "SD21UnclipL", "SD21UnclipH", "LotusD"), 455 | "is_sdxl": ( 456 | modelclass in ("SDXL", "SDXLRefiner", "SDXL_instructpix2pix", "Segmind_Vega", "KOALA_700M", "KOALA_1B") 457 | ), 458 | "is_ssd": modelclass in ("SSD1B",), 459 | "is_sd3": modelclass in ("SD3",), 460 | "is_flux": modelclass in ("Flux", "FluxInpaint", "FluxSchnell"), 461 | "is_auraflow": modelclass in ("AuraFlow",), 462 | "is_pixart": modelclass in ("PixArtAlpha", "PixArtSigma"), 463 | "is_lumina2": modelclass in ("Lumina2",), 464 | "is_ltxv": modelclass in ("LTXV",), 465 | "is_cosmos": modelclass in ("CosmosT2V", "CosmosI2V"), 466 | "is_genmomochi": modelclass in ("GenmoMochi",), 467 | "is_hunyuan": modelclass in ("HunyuanDiT", "HunyuanDiT1"), 468 | "is_hunyuanvideo": modelclass in ("HunyuanVideo", "HunyuanVideoI2V", "HunyuanVideoSkyreelsI2V"), 469 | "is_hunyuan3d": modelclass in ("Hunyuan3Dv2", "Hunyuan3Dv2mini"), 470 | "is_wanvideo": modelclass in ("WAN21_T2V", "WAN21_I2V", "WAN21_FunControl2V"), 471 | "is_hidream": modelclass in ("HiDream",), 472 | } 473 | # Also supported: SVD_img2vid, SVD3D_u, SVD3_p, Stable_Zero123, SD_X4Upscaler, Stable_Cascade_C, Stable_Cascade_B, StableAudio 474 | 475 | if wc_wildcards_folders == "": 476 | try: 477 | fp1 = folder_paths.get_folder_paths("ppp_wildcards") 478 | except Exception: # pylint: disable=W0718 479 | fp1 = None 480 | try: 481 | fp2 = folder_paths.get_folder_paths("wildcards") 482 | except Exception: # pylint: disable=W0718 483 | fp2 = None 484 | wc_wildcards_folders = ",".join(fp1 or fp2 or []) 485 | if wc_wildcards_folders == "": 486 | wc_wildcards_folders = os.getenv("WILDCARD_DIR", PPPWildcards.DEFAULT_WILDCARDS_FOLDER) 487 | wildcards_folders = [ 488 | (f if os.path.isabs(f) else os.path.abspath(os.path.join(folder_paths.models_dir, f))) 489 | for f in wc_wildcards_folders.split(",") 490 | if f.strip() != "" 491 | ] 492 | if en_mappings_folders == "": 493 | try: 494 | fp3 = folder_paths.get_folder_paths("ppp_extranetworkmappings") 495 | except Exception: # pylint: disable=W0718 496 | fp3 = None 497 | en_mappings_folders = ",".join(fp3 or []) 498 | if en_mappings_folders == "": 499 | en_mappings_folders = os.getenv( 500 | "EXTRANETWORKMAPPINGS_DIR", PPPExtraNetworkMappings.DEFAULT_ENMAPPINGS_FOLDER 501 | ) 502 | enmappings_folders = [ 503 | (f if os.path.isabs(f) else os.path.abspath(os.path.join(folder_paths.models_dir, f))) 504 | for f in en_mappings_folders.split(",") 505 | if f.strip() != "" 506 | ] 507 | 508 | if variants_definitions != "" and not "=" in variants_definitions: # mainly to warn about the old format 509 | raise ValueError("Invalid variants_definitions format") 510 | options = { 511 | "debug_level": debug_level, 512 | "on_warnings": on_warnings, 513 | "variants_definitions": variants_definitions, 514 | "process_wildcards": wc_process_wildcards, 515 | "if_wildcards": wc_if_wildcards, 516 | "choice_separator": wc_choice_separator, 517 | "keep_choices_order": wc_keep_choices_order, 518 | "stn_separator": stn_separator, 519 | "stn_ignore_repeats": stn_ignore_repeats, 520 | "cleanup_extra_spaces": cleanup_extra_spaces, 521 | "cleanup_empty_constructs": cleanup_empty_constructs, 522 | "cleanup_extra_separators": cleanup_extra_separators, 523 | "cleanup_extra_separators2": cleanup_extra_separators2, 524 | "cleanup_extra_separators_include_eol": cleanup_extra_separators_include_eol, 525 | "cleanup_breaks": cleanup_breaks, 526 | "cleanup_breaks_eol": cleanup_breaks_eol, 527 | "cleanup_ands": cleanup_ands, 528 | "cleanup_ands_eol": cleanup_ands_eol, 529 | "cleanup_extranetwork_tags": cleanup_extranetwork_tags, 530 | "cleanup_merge_attention": cleanup_merge_attention, 531 | "remove_extranetwork_tags": remove_extranetwork_tags, 532 | } 533 | self.wildcards_obj.refresh_wildcards( 534 | debug_level, 535 | wildcards_folders if options["process_wildcards"] else None, 536 | wc_wildcards_input, 537 | ) 538 | self.extranetwork_mappings_obj.refresh_extranetwork_mappings( 539 | debug_level, 540 | enmappings_folders, 541 | en_mappings_input, 542 | ) 543 | ppp = PromptPostProcessor( 544 | self.logger, 545 | self.interrupt, 546 | env_info, 547 | options, 548 | self.grammar_content, 549 | self.wildcards_obj, 550 | self.extranetwork_mappings_obj, 551 | ) 552 | pos_prompt, neg_prompt, variables = ppp.process_prompt(pos_prompt, neg_prompt, seed if seed is not None else 1) 553 | return ( 554 | pos_prompt, 555 | neg_prompt, 556 | variables, 557 | ) 558 | 559 | def interrupt(self): 560 | nodes.interrupt_processing(True) 561 | 562 | 563 | class PromptPostProcessorSelectVariableComfyUINode: 564 | """ 565 | Node for selecting a variable from a dictionary. 566 | """ 567 | 568 | def __init__(self): 569 | pass 570 | 571 | @classmethod 572 | def INPUT_TYPES(cls): 573 | return { 574 | "required": { 575 | "variables": ( 576 | "PPP_DICT", 577 | { 578 | "forceInput": True, 579 | }, 580 | ), 581 | }, 582 | "optional": { 583 | "name": ( 584 | "STRING", 585 | { 586 | "placeholder": "variable name", 587 | "multiline": False, 588 | "default": "", 589 | "dynamicPrompts": False, 590 | }, 591 | ), 592 | }, 593 | } 594 | 595 | RETURN_TYPES = ("STRING",) 596 | RETURN_NAMES = ("value",) 597 | 598 | FUNCTION = "select" 599 | 600 | CATEGORY = "ACB" 601 | 602 | def select( 603 | self, 604 | variables: dict[str, str], 605 | name: str, 606 | ): 607 | value = "" 608 | if variables: 609 | if name == "": 610 | value = "\n".join(f"{k}: {v}" for k, v in variables.items()) 611 | elif name in variables: 612 | value = variables[name] 613 | return (value,) 614 | -------------------------------------------------------------------------------- /scripts/ppp_script.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main__": 2 | raise SystemExit("This script must be run from a Stable Diffusion WebUI") 3 | 4 | import sys 5 | import os 6 | import time 7 | from pathlib import Path 8 | import numpy as np 9 | 10 | sys.path.append(str(Path(__file__).parent)) # base path for the extension 11 | 12 | from modules import scripts, shared, script_callbacks # pylint: disable=import-error 13 | from modules.processing import StableDiffusionProcessing # pylint: disable=import-error 14 | from modules.shared import opts # pylint: disable=import-error 15 | from modules.paths import models_path # pylint: disable=import-error 16 | import gradio as gr # pylint: disable=import-error 17 | from ppp import PromptPostProcessor # pylint: disable=import-error 18 | from ppp_hosts import SUPPORTED_APPS, SUPPORTED_APPS_NAMES # pylint: disable=import-error 19 | from ppp_logging import DEBUG_LEVEL, PromptPostProcessorLogFactory # pylint: disable=import-error 20 | from ppp_cache import PPPLRUCache # pylint: disable=import-error 21 | from ppp_wildcards import PPPWildcards # pylint: disable=import-error 22 | from ppp_enmappings import PPPExtraNetworkMappings # pylint: disable=import-error 23 | 24 | 25 | class PromptPostProcessorA1111Script(scripts.Script): 26 | """ 27 | This class represents a script for prompt post-processing. 28 | It is responsible for processing prompts and applying various settings and cleanup operations. 29 | 30 | Attributes: 31 | callbacks_added (bool): Flag indicating whether the script callbacks have been added. 32 | 33 | Methods: 34 | __init__(): Initializes the PromptPostProcessorScript object. 35 | title(): Returns the title of the script. 36 | show(is_img2img): Determines whether the script should be shown based on the input type. 37 | process(p, *args, **kwargs): Processes the prompts and applies post-processing operations. 38 | ppp_interrupt(): Interrupts the generation. 39 | __on_ui_settings(): Callback function for UI settings. 40 | """ 41 | 42 | instance_count = 0 43 | 44 | @classmethod 45 | def increment_instance_count(cls): 46 | cls.instance_count += 1 47 | return cls.instance_count 48 | 49 | @classmethod 50 | def get_instance_count(cls): 51 | return cls.instance_count 52 | 53 | def __init__(self): 54 | """ 55 | Initializes the PromptPostProcessor object. 56 | 57 | Parameters: 58 | None 59 | 60 | Returns: 61 | None 62 | """ 63 | self.instance_index = self.increment_instance_count() 64 | self.name = PromptPostProcessor.NAME 65 | grammar_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../grammar.lark") 66 | with open(grammar_filename, "r", encoding="utf-8") as file: 67 | self.grammar_content = file.read() 68 | self.ppp_logger = None 69 | self.ppp_debug_level = DEBUG_LEVEL.none.value 70 | self.lru_cache = None 71 | self.wildcards_obj = None 72 | self.extranetwork_mappings_obj = None 73 | 74 | def title(self): 75 | """ 76 | Returns the title of the script. 77 | 78 | Returns: 79 | str: The title of the script. 80 | """ 81 | return PromptPostProcessor.NAME 82 | 83 | def show(self, is_img2img): # pylint: disable=unused-argument 84 | """ 85 | Determines whether the script should be shown based on the kind of processing. 86 | 87 | Args: 88 | is_img2img (bool): Flag indicating whether the processing is image-to-image. 89 | 90 | Returns: 91 | scripts.Visibility: The visibility setting for the script. 92 | """ 93 | return scripts.AlwaysVisible 94 | 95 | def ui(self, is_img2img): # pylint: disable=unused-argument 96 | with gr.Accordion(PromptPostProcessor.NAME, open=False): 97 | force_equal_seeds = gr.Checkbox( 98 | label="Force equal seeds", 99 | info="Force all image seeds and variation seeds to be equal to the first one, disabling the default autoincrease.", 100 | value=False, 101 | # show_label=True, 102 | elem_id="ppp_force_equal_seeds", 103 | ) 104 | gr.HTML("
") 105 | gr.Markdown( 106 | """ 107 | Unlink the seed to use the specified one for the prompts instead of the image seed. 108 | 109 | * A seed of -1 and "Incremental seed" checked will use a random seed for the first prompt and consecutive values for the rest. This is the same as when you use -1 for the image seed. 110 | * A seed of -1 and "Incremental seed" unchecked will use a random seed for each prompt. 111 | * Any other seed value and "Incremental seed" checked will use the specified seed for the first prompt and consecutive values for the rest. 112 | * Any other seed value and "Incremental seed" unchecked will use the specified seed for all the prompts. 113 | 114 | Seeds are only used for the wildcards and choice constructs. 115 | """ 116 | ) 117 | gr.HTML("
") 118 | with gr.Row(equal_height=True): 119 | unlink_seed = gr.Checkbox( 120 | label="Unlink seed", 121 | value=False, 122 | # show_label=True, 123 | elem_id="ppp_unlink_seed", 124 | ) 125 | seed = gr.Number( 126 | label="Prompt seed", 127 | value=-1, 128 | precision=0, 129 | # minimum=-1, 130 | # maximum=2**32 - 1, 131 | # step=1, 132 | # show_label=True, 133 | min_width=100, 134 | elem_id="ppp_seed", 135 | ) 136 | incremental_seed = gr.Checkbox( 137 | label="Incremental seed (only applies to batches)", 138 | value=False, 139 | # show_label=True, 140 | elem_id="ppp_incremental_seed", 141 | ) 142 | return [force_equal_seeds, unlink_seed, seed, incremental_seed] 143 | 144 | def process( 145 | self, 146 | p: StableDiffusionProcessing, 147 | input_force_equal_seeds, 148 | input_unlink_seed, 149 | input_seed, 150 | input_incremental_seed, 151 | ): # pylint: disable=arguments-differ 152 | """ 153 | Processes the prompts and applies post-processing operations. 154 | 155 | Args: 156 | p (StableDiffusionProcessing): The StableDiffusionProcessing object containing the prompts. 157 | input_force_equal_seeds (bool): Flag indicating whether to force equal seeds. 158 | input_unlink_seed (bool): Flag indicating whether to unlink the seed. 159 | input_seed (int): The seed value. 160 | input_incremental_seed (bool): Flag indicating whether to use incremental seed. 161 | 162 | Returns: 163 | None 164 | """ 165 | app = ( 166 | SUPPORTED_APPS.forge 167 | if hasattr(p.sd_model, "model_config") 168 | else ( 169 | SUPPORTED_APPS.reforge 170 | if hasattr(p.sd_model, "forge_objects") 171 | else ( 172 | SUPPORTED_APPS.sdnext 173 | if hasattr(p.sd_model, "is_sdxl") and not hasattr(p.sd_model, "is_ssd") 174 | else SUPPORTED_APPS.a1111 175 | ) 176 | ) 177 | ) 178 | if self.ppp_logger is None: 179 | lf = PromptPostProcessorLogFactory(app) 180 | self.ppp_logger = lf.log 181 | self.ppp_debug_level = DEBUG_LEVEL(getattr(opts, "ppp_gen_debug_level", DEBUG_LEVEL.none.value)) 182 | self.lru_cache = PPPLRUCache(1000, logger=self.ppp_logger, debug_level=self.ppp_debug_level) 183 | self.wildcards_obj = PPPWildcards(self.ppp_logger) 184 | self.extranetwork_mappings_obj = PPPExtraNetworkMappings(self.ppp_logger) 185 | self.ppp_logger.info( 186 | f"{PromptPostProcessor.NAME} {PromptPostProcessor.VERSION} initialized, running on {SUPPORTED_APPS_NAMES[app]}" 187 | ) 188 | t1 = time.monotonic_ns() 189 | if getattr(opts, "prompt_attention", "") == "Compel parser": 190 | self.ppp_logger.warning("Compel parser is not supported!") 191 | init_images = getattr(p, "init_images", [None]) or [None] 192 | is_i2i = bool(init_images[0]) 193 | self.ppp_debug_level = DEBUG_LEVEL(getattr(opts, "ppp_gen_debug_level", DEBUG_LEVEL.none.value)) 194 | do_i2i = getattr(opts, "ppp_gen_doi2i", False) 195 | add_prompts = getattr(opts, "ppp_gen_addpromptstometadata", True) 196 | if is_i2i and not do_i2i: 197 | if self.ppp_debug_level != DEBUG_LEVEL.none: 198 | self.ppp_logger.info("Not processing the prompt for i2i") 199 | return 200 | 201 | p.extra_generation_params.update( 202 | { 203 | "PPP force equal seeds": input_force_equal_seeds, 204 | "PPP unlink seed": input_unlink_seed, 205 | "PPP prompt seed": input_seed, 206 | "PPP incremental seed": input_incremental_seed, 207 | } 208 | ) 209 | 210 | if self.ppp_debug_level != DEBUG_LEVEL.none: 211 | self.ppp_logger.info(f"Post-processing prompts ({'i2i' if is_i2i else 't2i'})") 212 | models_supported = {x: True for x in PromptPostProcessor.SUPPORTED_MODELS} 213 | if app == SUPPORTED_APPS.sdnext: 214 | models_supported["ssd"] = False 215 | elif app == SUPPORTED_APPS.forge: 216 | models_supported["ssd"] = False 217 | models_supported["auraflow"] = False 218 | elif app == SUPPORTED_APPS.reforge: 219 | models_supported["flux"] = False 220 | models_supported["auraflow"] = False 221 | else: # assume A1111 compatible 222 | models_supported["flux"] = False 223 | models_supported["auraflow"] = False 224 | env_info = { 225 | "app": app.value, 226 | "models_path": models_path, 227 | "model_filename": getattr(p.sd_model.sd_checkpoint_info, "filename", ""), 228 | "model_class": "", 229 | "is_sd1": False, # Stable Diffusion 1 230 | "is_sd2": False, # Stable Diffusion 2 231 | "is_sdxl": False, # Stable Diffusion XL 232 | "is_ssd": False, # Segmind Stable Diffusion 1B 233 | "is_sd3": False, # Stable Diffusion 3 234 | "is_flux": False, # Flux 235 | "is_auraflow": False, # AuraFlow 236 | "is_pixart": False, # PixArt 237 | "is_lumina2": False, # Lumina2 238 | "is_ltxv": False, # LTXV 239 | "is_cosmos": False, # Cosmos 240 | "is_genmomochi": False, # GenmoMochi 241 | "is_hunyuan": False, # Hunyuan 242 | "is_hunyuanvideo": False, # HunyuanVideo 243 | "is_hunyuan3d": False, # Hunyuan3D 244 | "is_wanvideo": False, # WanVideo 245 | "is_hidream": False, # HiDream 246 | } 247 | if app == SUPPORTED_APPS.sdnext: 248 | # cannot differentiate SD1 and SD2, we set True to both 249 | # LatentDiffusion is for the original backend, StableDiffusionPipeline is for the diffusers backend 250 | env_info["model_class"] = p.sd_model.__class__.__name__ 251 | env_info["is_sd1"] = p.sd_model.__class__.__name__ in ("LatentDiffusion", "StableDiffusionPipeline") 252 | env_info["is_sd2"] = p.sd_model.__class__.__name__ in ("LatentDiffusion", "StableDiffusionPipeline") 253 | env_info["is_sdxl"] = p.sd_model.__class__.__name__ == "StableDiffusionXLPipeline" 254 | env_info["is_ssd"] = False # ? 255 | env_info["is_sd3"] = p.sd_model.__class__.__name__ == "StableDiffusion3Pipeline" 256 | env_info["is_flux"] = p.sd_model.__class__.__name__ == "FluxPipeline" 257 | env_info["is_auraflow"] = p.sd_model.__class__.__name__ == "AuraFlowPipeline" 258 | # also supports 'Latent Consistency Model': LatentConsistencyModelPipeline', 'PixArt-Alpha': 'PixArtAlphaPipeline', 'UniDiffuser': 'UniDiffuserPipeline', 'Wuerstchen': 'WuerstchenCombinedPipeline', 'Kandinsky 2.1': 'KandinskyPipeline', 'Kandinsky 2.2': 'KandinskyV22Pipeline', 'Kandinsky 3': 'Kandinsky3Pipeline', 'DeepFloyd IF': 'IFPipeline', 'Custom Diffusers Pipeline': 'DiffusionPipeline', 'InstaFlow': 'StableDiffusionPipeline', 'SegMoE': 'StableDiffusionPipeline', 'Kolors': 'KolorsPipeline', 'AuraFlow': 'AuraFlowPipeline', 'CogView': 'CogView3PlusPipeline' 259 | elif app == SUPPORTED_APPS.forge: 260 | # from repositories\huggingface_guess\huggingface_guess\model_list.py 261 | env_info["model_class"] = p.sd_model.model_config.__class__.__name__ 262 | env_info["is_sd1"] = getattr(p.sd_model, "is_sd1", False) 263 | env_info["is_sd2"] = getattr(p.sd_model, "is_sd2", False) 264 | env_info["is_sdxl"] = getattr(p.sd_model, "is_sdxl", False) 265 | env_info["is_ssd"] = False # ? 266 | env_info["is_sd3"] = getattr( 267 | p.sd_model, "is_sd3", False 268 | ) # p.sd_model.model_config.__class__.__name__ == "SD3" # not actually supported? 269 | env_info["is_flux"] = p.sd_model.model_config.__class__.__name__ in ("Flux", "FluxSchnell") 270 | env_info["is_auraflow"] = False # p.sd_model.model_config.__class__.__name__ == "AuraFlow" # not supported 271 | elif app == SUPPORTED_APPS.reforge: 272 | env_info["model_class"] = p.sd_model.__class__.__name__ 273 | env_info["is_sd1"] = getattr(p.sd_model, "is_sd1", False) 274 | env_info["is_sd2"] = getattr(p.sd_model, "is_sd2", False) 275 | env_info["is_sdxl"] = getattr(p.sd_model, "is_sdxl", False) 276 | env_info["is_ssd"] = getattr(p.sd_model, "is_ssd", False) 277 | env_info["is_sd3"] = getattr(p.sd_model, "is_sd3", False) 278 | env_info["is_flux"] = False 279 | env_info["is_auraflow"] = False 280 | else: # assume A1111 compatible (p.sd_model.__class__.__name__=="DiffusionEngine") 281 | env_info["model_class"] = p.sd_model.__class__.__name__ 282 | env_info["is_sd1"] = getattr(p.sd_model, "is_sd1", False) 283 | env_info["is_sd2"] = getattr(p.sd_model, "is_sd2", False) 284 | env_info["is_sdxl"] = getattr(p.sd_model, "is_sdxl", False) 285 | env_info["is_ssd"] = getattr(p.sd_model, "is_ssd", False) 286 | env_info["is_sd3"] = getattr(p.sd_model, "is_sd3", False) 287 | env_info["is_flux"] = False 288 | env_info["is_auraflow"] = False 289 | hash_envinfo = hash(tuple(sorted(env_info.items()))) 290 | wc_wildcards_folders = getattr(opts, "ppp_wil_wildcardsfolders", "") 291 | if wc_wildcards_folders == "": 292 | wc_wildcards_folders = os.getenv("WILDCARD_DIR", PPPWildcards.DEFAULT_WILDCARDS_FOLDER) 293 | wildcards_folders = [ 294 | (f if os.path.isabs(f) else os.path.abspath(os.path.join(models_path, f))) 295 | for f in wc_wildcards_folders.split(",") 296 | if f.strip() != "" 297 | ] 298 | en_mappings_folders = getattr(opts, "ppp_en_mappingsfolders", "") 299 | if en_mappings_folders == "": 300 | en_mappings_folders = os.getenv( 301 | "EXTRANETWORKMAPPINGS_DIR", 302 | PPPExtraNetworkMappings.DEFAULT_ENMAPPINGS_FOLDER, 303 | ) 304 | enmappings_folders = [ 305 | (f if os.path.isabs(f) else os.path.abspath(os.path.join(models_path, f))) 306 | for f in en_mappings_folders.split(",") 307 | if f.strip() != "" 308 | ] 309 | options = { 310 | "debug_level": getattr(opts, "ppp_gen_debug_level", DEBUG_LEVEL.none.value), 311 | "on_warning": getattr(opts, "ppp_gen_onwarning", PromptPostProcessor.ONWARNING_CHOICES.warn.value), 312 | "variants_definitions": getattr( 313 | opts, "ppp_gen_variantsdefinitions", PromptPostProcessor.DEFAULT_VARIANTS_DEFINITIONS 314 | ), 315 | "process_wildcards": getattr(opts, "ppp_wil_processwildcards", True), 316 | "if_wildcards": getattr(opts, "ppp_wil_ifwildcards", PromptPostProcessor.IFWILDCARDS_CHOICES.stop.value), 317 | "choice_separator": getattr(opts, "ppp_wil_choice_separator", PromptPostProcessor.DEFAULT_CHOICE_SEPARATOR), 318 | "keep_choices_order": getattr(opts, "ppp_wil_keep_choices_order", False), 319 | "stn_separator": getattr(opts, "ppp_stn_separator", PromptPostProcessor.DEFAULT_STN_SEPARATOR), 320 | "stn_ignore_repeats": getattr(opts, "ppp_stn_ignorerepeats", True), 321 | "cleanup_extra_spaces": getattr(opts, "ppp_cup_extraspaces", True), 322 | "cleanup_empty_constructs": getattr(opts, "ppp_cup_emptyconstructs", True), 323 | "cleanup_extra_separators": getattr(opts, "ppp_cup_extraseparators", True), 324 | "cleanup_extra_separators2": getattr(opts, "ppp_cup_extraseparators2", True), 325 | "cleanup_extra_separators_include_eol": getattr(opts, "ppp_cup_extraseparators_include_eol", True), 326 | "cleanup_breaks": getattr(opts, "ppp_cup_breaks", True), 327 | "cleanup_breaks_eol": getattr(opts, "ppp_cup_breaks_eol", False), 328 | "cleanup_ands": getattr(opts, "ppp_cup_ands", True), 329 | "cleanup_ands_eol": getattr(opts, "ppp_cup_ands_eol", False), 330 | "cleanup_extranetwork_tags": getattr(opts, "ppp_cup_extranetworktags", False), 331 | "cleanup_merge_attention": getattr(opts, "ppp_cup_mergeattention", True), 332 | "remove_extranetwork_tags": getattr(opts, "ppp_rem_removeextranetworktags", False), 333 | } 334 | hash_options = hash(tuple(sorted(options.items()))) 335 | self.wildcards_obj.refresh_wildcards( 336 | self.ppp_debug_level, wildcards_folders if options["process_wildcards"] else None 337 | ) 338 | self.extranetwork_mappings_obj.refresh_extranetwork_mappings(self.ppp_debug_level, enmappings_folders) 339 | ppp = PromptPostProcessor( 340 | self.ppp_logger, 341 | self.ppp_interrupt, 342 | env_info, 343 | options, 344 | self.grammar_content, 345 | self.wildcards_obj, 346 | self.extranetwork_mappings_obj, 347 | ) 348 | prompts_list = [] 349 | 350 | if input_force_equal_seeds: 351 | if self.ppp_debug_level != DEBUG_LEVEL.none: 352 | self.ppp_logger.info("Forcing equal seeds") 353 | seeds = getattr(p, "all_seeds", []) 354 | subseeds = getattr(p, "all_subseeds", []) 355 | p.all_seeds = [seeds[0] for _ in seeds] 356 | p.all_subseeds = [subseeds[0] for _ in subseeds] 357 | 358 | if input_unlink_seed: 359 | if self.ppp_debug_level != DEBUG_LEVEL.none: 360 | self.ppp_logger.info("Using unlinked seed") 361 | num_seeds = len(getattr(p, "all_seeds", [])) 362 | if input_incremental_seed: 363 | first_seed = np.random.randint(0, 2**32, dtype=np.int64) if input_seed == -1 else input_seed 364 | calculated_seeds = [first_seed + i for i in range(num_seeds)] 365 | elif input_seed == -1: 366 | calculated_seeds = np.random.randint(0, 2**32, size=num_seeds, dtype=np.int64) 367 | else: 368 | calculated_seeds = [input_seed for _ in range(num_seeds)] 369 | else: 370 | seeds = getattr(p, "all_seeds", []) 371 | subseeds = getattr(p, "all_subseeds", []) 372 | subseed_strength = getattr(p, "subseed_strength", 0.0) 373 | if subseed_strength > 0: 374 | calculated_seeds = [ 375 | int(subseed * subseed_strength + seed * (1 - subseed_strength)) 376 | for seed, subseed in zip(seeds, subseeds) 377 | ] 378 | # if len(set(calculated_seeds)) < len(calculated_seeds): 379 | # self.ppp_logger.info("Adjusting seeds because some are equal.") 380 | # calculated_seeds = [seed + i for i, seed in enumerate(calculated_seeds)] 381 | else: 382 | calculated_seeds = seeds 383 | 384 | # initialize extra generation parameters 385 | extra_params = {} 386 | 387 | # adds regular prompts 388 | rpr: list[str] = getattr(p, "all_prompts", None) 389 | rnr: list[str] = getattr(p, "all_negative_prompts", None) 390 | if rpr is not None and rnr is not None: 391 | prompts_list += [ 392 | ("regular", seed, prompt, negative_prompt) 393 | for seed, prompt, negative_prompt in zip(calculated_seeds, rpr, rnr) 394 | if (seed, prompt, negative_prompt) not in prompts_list 395 | ] 396 | # make it compatible with A1111 hires fix 397 | rph: list[str] = getattr(p, "all_hr_prompts", None) 398 | rnh: list[str] = getattr(p, "all_hr_negative_prompts", None) 399 | if rph is not None and rnh is not None and (rph != rpr or rnh != rnr): 400 | prompts_list += [ 401 | ("hiresfix", seed, prompt, negative_prompt) 402 | for seed, prompt, negative_prompt in zip(calculated_seeds, rph, rnh) 403 | if (seed, prompt, negative_prompt) not in prompts_list 404 | ] 405 | 406 | # processes prompts 407 | for i, (prompttype, seed, prompt, negative_prompt) in enumerate(prompts_list): 408 | if self.ppp_debug_level != DEBUG_LEVEL.none: 409 | self.ppp_logger.info(f"processing prompts[{i+1}] ({prompttype})") 410 | if ( 411 | self.lru_cache.get( 412 | (hash_envinfo, hash_options, seed, hash(self.wildcards_obj), prompt, negative_prompt) 413 | ) 414 | is None 415 | ): 416 | posp, negp, _ = ppp.process_prompt(prompt, negative_prompt, seed) 417 | self.lru_cache.put( 418 | (hash_envinfo, hash_options, seed, hash(self.wildcards_obj), prompt, negative_prompt), (posp, negp) 419 | ) 420 | # adds also the result so i2i doesn't process it unnecessarily 421 | self.lru_cache.put( 422 | (hash_envinfo, hash_options, seed, hash(self.wildcards_obj), posp, negp), (posp, negp) 423 | ) 424 | elif self.ppp_debug_level != DEBUG_LEVEL.none: 425 | self.ppp_logger.info("result already in cache") 426 | 427 | # updates the prompts 428 | rpr_copy = None 429 | rnr_copy = None 430 | if rpr is not None and rnr is not None: 431 | rpr_changes = False 432 | rnr_changes = False 433 | rpr_copy = rpr.copy() 434 | rnr_copy = rnr.copy() 435 | for i, (seed, prompt, negative_prompt) in enumerate(zip(calculated_seeds, rpr, rnr)): 436 | found = self.lru_cache.get( 437 | (hash_envinfo, hash_options, seed, hash(self.wildcards_obj), prompt, negative_prompt) 438 | ) 439 | if found is not None: 440 | if rpr[i].strip() != found[0].strip(): 441 | rpr_changes = True 442 | if rnr[i].strip() != found[1].strip(): 443 | rnr_changes = True 444 | rpr[i] = found[0] 445 | rnr[i] = found[1] 446 | if add_prompts: 447 | if rpr_changes: 448 | extra_params["PPP original prompts"] = rpr_copy 449 | if rnr_changes: 450 | extra_params["PPP original negative prompts"] = rnr_copy 451 | if rph is not None and rnh is not None: 452 | rph_changes = False 453 | rnh_changes = False 454 | rph_copy = rph.copy() 455 | rnh_copy = rnh.copy() 456 | for i, (seed, prompt, negative_prompt) in enumerate(zip(calculated_seeds, rph, rnh)): 457 | found = self.lru_cache.get( 458 | (hash_envinfo, hash_options, seed, hash(self.wildcards_obj), prompt, negative_prompt) 459 | ) 460 | if found is not None: 461 | if rph[i].strip() != found[0].strip() and (not rpr_copy or rph[i].strip() != rpr_copy[i].strip()): 462 | rph_changes = True 463 | if rnh[i].strip() != found[1].strip() and (not rnr_copy or rnh[i].strip() != rnr_copy[i].strip()): 464 | rnh_changes = True 465 | rph[i] = found[0] 466 | rnh[i] = found[1] 467 | if add_prompts: 468 | if rph_changes: 469 | extra_params["PPP original HR prompts"] = rph_copy 470 | if rnh_changes: 471 | extra_params["PPP original HR negative prompts"] = rnh_copy 472 | 473 | # fill extra generation parameters only if not already present 474 | for k, v in extra_params.items(): 475 | if p.extra_generation_params.get(k) is None: 476 | p.extra_generation_params[k] = v 477 | 478 | t2 = time.monotonic_ns() 479 | if self.ppp_debug_level != DEBUG_LEVEL.none: 480 | self.ppp_logger.info(f"process time: {(t2 - t1) / 1_000_000_000:.3f} seconds") 481 | 482 | def ppp_interrupt(self): 483 | """ 484 | Interrupts the generation. 485 | 486 | Returns: 487 | None 488 | """ 489 | shared.state.interrupted = True 490 | 491 | 492 | def on_ui_settings(): 493 | """ 494 | Callback function for UI settings. 495 | 496 | Returns: 497 | None 498 | """ 499 | 500 | section = ("prompt-post-processor", PromptPostProcessor.NAME) 501 | 502 | def import_old_settings(names, default): 503 | for name in names: 504 | if hasattr(opts, name): 505 | return getattr(opts, name) 506 | return default 507 | 508 | def import_bool_to_any(name, value_false, value_true, default): 509 | if hasattr(opts, name): 510 | return value_true if getattr(opts, name) else value_false 511 | return default 512 | 513 | def new_html_title(title): 514 | info = shared.OptionInfo( 515 | title, 516 | "", 517 | gr.HTML, 518 | section=section, 519 | ) 520 | info.do_not_save = True 521 | return info 522 | 523 | # general settings 524 | shared.opts.add_option( 525 | key="ppp_gen_sep", 526 | info=new_html_title("

General settings

"), 527 | ) 528 | shared.opts.add_option( 529 | key="ppp_gen_debug_level", 530 | info=shared.OptionInfo( 531 | default=import_bool_to_any( 532 | "ppp_gen_debug", 533 | DEBUG_LEVEL.minimal.value, 534 | DEBUG_LEVEL.full.value, 535 | DEBUG_LEVEL.minimal.value, 536 | ), 537 | label="Debug level", 538 | component=gr.Radio, 539 | component_args={ 540 | "choices": ( 541 | ("None", DEBUG_LEVEL.none.value), 542 | ("Minimal", DEBUG_LEVEL.minimal.value), 543 | ("Full", DEBUG_LEVEL.full.value), 544 | ), 545 | }, 546 | section=section, 547 | ), 548 | ) 549 | shared.opts.add_option( 550 | key="ppp_gen_onwarning", 551 | info=shared.OptionInfo( 552 | default=PromptPostProcessor.ONWARNING_CHOICES.warn.value, 553 | label="What to do on invalid content warnings?", 554 | component=gr.Radio, 555 | component_args={ 556 | "choices": ( 557 | ("Show warning in console", PromptPostProcessor.ONWARNING_CHOICES.warn.value), 558 | ("Stop the generation", PromptPostProcessor.ONWARNING_CHOICES.stop.value), 559 | ) 560 | }, 561 | section=section, 562 | ), 563 | ) 564 | shared.opts.add_option( 565 | key="ppp_gen_variantsdefinitions", 566 | info=shared.OptionInfo( 567 | PromptPostProcessor.DEFAULT_VARIANTS_DEFINITIONS, 568 | label="Definitions for variant models", 569 | comment_after="Recognized based on strings found in the full filename. Format for each line is: 'name(kind)=comma separated list of substrings (case insensitive)' with kind being one of the base model types (" 570 | + ",".join(PromptPostProcessor.SUPPORTED_MODELS) 571 | + ") or not specified.", 572 | component=gr.Textbox, 573 | component_args={"lines": 7}, 574 | section=section, 575 | ), 576 | ) 577 | shared.opts.add_option( 578 | key="ppp_gen_doi2i", 579 | info=shared.OptionInfo( 580 | False, 581 | label="Apply in img2img", 582 | comment_after='(this includes any pass that contains an initial image, like adetailer)', 583 | section=section, 584 | ), 585 | ) 586 | shared.opts.add_option( 587 | key="ppp_gen_addpromptstometadata", 588 | info=shared.OptionInfo( 589 | True, 590 | label="Add original prompts to metadata (if they change)", 591 | section=section, 592 | ), 593 | ) 594 | 595 | shared.opts.add_option( 596 | key="ppp_en_mappingsfolders", 597 | info=shared.OptionInfo( 598 | PPPExtraNetworkMappings.DEFAULT_ENMAPPINGS_FOLDER, 599 | label="Extranetwork Mappings folders", 600 | comment_after='(absolute or relative to the models folder)', 601 | section=section, 602 | ), 603 | ) 604 | 605 | # wildcard settings 606 | shared.opts.add_option( 607 | key="ppp_wil_sep", 608 | info=new_html_title("

Wildcard settings

"), 609 | ) 610 | shared.opts.add_option( 611 | key="ppp_wil_processwildcards", 612 | info=shared.OptionInfo( 613 | True, 614 | label="Process wildcards", 615 | section=section, 616 | ), 617 | ) 618 | shared.opts.add_option( 619 | key="ppp_wil_wildcardsfolders", 620 | info=shared.OptionInfo( 621 | PPPWildcards.DEFAULT_WILDCARDS_FOLDER, 622 | label="Wildcards folders", 623 | comment_after='(absolute or relative to the models folder)', 624 | section=section, 625 | ), 626 | ) 627 | shared.opts.add_option( 628 | key="ppp_wil_ifwildcards", 629 | info=shared.OptionInfo( 630 | default=import_old_settings( 631 | ["ppp_gen_ifwildcards", "ppp_ifwildcards"], 632 | PromptPostProcessor.IFWILDCARDS_CHOICES.ignore.value, 633 | ), 634 | label="What to do with remaining/invalid wildcards?", 635 | component=gr.Radio, 636 | component_args={ 637 | "choices": ( 638 | ("Ignore", PromptPostProcessor.IFWILDCARDS_CHOICES.ignore.value), 639 | ("Remove", PromptPostProcessor.IFWILDCARDS_CHOICES.remove.value), 640 | ("Add visible warning", PromptPostProcessor.IFWILDCARDS_CHOICES.warn.value), 641 | ("Stop the generation", PromptPostProcessor.IFWILDCARDS_CHOICES.stop.value), 642 | ) 643 | }, 644 | section=section, 645 | ), 646 | ) 647 | shared.opts.add_option( 648 | key="ppp_wil_choice_separator", 649 | info=shared.OptionInfo( 650 | PromptPostProcessor.DEFAULT_CHOICE_SEPARATOR, 651 | label="Default separator used when adding multiple choices", 652 | section=section, 653 | ), 654 | ) 655 | shared.opts.add_option( 656 | key="ppp_wil_keep_choices_order", 657 | info=shared.OptionInfo( 658 | False, 659 | label="Keep the order of selected choices", 660 | section=section, 661 | ), 662 | ) 663 | 664 | # content removal settings 665 | shared.opts.add_option( 666 | key="ppp_rem_sep", 667 | info=new_html_title("

Content removal settings

"), 668 | ) 669 | shared.opts.add_option( 670 | key="ppp_rem_removeextranetworktags", 671 | info=shared.OptionInfo( 672 | False, 673 | label="Remove extra network tags", 674 | section=section, 675 | ), 676 | ) 677 | 678 | # send to negative settings 679 | shared.opts.add_option( 680 | key="ppp_stn_sep", 681 | info=new_html_title("

Send to Negative settings

"), 682 | ) 683 | shared.opts.add_option( 684 | key="ppp_stn_separator", 685 | info=shared.OptionInfo( 686 | PromptPostProcessor.DEFAULT_STN_SEPARATOR, 687 | label="Separator used when adding to the negative prompt", 688 | section=section, 689 | ), 690 | ) 691 | shared.opts.add_option( 692 | key="ppp_stn_ignorerepeats", 693 | info=shared.OptionInfo( 694 | True, 695 | label="Ignore repeated content", 696 | section=section, 697 | ), 698 | ) 699 | # clean-up settings 700 | shared.opts.add_option( 701 | key="ppp_cup_sep", 702 | info=new_html_title("

Clean-up settings

"), 703 | ) 704 | shared.opts.add_option( 705 | key="ppp_cup_emptyconstructs", 706 | info=shared.OptionInfo( 707 | True, 708 | label="Remove empty constructs (attention, alternation, scheduling)", 709 | section=section, 710 | ), 711 | ) 712 | shared.opts.add_option( 713 | key="ppp_cup_extraseparators", 714 | info=shared.OptionInfo( 715 | True, 716 | label="Remove extra separators", 717 | section=section, 718 | ), 719 | ) 720 | shared.opts.add_option( 721 | key="ppp_cup_extraseparators2", 722 | info=shared.OptionInfo( 723 | True, 724 | label="Remove additional extra separators", 725 | section=section, 726 | ), 727 | ) 728 | shared.opts.add_option( 729 | key="ppp_cup_extraseparators_include_eol", 730 | info=shared.OptionInfo( 731 | False, 732 | label="The extra separators options also remove EOLs", 733 | section=section, 734 | ), 735 | ) 736 | shared.opts.add_option( 737 | key="ppp_cup_breaks", 738 | info=shared.OptionInfo( 739 | True, 740 | label="Clean up around BREAKs", 741 | section=section, 742 | ), 743 | ) 744 | shared.opts.add_option( 745 | key="ppp_cup_breaks_eol", 746 | info=shared.OptionInfo( 747 | False, 748 | label="Use EOL instead of Space before BREAKs", 749 | section=section, 750 | ), 751 | ) 752 | shared.opts.add_option( 753 | key="ppp_cup_ands", 754 | info=shared.OptionInfo( 755 | True, 756 | label="Clean up around ANDs", 757 | section=section, 758 | ), 759 | ) 760 | shared.opts.add_option( 761 | key="ppp_cup_ands_eol", 762 | info=shared.OptionInfo( 763 | False, 764 | label="Use EOL instead of Space before ANDs", 765 | section=section, 766 | ), 767 | ) 768 | shared.opts.add_option( 769 | key="ppp_cup_extranetworktags", 770 | info=shared.OptionInfo( 771 | False, 772 | label="Clean up around extra network tags", 773 | section=section, 774 | ), 775 | ) 776 | shared.opts.add_option( 777 | key="ppp_cup_extraspaces", 778 | info=shared.OptionInfo( 779 | True, 780 | label="Remove extra spaces", 781 | section=section, 782 | ), 783 | ) 784 | shared.opts.add_option( 785 | key="ppp_cup_mergeattention", 786 | info=shared.OptionInfo( 787 | True, 788 | label="Merge attention modifiers (weights) when possible", 789 | section=section, 790 | ), 791 | ) 792 | 793 | # Remove old settings 794 | # for name in ["ppp_gen_ifwildcards", "ppp_ifwildcards", "ppp_gen_debug", "ppp_stn_doi2i", "ppp_cup_doi2i"]: 795 | # if hasattr(opts, name): 796 | # delattr(opts, name) 797 | 798 | 799 | script_callbacks.on_ui_settings(on_ui_settings) 800 | --------------------------------------------------------------------------------