# 初始化

This commit is contained in:
xiangyuanmeng
2023-11-29 21:01:44 +08:00
commit 0933c8ba26
22 changed files with 512 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 twri
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+72
View File
@@ -0,0 +1,72 @@
## 风格选择器
![demo.png](image/demo.png)
## 简单的风格介绍
均以以下提示词出图(为SDXL出图)
![img.png](image/img.png)
宽高: 768 x 1024
采样: dpmpp 2M Karras x 10步
### 摄影棚
![img_2.png](image/img_2.png)
### 生活摄影风格
![img_3.png](image/img_3.png)
### 模特摄影风格
![img_4.png](image/img_4.png)
### 肖像摄影风格
![img_5.png](image/img_5.png)
### 富士摄影风格
![img_6.png](image/img_6.png)
### 人物抽象插画
![img_7.png](image/img_7.png)
### 混合抽象插画
![img_8.png](image/img_8.png)
### 黑暗恐怖主题
![img_9.png](image/img_9.png)
### 黑暗主题
![img_10.png](image/img_10.png)
### 机械朋克主题
![img_11.png](image/img_11.png)
尝试使用LCM出图效果如下
![img.png](image/imgLCM.png)
### 线稿(复杂设计)
> 时灵时不灵
![img_12.png](image/img_12.png)
### 线稿(简单)
> 时灵时不灵
![img_1.png](image/img_1.png)
### 复杂细节
![img_13.png](image/img_13.png)
+3
View File
@@ -0,0 +1,3 @@
from .mexx_styler import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 494 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

+306
View File
@@ -0,0 +1,306 @@
import json
import os
def read_json_file(file_path):
"""
Reads a JSON file's content and returns it.
Ensures content matches the expected format.
"""
if not os.access(file_path, os.R_OK):
print(f"Warning: No read permissions for file {file_path}")
return None
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = json.load(file)
# Check if the content matches the expected format.
if not all(['name' in item and 'prompt' in item and 'negative_prompt' in item for item in content]):
print(f"Warning: Invalid content in file {file_path}")
return None
return content
except Exception as e:
print(f"An error occurred while reading {file_path}: {str(e)}")
return None
def read_sdxl_styles(json_data):
"""
Returns style names from the provided JSON data.
"""
if not isinstance(json_data, list):
print("Error: input data must be a list")
return []
return [item['name'] for item in json_data if isinstance(item, dict) and 'name' in item]
def get_all_json_files(directory):
"""
Returns all JSON files from the specified directory.
"""
return [os.path.join(directory, file) for file in os.listdir(directory) if file.endswith('.json') and os.path.isfile(os.path.join(directory, file))]
def load_styles_from_directory(directory):
"""
Loads styles from all JSON files in the directory.
Renames duplicate style names by appending a suffix.
"""
json_files = get_all_json_files(directory)
combined_data = []
seen = set()
for json_file in json_files:
json_data = read_json_file(json_file)
if json_data:
for item in json_data:
original_style = item['name']
style = original_style
suffix = 1
while style in seen:
style = f"{original_style}_{suffix}"
suffix += 1
item['name'] = style
seen.add(style)
combined_data.append(item)
unique_style_names = [item['name'] for item in combined_data if isinstance(item, dict) and 'name' in item]
return combined_data, unique_style_names
def validate_json_data(json_data):
"""
Validates the structure of the JSON data.
"""
if not isinstance(json_data, list):
return False
for template in json_data:
if 'name' not in template or 'prompt' not in template:
return False
return True
def find_template_by_name(json_data, template_name):
"""
Returns a template from the JSON data by name or None if not found.
"""
for template in json_data:
if template['name'] == template_name:
return template
return None
def split_template_advanced(template: str) -> tuple:
"""
Splits a template into two parts based on a specific pattern.
"""
if "{prompt} ." in template:
template_prompt_g, template_prompt_l = template.split("{prompt} .", 1)
template_prompt_g = template_prompt_g.strip() + " {prompt}"
template_prompt_l = template_prompt_l.strip()
else:
template_prompt_g = template
template_prompt_l = ""
return template_prompt_g, template_prompt_l
def replace_prompts_in_template(template, positive_prompt, negative_prompt):
"""
Replace the placeholders in a given template with the provided prompts.
Args:
- template (dict): The template containing prompt placeholders.
- positive_prompt (str): The positive prompt to replace '{prompt}' in the template.
- negative_prompt (str): The negative prompt to be combined with any existing negative prompt in the template.
Returns:
- tuple: A tuple containing the replaced positive and negative prompts.
"""
positive_result = template['prompt'].replace('{prompt}', positive_prompt)
json_negative_prompt = template.get('negative_prompt', "")
negative_result = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt and negative_prompt else json_negative_prompt or negative_prompt
return positive_result, negative_result
def replace_prompts_in_template_advanced(template, positive_prompt_g, positive_prompt_l, negative_prompt, negative_prompt_to):
"""
Replace the placeholders in a given template with the provided prompts and split them accordingly.
Args:
- template (dict): The template containing prompt placeholders.
- positive_prompt_g (str): The main positive prompt to replace '{prompt}' in the template.
- positive_prompt_l (str): The auxiliary positive prompt to be combined in a specific manner.
- negative_prompt (str): The negative prompt to be combined with any existing negative prompt in the template.
- negative_prompt_to (str): The negative prompt destination {Both, G only, L only}.
Returns:
- tuple: A tuple containing the replaced main positive, auxiliary positive, combined positive, main negative, auxiliary negative, and negative prompts.
"""
template_prompt_g, template_prompt_l_template = split_template_advanced(template['prompt'])
text_g_positive = template_prompt_g.replace("{prompt}", positive_prompt_g)
text_l_positive = f"{template_prompt_l_template}, {positive_prompt_l}" if template_prompt_l_template and positive_prompt_l else template_prompt_l_template or positive_prompt_l
text_positive = f"{text_g_positive} . {text_l_positive}" if text_l_positive else text_g_positive
json_negative_prompt = template.get('negative_prompt', "")
text_negative = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt and negative_prompt else json_negative_prompt or negative_prompt
text_g_negative = ""
if negative_prompt_to in ("Both", "G only"):
text_g_negative = text_negative
text_l_negative = ""
if negative_prompt_to in ("Both", "L only"):
text_l_negative = text_negative
return text_g_positive, text_l_positive, text_positive, text_g_negative, text_l_negative, text_negative
def read_sdxl_templates_replace_and_combine(json_data, template_name, positive_prompt, negative_prompt):
"""
Find a specific template by its name, then replace and combine its placeholders with the provided prompts.
Args:
- json_data (list): The list of templates.
- template_name (str): The name of the desired template.
- positive_prompt (str): The positive prompt to replace placeholders.
- negative_prompt (str): The negative prompt to be combined.
Returns:
- tuple: A tuple containing the replaced and combined positive and negative prompts.
"""
if not validate_json_data(json_data):
return positive_prompt, negative_prompt
template = find_template_by_name(json_data, template_name)
if template:
return replace_prompts_in_template(template, positive_prompt, negative_prompt)
else:
return positive_prompt, negative_prompt
def read_sdxl_templates_replace_and_combine_advanced(json_data, template_name, positive_prompt_g, positive_prompt_l, negative_prompt, negative_prompt_to):
"""
Find a specific template by its name, then replace and combine its placeholders with the provided prompts in an advanced manner.
Args:
- json_data (list): The list of templates.
- template_name (str): The name of the desired template.
- positive_prompt_g (str): The main positive prompt.
- positive_prompt_l (str): The auxiliary positive prompt.
- negative_prompt (str): The negative prompt to be combined.
- negative_prompt_to (str): The negative prompt destination {Both, G only, L only}.
Returns:
- tuple: A tuple containing the replaced and combined main positive, auxiliary positive, combined positive, main negative, auxiliary negative, and negative prompts.
"""
if not validate_json_data(json_data):
return positive_prompt_g, positive_prompt_l, f"{positive_prompt_g} . {positive_prompt_l}", negative_prompt, negative_prompt, negative_prompt
template = find_template_by_name(json_data, template_name)
if template:
return replace_prompts_in_template_advanced(template, positive_prompt_g, positive_prompt_l, negative_prompt, negative_prompt_to)
else:
return positive_prompt_g, positive_prompt_l, f"{positive_prompt_g} . {positive_prompt_l}", negative_prompt, negative_prompt, negative_prompt
class MexxSDXLPromptStyler:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(self):
current_directory = os.path.dirname(os.path.realpath(__file__))
self.json_data, styles = load_styles_from_directory(current_directory)
return {
"required": {
"text_positive": ("STRING", {"default": "a beautiful k-pop girl with soaked dress", "multiline": True}),
"text_negative": ("STRING", {"default": "noisy, blurry, deformed, ugly", "multiline": True}),
"style": (styles,),
"log_prompt": (["No", "Yes"], {"default":"Yes"}),
},
}
RETURN_TYPES = ('STRING','STRING',)
RETURN_NAMES = ('text_positive','text_negative',)
FUNCTION = 'prompt_styler'
CATEGORY = 'utils'
def prompt_styler(self, text_positive, text_negative, style, log_prompt):
# Process and combine prompts in templates
# The function replaces the positive prompt placeholder in the template,
# and combines the negative prompt with the template's negative prompt, if they exist.
text_positive_styled, text_negative_styled = read_sdxl_templates_replace_and_combine(self.json_data, style, text_positive, text_negative)
# If logging is enabled (log_prompt is set to "Yes"),
# print the style, positive and negative text, and positive and negative prompts to the console
if log_prompt == "Yes":
print(f"style: {style}")
print(f"text_positive: {text_positive}")
print(f"text_negative: {text_negative}")
print(f"text_positive_styled: {text_positive_styled}")
print(f"text_negative_styled: {text_negative_styled}")
return text_positive_styled, text_negative_styled
class MexxSDXLPromptStylerAdvanced:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(self):
current_directory = os.path.dirname(os.path.realpath(__file__))
self.json_data, styles = load_styles_from_directory(current_directory)
return {
"required": {
"text_positive_g": ("STRING", {"default": "", "multiline": True}),
"text_positive_l": ("STRING", {"default": "", "multiline": True}),
"text_negative": ("STRING", {"default": "", "multiline": True}),
"style": ((styles), ),
"negative_prompt_to": (["Both", "G only", "L only"], {"default":"Both"}),
"log_prompt": (["No", "Yes"], {"default":"No"}),
},
}
RETURN_TYPES = ('STRING','STRING','STRING','STRING','STRING','STRING',)
RETURN_NAMES = ('text_positive_g','text_positive_l','text_positive','text_negative_g','text_negative_l','text_negative',)
FUNCTION = 'prompt_styler_advanced'
CATEGORY = 'utils'
def prompt_styler_advanced(self, text_positive_g, text_positive_l, text_negative, style, negative_prompt_to, log_prompt):
# Process and combine prompts in templates
# The function replaces the positive prompt placeholder in the template,
# and combines the negative prompt with the template's negative prompt, if they exist.
text_positive_g_styled, text_positive_l_styled, text_positive_styled, text_negative_g_styled, text_negative_l_styled, text_negative_styled = read_sdxl_templates_replace_and_combine_advanced(self.json_data, style, text_positive_g, text_positive_l, text_negative, negative_prompt_to)
# If logging is enabled (log_prompt is set to "Yes"),
# print the style, positive and negative text, and positive and negative prompts to the console
if log_prompt == "Yes":
print(f"style: {style}")
print(f"text_positive_g: {text_positive_g}")
print(f"text_positive_l: {text_positive_l}")
print(f"text_negative: {text_negative}")
print(f"text_positive_g_styled: {text_positive_g_styled}")
print(f"text_positive_l_styled: {text_positive_l_styled}")
print(f"text_positive_styled: {text_positive_styled}")
print(f"text_negative_g_styled: {text_negative_g_styled}")
print(f"text_negative_l_styled: {text_negative_l_styled}")
print(f"text_negative_styled: {text_negative_styled}")
return text_positive_g_styled, text_positive_l_styled, text_positive_styled, text_negative_g_styled, text_negative_l_styled, text_negative_styled
NODE_CLASS_MAPPINGS = {
"MexxSDXLPromptStyler": MexxSDXLPromptStyler,
"MexxSDXLPromptStylerAdvanced": MexxSDXLPromptStylerAdvanced,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"MexxSDXLPromptStyler": "ComfyUI Mexx Styler",
"MexxSDXLPromptStylerAdvanced": "ComfyUI Mexx Styler Advanced",
}
+72
View File
@@ -0,0 +1,72 @@
[
{
"name": "无",
"prompt": "{prompt}",
"negative_prompt": ""
},
{
"name": "摄影棚",
"prompt": "Studio Photography,Leica M50 F/2.8,deep Shadows,vivid colorsexposure Mixing,sharp focus,glorification, {prompt}, professional,RAW photo,highly detailed,intricate details,extremely detailed,",
"negative_prompt": "anime, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "生活摄影风格",
"prompt": "Lifestyle Photography, 35mm photograph, {prompt}, film, bokeh, professional, 4k, highly detailed, intricate details, extremely detailed, sharp focus, soft cinematic light",
"negative_prompt": "anime, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "模特摄影风格",
"prompt": "Model Photography, 35mm photograph, {prompt}, film, bokeh, professional, 4k, highly detailed, intricate details, extremely detailed, sharp focus, soft cinematic light",
"negative_prompt": "anime, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "肖像摄影风格",
"prompt": "Protrait Photography, 35mm photograph, {prompt}, film, bokeh, professional, 4k, highly detailed, intricate details, extremely detailed, hard focus",
"negative_prompt": "anime, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
},
{
"name": "富士摄影风格",
"prompt": "35mm Photography, Fujifilm Provia 400X, {prompt}, film, bokeh, professional, 4k, highly detailed, intricate details, extremely detailed, hard focus",
"negative_prompt": "anime, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
},
{
"name": "人物抽象插画",
"prompt": "It is Agnes cecile's works, {prompt}, highly detailed, intricate details, extremely detailed, dramatic atmosphere, atmospheric perspective",
"negative_prompt": "photography, anime, crayon, sketch, graphite, noisy, blurry, deformed, ugly"
},
{
"name": "混合抽象插画",
"prompt": "It is Anne Bachelier's works, {prompt}, highly detailed, intricate details, extremely detailed, dramatic atmosphere, atmospheric perspective",
"negative_prompt": "photography, anime, crayon, sketch, graphite, noisy, blurry, deformed, ugly"
},
{
"name": "黑暗恐怖主题",
"prompt": "The abstract style of the horror theme, dark Magic, {prompt}, highly detailed, intricate details, extremely detailed, heavy breathing, terrifying, ferocious",
"negative_prompt": "anime, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "黑暗主题",
"prompt": "dark Style,emitting a sense of dilapidation,a painting,{prompt},natural skin texture,intricate details,background of horror movies,perfect detailed,extremely detailed,hyper detailedextremely detailed,deep shadows,vibrant colors,dynamic Lighting,hard focus",
"negative_prompt": "anime, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "机械朋克主题",
"prompt": "(biomechanical style), {prompt}, blend of organic and mechanical elements, futuristic, cybernetic, highly detailed, intricate details, extremely detailed, decorated with complex mecha",
"negative_prompt": "anime, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
},
{
"name": "线稿(复杂设计)",
"prompt": "(It is a pencil drawing work:1.3),structured patterns,meditative drawing,designs,focus and relaxation,creative doodling, pencil drawing, {prompt}, graphic design,Black and white line draft",
"negative_prompt": "Stereoscopic,colourful,detailed,realism,crayon,photography,graphite,impressionist,noisy,blurry,deformed,ugly"
},
{
"name": "线稿(简单设计)",
"prompt": "(It is a simple pencil drawing work:1.3),structured patterns,meditative drawing,Less details,simple design,focus and relaxation, creative, {prompt}, colourless, Black and white line draft",
"negative_prompt": "Stereoscopic,complex,detailed,realism,crayon,photography,impressionist,noisy,blurry,deformed,ugly"
},
{
"name": "复杂细节",
"prompt": "highly detailed, intricate details, extremely detailed, {prompt}, film, decorated with complex patterns and exquisite lines",
"negative_prompt": "anime, crayon, sketch, graphite, impressionist, noisy, blurry, deformed, ugly"
}
]