Skip to content

Commit

Permalink
commit UserPromptGeneratorTxt2ImgWithReference node
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Sep 26, 2024
1 parent d6c576a commit 5486aa1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
14 changes: 14 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ When this error has occurred, please check the network environment.
## Update
<font size="4">**If the dependency package error after updating, please double clicking ```repair_dependency.bat``` (for Official ComfyUI Protable) or ```repair_dependency_aki.bat``` (for ComfyUI-aki-v1.x) in the plugin folder to reinstall the dependency packages. </font><br />

* Commit [UserPromptGeneratorTxtImgWithReference](#UserPromptGeneratorTxtImgWithReference) node.
* Commit [GrayValue](#GrayValue) node, output the grayscale values corresponding to the RGB color values.
* [LUT Apply](#LUT), [TextImageV2](#TextImageV2), [TextImage](#TextImage), [SimpleTextImage](#SimpleTextImage) nodes to support defining multiple folders in ```resource-dir.ini```, separated by commas, semicolons, or spaces. Simultaneously supports refreshing real-time updates.
* [LUT Apply](#LUT), [TextImageV2](#TextImageV2), [TextImage](#TextImage), [SimpleTextImage](#SimpleTextImage) nodes support defining multi directory fonts and lut folders, and support refreshing and real-time updates.
Expand Down Expand Up @@ -816,6 +817,19 @@ Node options:
* describe: Prompt word description. Enter a simple description here.
* limit_word: Maximum length limit for output prompt words. For example, 200 means that the output text will be limited to 200 words.


### <a id="table1">UserPromptGeneratorTxtImgWithReference</a>
UserCompt preset for generating SD text to image prompt words based on input content.

Node options:
![image](image/userprompt_generator_txt2img_with_reference_node.jpg)

* reference_text: Reference text input. Usually it is a style description of the image.
* template: Prompt word template. Currently, only the 'SD txt2img prompt' is available.
* describe: Prompt word description. Enter a simple description here.
* limit_word: Maximum length limit for output prompt words. For example, 200 means that the output text will be limited to 200 words.


### <a id="table1">UserPromptGeneratorReplaceWord</a>
UserPrompt preset used to replace a keyword in text with different content. This is not only a simple replacement, but also a logical sorting of the text based on the context of the prompt words to achieve the rationality of the output content.

Expand Down
13 changes: 13 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
## 更新说明
<font size="4">**如果本插件更新后出现依赖包错误,请双击运行插件目录下的```install_requirements.bat```(官方便携包),或 ```install_requirements_aki.bat```(秋叶整合包) 重新安装依赖包。

* 添加 [UserPromptGeneratorTxtImgWithReference](#UserPromptGeneratorTxtImgWithReference) 节点。
* 添加 [GrayValue](#GrayValue) 节点,输出RGB色值对应的灰度值。
* [LUT Apply](#LUT), [TextImageV2](#TextImageV2), [TextImage](#TextImage), [SimpleTextImage](#SimpleTextImage) 等节点支持在 ```resource_dir.ini``` 中定义多个文件夹,之间用逗号,分号或者空格分隔。同时支持刷新实时更新。
* 添加 [HumanPartsUltra](#HumanPartsUltra) 节点,用于人物肢体分割。本节点是基于[metal3d/ComfyUI_Human_Parts](https://github.com/metal3d/ComfyUI_Human_Parts) 的重新封装,感谢原作者。
Expand Down Expand Up @@ -805,6 +806,18 @@ ImageScaleByAspectRatio的V2升级版
* describe: 提示词描述。在这里输入简单的描述。
* limit_word: 输出的提示词最大长度限制。例如200即表示输出文本将被限制在200个词以内。

### <a id="table1">UserPromptGeneratorTxtImgWithReference</a>
用于参考输入的内容生成SD文本到图片提示词的UserPrompt预设。

节点选项说明:
![image](image/userprompt_generator_txt2img_with_reference_node.jpg)

* reference_text: 参考文本输入。通常是图片的风格描述。
* template: 提示词模板。目前仅有“SD txt2img prompt”可用。
* describe: 提示词描述。在这里输入简单的描述。
* limit_word: 输出的提示词最大长度限制。例如200即表示输出文本将被限制在200个词以内。


### <a id="table1">UserPromptGeneratorReplaceWord</a>
用于将文本中的某个关键词替换为不同内容的UserPrompt预设。这不仅是简单的替换,还可以根据提示词上下文进行文字逻辑梳理以达到输出内容的合理性。

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions py/user_prompt_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
from .imagefunc import log

class LS_UserPromptGenerator_Txt2ImgPromptWithReference:

def __init__(self):
self.NODE_NAME = 'UserPromptGenerator-Txt2ImgPromptWithReference'

@classmethod
def INPUT_TYPES(self):
template_list = ['SD txt2img prompt',]
return {
"required": {
"template": (template_list,),
"reference_text": ("STRING", {"multiline": False,"forceInput":True}),
"describe": ("STRING", {"default": "1 girl","multiline": True}),
"limit_words": ("INT", {"default": 200, "min": 2, "max": 999, "step": 1}),
},
"optional": {
}
}

RETURN_TYPES = ("STRING", )
RETURN_NAMES = ("user_prompt", )
FUNCTION = 'user_prompt_generator_txt2img_prompt_with_reference'
CATEGORY = '😺dzNodes/LayerUtility/Prompt'

def user_prompt_generator_txt2img_prompt_with_reference(self, template, reference_text, describe, limit_words):

if template == 'SD txt2img prompt':
prompt = (f'The REFERENCE TEXT is "{reference_text}".\r\n'
f"You are creating a prompt for Stable Diffusion to generate an image.\r\n"
f"Using '{describe}' as the basic content and depicting it as main subject, refer to the visual style described in the REFERENCE TEXT, polish and embellish it to describe into text.\r\n"
f"The word limit for the answer is between {int(limit_words * 0.7)} - {int(limit_words * 1.1)} words. Not too little, nor too much.\r\n"
f"Only output the prompt itself, don't output any unnecessary content like word count info.")

log(f'{self.NODE_NAME} Processed. result is \r\n"{prompt}".')
return (prompt,)


class LS_UserPromptGenerator_Txt2ImgPrompt:

def __init__(self):
Expand Down Expand Up @@ -73,10 +110,12 @@ def user_prompt_generator_replace_word(self, orig_prompt, template, exclude_word

NODE_CLASS_MAPPINGS = {
"LayerUtility: UserPromptGeneratorTxt2ImgPrompt": LS_UserPromptGenerator_Txt2ImgPrompt,
"LayerUtility: UserPromptGeneratorTxt2ImgPromptWithReference": LS_UserPromptGenerator_Txt2ImgPromptWithReference,
"LayerUtility: UserPromptGeneratorReplaceWord": LS_UserPromptGenerator_ReplaceWord
}

NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: UserPromptGeneratorTxt2ImgPrompt": "LayerUtility: UserPrompt Generator Txt2Img",
"LayerUtility: UserPromptGeneratorTxt2ImgPromptWithReference": "LayerUtility: UserPrompt Generator Txt2Img with Reference",
"LayerUtility: UserPromptGeneratorReplaceWord": "LayerUtility: UserPrompt Generator Replace Word"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_layerstyle"
description = "A set of nodes for ComfyUI it generate image like Adobe Photoshop's Layer Style. the Drop Shadow is first completed node, and follow-up work is in progress."
version = "1.0.66"
version = "1.0.67"
license = "MIT"
dependencies = ["numpy", "pillow", "torch", "matplotlib", "Scipy", "scikit_image", "scikit_learn", "opencv-contrib-python", "pymatting", "segment_anything", "timm", "addict", "yapf", "colour-science", "wget", "mediapipe", "loguru", "typer_config", "fastapi", "rich", "google-generativeai", "diffusers", "omegaconf", "tqdm", "transformers", "kornia", "image-reward", "ultralytics", "blend_modes", "blind-watermark", "qrcode", "pyzbar", "transparent-background", "huggingface_hub", "accelerate", "bitsandbytes", "torchscale", "wandb", "hydra-core", "psd-tools", "inference-cli[yolo-world]", "inference-gpu[yolo-world]", "onnxruntime"]

Expand Down
4 changes: 2 additions & 2 deletions resource_dir.ini.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FONT_dir=C:\font,C:\another\font
LUT_dir=C:\lut,C:\another\lut
FONT_dir=C:\font,D:\other_font
LUT_dir=C:\lut,D:\other_lut

0 comments on commit 5486aa1

Please sign in to comment.