diff --git a/__init__.py b/__init__.py index e69de29..80bf072 100644 --- a/__init__.py +++ b/__init__.py @@ -0,0 +1 @@ +from .nodes import * \ No newline at end of file diff --git a/nodes.py b/nodes.py index e69de29..a71f3e1 100644 --- a/nodes.py +++ b/nodes.py @@ -0,0 +1,66 @@ +import os +import folder_paths + +# --- Get Text Files --- +# 1. Get the ComfyUI 'input' directory +input_dir = folder_paths.get_input_directory() + +# 2. Find all .txt files in that directory +# We os.path.isfile to make sure we don't grab directories +text_files = [ + f for f in os.listdir(input_dir) + if os.path.isfile(os.path.join(input_dir, f)) and f.endswith(".txt") +] + +# --- The Node Class --- +class LoadTextFile: + """ + A node that loads text from a file in the ComfyUI/input/ directory. + """ + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + # This creates the dropdown widget with our file list + "file_name": (text_files, ) + } + } + + # What the node will output + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) # Optional, but good practice + + # The function that runs when the node is executed + FUNCTION = "load_text" + + # The category in the right-click menu + CATEGORY = "Rathius_ComfyNodes/Utils" + + def load_text(self, file_name): + # Get the full path to the file + file_path = os.path.join(input_dir, file_name) + + try: + # Open and read the file + with open(file_path, 'r', encoding='utf-8') as f: + text_content = f.read() + + # Nodes must return their outputs as a tuple + return (text_content, ) + + except Exception as e: + print(f"[LoadTextFile] Error: {e}") + # Return the error as a string so you can see it in ComfyUI + return (f"Error loading file: {e}", ) + +# --- Node Registration --- +# This tells ComfyUI about our new node +NODE_CLASS_MAPPINGS = { + "LoadTextFile_Rathius": LoadTextFile +} + +# This sets the name that appears in the Add Node menu +NODE_DISPLAY_NAME_MAPPINGS = { + "LoadTextFile_Rathius": "Load Text from File" +} \ No newline at end of file diff --git a/samples/negative_sample.txt b/samples/negative_sample.txt new file mode 100644 index 0000000..e772e90 --- /dev/null +++ b/samples/negative_sample.txt @@ -0,0 +1 @@ +worst quality, low quality, blurry, jpeg artifacts, text, watermark, signature, (boring:1.3), dark, gloomy \ No newline at end of file diff --git a/samples/positive_sample.txt b/samples/positive_sample.txt new file mode 100644 index 0000000..ecd15f5 --- /dev/null +++ b/samples/positive_sample.txt @@ -0,0 +1 @@ +masterpiece, best quality, beautiful painting of a cozy room, bright sunlight streaming through a window, a black cat with bright blue eyes, steam rising from a coffee cup \ No newline at end of file