80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
# ======================================================================
|
|
# Node Pack: artyclaw-comfy
|
|
# Author: artyclaw
|
|
# Version: 1.0.0
|
|
# Description: A power-user toolkit for prompt logic, IO, and RNG.
|
|
# ======================================================================
|
|
|
|
import os
|
|
|
|
NODE_NAME = "LoadSidecarPrompt"
|
|
|
|
class LoadSidecarPrompt:
|
|
"""
|
|
Load sidecar .txt files for a list of image filenames.
|
|
|
|
Input:
|
|
- filenames (LIST of STRING): e.g. ["img001.png", "img002.jpg"]
|
|
|
|
Behavior:
|
|
For each filename:
|
|
- look for same basename with ".txt"
|
|
- if exists: return content
|
|
- else: return ""
|
|
|
|
Output:
|
|
- prompt_texts (LIST of STRING)
|
|
"""
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(s):
|
|
return {
|
|
"required": {
|
|
"filenames": ("STRING", {"multiline": True, "forceInput": True})
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING",)
|
|
RETURN_NAMES = ("prompt_texts",)
|
|
OUTPUT_IS_LIST = (True,) # IMPORTANT: tells Comfy this output is a list
|
|
FUNCTION = "load_prompts"
|
|
CATEGORY = "text/utils"
|
|
|
|
def load_prompts(self, filenames):
|
|
"""
|
|
`filenames` will be a python list of strings.
|
|
"""
|
|
prompts = []
|
|
|
|
# Ensure it's iterable (Comfy may pass a single string if not list-wired)
|
|
if not isinstance(filenames, list):
|
|
filenames = [filenames]
|
|
|
|
for fn in filenames:
|
|
if not fn:
|
|
prompts.append("")
|
|
continue
|
|
|
|
base, _ = os.path.splitext(fn)
|
|
txt_path = base + ".txt"
|
|
|
|
if os.path.isfile(txt_path):
|
|
try:
|
|
with open(txt_path, "r", encoding="utf-8") as f:
|
|
prompts.append(f.read())
|
|
except Exception:
|
|
prompts.append("")
|
|
else:
|
|
prompts.append("")
|
|
|
|
return (prompts,)
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
"LoadSidecarPrompt": LoadSidecarPrompt
|
|
}
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"LoadSidecarPrompt": "Load Sidecar Prompt (.txt) – List"
|
|
}
|