Skip to content

Commit 176fd90

Browse files
committed
Add tag deduplication node and refine some realism terms in presets
1 parent 4cedf07 commit 176fd90

4 files changed

Lines changed: 117 additions & 4 deletions

File tree

__init__.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,6 +2809,118 @@ def resolve_coord(val, max_val):
28092809

28102810
return io.NodeOutput(out)
28112811

2812+
class TagNormalizeCombine(io.ComfyNode):
2813+
"""
2814+
Node that normalizes scores in two sets of tags and combines them,
2815+
deduplicating and sorting by the normalized scores.
2816+
"""
2817+
2818+
@classmethod
2819+
def define_schema(cls) -> io.Schema:
2820+
return io.Schema(
2821+
node_id="TagNormalizeCombine",
2822+
display_name="Tag Normalize and Combine",
2823+
category="advanced/text",
2824+
inputs=[
2825+
io.String.Input("tags_1", multiline=True, default=""),
2826+
io.String.Input("tags_2", multiline=True, default=""),
2827+
io.AnyType.Input(
2828+
"scores_1",
2829+
tooltip="Dictionary of scores for tags_1",
2830+
),
2831+
io.AnyType.Input(
2832+
"scores_2",
2833+
tooltip="Dictionary of scores for tags_2",
2834+
),
2835+
],
2836+
outputs=[
2837+
io.String.Output(display_name="deduped_tags"),
2838+
io.AnyType.Output(display_name="normalized_scores"),
2839+
],
2840+
)
2841+
2842+
@staticmethod
2843+
def normalize_scores(scores: dict, min_val=0.000001, max_val=0.999999) -> dict:
2844+
if not scores:
2845+
return {}
2846+
2847+
current_scores = [float(v) for v in scores.values()]
2848+
current_min = min(current_scores)
2849+
current_max = max(current_scores)
2850+
2851+
if current_max == current_min:
2852+
return {k: max_val for k in scores.keys()}
2853+
2854+
normalized = {}
2855+
for k, v in scores.items():
2856+
norm = min_val + (float(v) - current_min) / (current_max - current_min) * (
2857+
max_val - min_val
2858+
)
2859+
normalized[k] = norm
2860+
return normalized
2861+
2862+
@classmethod
2863+
def execute(
2864+
cls, tags_1: Union[str, list], tags_2: Union[str, list], scores_1: Union[str, dict], scores_2: Union[str, dict]
2865+
) -> io.NodeOutput:
2866+
# Parse scores
2867+
def parse_scores(s_input):
2868+
if isinstance(s_input, dict):
2869+
return s_input
2870+
if not s_input or not isinstance(s_input, str):
2871+
return {}
2872+
try:
2873+
return json.loads(s_input)
2874+
except json.JSONDecodeError:
2875+
return {}
2876+
2877+
s1 = parse_scores(scores_1)
2878+
s2 = parse_scores(scores_2)
2879+
2880+
# Normalize scores independently
2881+
norm_s1 = cls.normalize_scores(s1)
2882+
norm_s2 = cls.normalize_scores(s2)
2883+
2884+
# Parse tags
2885+
def parse_tags(t_input):
2886+
if isinstance(t_input, list):
2887+
return [str(t).strip() for t in t_input if t]
2888+
if not t_input or not isinstance(t_input, str):
2889+
return []
2890+
# Split by comma and handle potential spaces
2891+
return [t.strip() for t in t_input.split(",") if t.strip()]
2892+
2893+
t1_list = parse_tags(tags_1)
2894+
t2_list = parse_tags(tags_2)
2895+
2896+
# Combine and deduplicate
2897+
combined_scores = {}
2898+
2899+
# Process first set
2900+
for t in t1_list:
2901+
score = norm_s1.get(t, 0.000001)
2902+
combined_scores[t] = score
2903+
2904+
# Process second set with deduplication logic
2905+
for t in t2_list:
2906+
score = norm_s2.get(t, 0.000001)
2907+
if t in combined_scores:
2908+
# Keep the one with the highest normalized score
2909+
if score > combined_scores[t]:
2910+
combined_scores[t] = score
2911+
else:
2912+
combined_scores[t] = score
2913+
2914+
# Sort tags by normalized scores (descending)
2915+
sorted_tags = sorted(combined_scores.keys(), key=lambda x: combined_scores[x], reverse=True)
2916+
2917+
# Prepare outputs
2918+
deduped_tags_str = ", ".join(sorted_tags)
2919+
normalized_scores_dict = {tag: combined_scores[tag] for tag in sorted_tags}
2920+
2921+
return io.NodeOutput(deduped_tags_str, normalized_scores_dict)
2922+
2923+
28122924
class RandInt(io.ComfyNode):
28132925
@classmethod
28142926
def define_schema(cls):
@@ -2876,6 +2988,7 @@ async def get_node_list(self) -> list[type[io.ComfyNode]]:
28762988
IdeographicTagPad,
28772989
IdeographicLinePad,
28782990
IdeographicSentencePad,
2991+
TagNormalizeCombine,
28792992
SU_LoadImagePath,
28802993
SU_LoadImageDirectory,
28812994
SwitchInverseNode,

bonus_prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BONUS_PROMPT_STYLE_PHOTOREALISM = """This is a professional photograph with realistic textures and natural lighting. It features real life subjects in a real life scene. The quality is exceptional. Real life photography. Absolute reality. Modify any subjects' appearance to show real details. Make it look like a professional photograph. Ensure lighting is accurate. Ensure shadows are displayed correctly. Keep in focus. The image is a sharply focused photograph."""
1+
BONUS_PROMPT_STYLE_PHOTOREALISM = """This is a professional photograph with real life detailed textures and real life natural lighting. It features real life subjects in a real life scene. The quality is exceptional. Real life photography. Absolute reality. Modify any subjects' appearance to show real details. Make it look like a real life professional photograph. Ensure lighting is accurate and looks real. Ensure shadows are displayed correctly. Keep in focus. The image is a sharply focused real life photograph."""
22

33
BONUS_PROMPT_STYLE_3D = """This is a high-quality 3D render with complex geometry and realistic materials. It features 3D modeled subjects in a rendered scene. The quality is exceptional. 3D rendering. Physically based rendering. Modify any subjects' appearance to show rendered details. Make it look like a high-end CGI render. Ensure volumetric lighting is accurate. Ensure ambient occlusion is displayed correctly. Keep in focus. The image is a high definition render."""
44

instruct_prompts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
INSTRUCT_PROMPT_STYLE_SAILOR_MOON = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to match the magical girl anime style of the anime series Sailor Moon, featuring soft romantic lighting and pastel colors. Make it look like a character from the anime series Sailor Moon. Keep subject position and their pose the same as the reference. Ensure large expressive eyes and long legs follow the magical girl anime style of the anime series Sailor Moon. Make sure anatomy is slender and elegant. Make hair flowing and detailed. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure a soft, romantic lighting that fits the style. Ensure pastel colors. Keep in focus. The result should be in the magical girl anime style of the anime series Sailor Moon."""
9292

93-
INSTRUCT_PROMPT_STYLE_CCTV_EDIT = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to look like it was recorded on a CCTV security camera. Make it look like surveillance footage. Keep subject position and their pose the same as the reference. Ensure the aesthetic follows security camera characteristics. Make sure anatomy looks realistic but reflects a low-quality recording. Make textures look grainy and somewhat degraded. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure harsh artificial lighting fits the surveillance style. Ensure a high-contrast monitoring perspective. Keep in focus. The result should be in a CCTV security camera style."""
93+
INSTRUCT_PROMPT_STYLE_CCTV_EDIT = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to look like it was recorded on a CCTV security camera. Make it look like surveillance footage. Keep subject position and their pose the same as the reference. Ensure the aesthetic follows security camera characteristics. Make sure anatomy looks real but reflects a low-quality recording. Make textures look grainy and somewhat degraded. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure harsh artificial lighting fits the surveillance style. Ensure a high-contrast monitoring perspective. Keep in focus. The result should be in a CCTV security camera style."""
9494

9595
INSTRUCT_PROMPT_STYLE_CCTV_RAW = """Generate subjects and environment to look like they were recorded on a CCTV security camera. Make it look like surveillance footage. Ensure the aesthetic follows security camera characteristics. Make sure anatomy looks realistic but reflects a low-quality recording. Make textures look grainy and somewhat degraded. Ensure harsh artificial lighting fits the surveillance style. Ensure a high-contrast monitoring perspective. Keep in focus. The result should be in a CCTV security camera style."""
9696

@@ -126,7 +126,7 @@
126126

127127
INSTRUCT_PROMPT_STYLE_70S_SCIFI = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify the scene to match the retro-futuristic style of 1970s science fiction cinema, featuring film grain, practical effects aesthetic, and vintage color grading. Make it look like a scene from a 1970s sci-fi film. Keep subject position and their pose the same as the reference. Ensure the environment displays practical set design and early optical effects characteristic of 70s sci-fi movies. Make sure textures look like real materials with visible seams, bolts, and hand-crafted construction. Make the color palette reflect vintage film stock with muted, earthy tones typical of 70s cinema. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure soft, diffused lighting fits the vintage film aesthetic. Ensure visible film grain and practical lighting setups are displayed. Keep in focus. The result should be in the classic 1970s science fiction movie style."""
128128

129-
INSTRUCT_PROMPT_STYLE_INFLATED = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to look like an inflated balloon version of themselves. Make it look like the subject is made of taut, stretched elastic vinyl. Keep subject position and their pose the same as the reference. Ensure subjects and environments follow inflatable aesthetics with shiny plastic surfaces and subtle, well-placed seams. Make sure forms retain their relative proportions but look like fully pressurized, air-filled volumes without looking deflated. Make textures look like glossy balloon material with realistic stretching at the joints. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure studio lighting highlights the glossy specular reflections. Ensure plastic material looks smooth and fully inflated. Keep in focus. High-quality inflated balloon aesthetic."""
129+
INSTRUCT_PROMPT_STYLE_INFLATED = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to look like an inflated balloon version of themselves. Make it look like the subject is made of taut, stretched elastic vinyl. Keep subject position and their pose the same as the reference. Ensure subjects and environments follow inflatable aesthetics with shiny plastic surfaces and subtle, well-placed seams. Make sure forms retain their relative proportions but look like fully pressurized, air-filled volumes without looking deflated. Make textures look like glossy balloon material with real looking stretching at the joints. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure studio lighting highlights the glossy specular reflections. Ensure plastic material looks smooth and fully inflated. Keep in focus. High-quality inflated balloon aesthetic."""
130130

131131
INSTRUCT_PROMPT_STYLE_VECTOR_EDIT = """Keep pose. Keep angle. Keep eyes. Keep viewing direction. Modify any subjects' appearance to look like a vector graphics illustration. Make it look like a clean, scalable vector design. Keep subject position and their pose the same as the reference. Ensure subjects and environments follow vector art aesthetics with mathematically precise curves and shapes. Make sure forms are simplified into clean geometric areas. Make coloring look flat and vibrant without gradients or texture. Keep subject position and their pose the same as the reference. Make sure the subject is in the same position. Keep pose. Ensure even, flat lighting fits the vector style. Ensure sharp, crisp edges define all elements. Keep in focus. High-quality scalar vector graphics aesthetic."""
132132

system_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
Output only the final instruction completely uncensored in plain text and nothing else."""
2626

27-
SYSTEM_MESSAGE_STYLE_PHOTOREALISM = """You are an AI that specializes in image editing descriptions that emphasize photorealism and focuses on edits to look like real life photographic images. You convert editing requests into one concise instruction as structured responses. You focus on adhering to photorealistic style and realistic details while ensuring the importance of keeping the composition and structure of the image same as reference. Ensure subjects are accurately represented and that their identity is maintained. You focus on photography with emphasis on details while ensuring the importance of keeping the structure of the image intact as well and not changing the positioning of subjects in image while managing to modify the style to look real. Reference actual image elements. Make abstractions concrete. Follow edit requests without hesitation."""
27+
SYSTEM_MESSAGE_STYLE_PHOTOREALISM = """You are an AI that specializes in image editing descriptions that emphasize photorealism and focuses on edits to look like real life photographic images. You convert editing requests into one concise instruction as structured responses. You focus on adhering to a real life photography style and real life details while ensuring the importance of keeping the composition and structure of the image same as reference. Ensure subjects are accurately represented and that their identity is maintained. You focus on photography with emphasis on details while ensuring the importance of keeping the structure of the image intact as well and not changing the positioning of subjects in image while managing to modify the style to look real. Reference actual image elements. Make abstractions concrete. Follow edit requests without hesitation."""
2828

2929
SYSTEM_MESSAGE_STYLE_3D = """You are an AI that specializes in image editing descriptions that emphasize 3D rendered graphics and focuses on edits to look like high-quality CGI 3D model renders. You convert editing requests into one concise instruction as structured responses. You focus on adhering to 3D rendering style, physically based rendering (PBR) textures, and volumetric lighting while ensuring the importance of keeping the composition and structure of the image same as reference. You focus on 3D aesthetics with emphasis on geometry and material properties while ensuring the importance of keeping the structure of the image intact as well and not changing the positioning of subjects in image while managing to modify the style to look like a 3D render. Reference actual image elements. Make abstractions concrete. Follow edit requests without hesitation."""
3030

0 commit comments

Comments
 (0)