chatgpt wrote me a custom node do you rike it, haven't checked it for errors because i go to work now
import comfy.model_management as model_management
import comfy.sd_nodes as sd_nodes
import re
import os
# Function to read and clean contents from file within `{}` braces
def extract_and_clean_brace_content_from_file(file_path):
if not os.path.isfile(file_path):
print(f"File not found: {file_path}")
return []
with open(file_path, 'r') as f:
prompt_text = f.read()
brace_contents = re.findall(r"\{(.*?)\}", prompt_text)
cleaned_contents = [
re.sub(r'\s+', ' ', content.replace('\t', '')).strip()
for content in brace_contents
]
return cleaned_contents
class BraceIndexedFile(sd_nodes.Node):
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"file_name": ("FILENAME", {"default": "", "filter": "*.txt", "root": "input"}),
"index": ("INT", {"default": 0, "min": 0}),
}
}
RETURN_TYPES = ("STRING",)
FUNCTION = "get_brace_content_from_file"
CATEGORY = "Custom Nodes"
def get_brace_content_from_file(self, file_name, index):
file_path = os.path.join("input", file_name)
brace_contents = extract_and_clean_brace_content_from_file(file_path)
if index < 0 or index >= len(brace_contents):
return ("",)
return (brace_contents[index],)
def get_node():
return BraceIndexedFile
model_management.register_custom_node(get_node(), "Custom Nodes")