Bundle vocab fallback for random string node

This commit is contained in:
OnekoSL
2026-05-28 14:04:08 +02:00
parent c46dcae2be
commit bf5dfcd4d4
4 changed files with 28 additions and 5 deletions
+1
View File
@@ -3,6 +3,7 @@
## v0.3.0
- Added `Random Vocab String List (Nukun)` for deterministic random word-list prompt strings from `ComfyUI/user/vocab.json`.
- Added a bundled fallback vocabulary at `resources/vocab.json`.
- Added a browser-side rectangle editor for rectangular regional nodes.
- Added `Tiled HiRes Fix Advanced (Nukun)` for step-ranged tiled HiResFix workflows.
- Added expanded Universal Noise Sampler profiles and `Noise Profile Cycler (Nukun)`.
+1
View File
@@ -93,6 +93,7 @@ It exposes one integer widget with ComfyUI's control-after-generate support and
## Random Vocab String List
This node reads `ComfyUI/user/vocab.json` as a comma-separated plain-text word list and outputs a deterministic random space-separated string.
If the user file is missing, it falls back to the bundled `resources/vocab.json` word list included with this node pack.
Set `amount` for the number of words and use the `seed` widget's control-after-generate behavior to keep, increment, decrement, or randomize selections between queued runs.
Words are sampled without duplicates; if `amount` is larger than the available vocabulary, the output is clamped to the full list.
+25 -5
View File
@@ -9,11 +9,27 @@ def _vocab_path():
return os.path.join(folder_paths.get_user_directory(), "vocab.json")
def _load_words():
path = _vocab_path()
if not os.path.exists(path):
raise RuntimeError(f"Random Vocab String List: vocab file not found: {path}")
def _bundled_vocab_path():
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "resources", "vocab.json"))
def _resolve_vocab_path():
user_path = _vocab_path()
if os.path.exists(user_path):
return user_path
bundled_path = _bundled_vocab_path()
if os.path.exists(bundled_path):
return bundled_path
raise RuntimeError(
"Random Vocab String List: vocab file not found. Expected "
f"{user_path} or bundled fallback {bundled_path}"
)
def _load_words():
path = _resolve_vocab_path()
with open(path, "r", encoding="utf-8") as vocab_file:
text = vocab_file.read()
@@ -65,7 +81,11 @@ class NukunRandomVocabStringList:
@classmethod
def IS_CHANGED(cls, amount, seed):
path = _vocab_path()
try:
path = _resolve_vocab_path()
except RuntimeError:
path = ""
digest = hashlib.sha256()
digest.update(str(int(amount)).encode("utf-8"))
digest.update(str(int(seed)).encode("utf-8"))
File diff suppressed because one or more lines are too long