From 9efdda21a8113d151f601e5357c9f06785d251b1 Mon Sep 17 00:00:00 2001 From: Barry Downes Date: Sun, 6 Aug 2023 08:47:19 +1000 Subject: [PATCH] Combine the comments and choices into a single function to ease integration into various nodes. --- comfy/choices.py | 7 +++++++ nodes.py | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/comfy/choices.py b/comfy/choices.py index fe9e085ff..923bd0680 100644 --- a/comfy/choices.py +++ b/comfy/choices.py @@ -6,6 +6,13 @@ import random import comfy.parse as parse from comfy.parse import ParseError, ParseLogicError +from comfy.comments import strip_c_comments + +def translate_choices_with_c_comments(text, seed=None, strict=True, reescape=frozenset()): + text = strip_c_comments(text, strict=strict) + text = translate(text, seed=seed, strict=strict, reescape = reescape) + return text + def get_random_seed(): return int.from_bytes(os.urandom(8)) diff --git a/nodes.py b/nodes.py index 58e85bcee..44bbef459 100644 --- a/nodes.py +++ b/nodes.py @@ -15,7 +15,6 @@ import numpy as np import safetensors.torch import comfy.choices -import comfy.comments sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy")) @@ -1482,8 +1481,7 @@ class DynamicPrompt: CATEGORY = "conditioning" def dynamic_prompt(self, text, seed): - text = comfy.comments.strip_c_comments(text) - text = comfy.choices.translate(text, seed=seed, strict=False, reescape=r'\()') + text = comfy.choices.translate_choices_with_c_comments(text, seed=seed, strict=False, reescape=r'\()') return (text,)