1010
1111from typing import Dict , List , Any , Callable , Tuple
1212
13- from utils import import_custom_nodes , add_comfyui_directories_to_sys_path
13+ from utils import import_custom_nodes , add_comfyui_directory_to_sys_path , get_value_at_index
1414
1515
1616sys .path .append ('../' )
@@ -218,7 +218,7 @@ def generate_workflow(self, load_order: List, filename: str = 'generated_code_wo
218218 continue
219219
220220 class_type , import_statement , class_code = self .get_class_info (class_type )
221- initialized_objects [class_type ] = class_type .lower ()
221+ initialized_objects [class_type ] = class_type .lower (). strip ()
222222 if class_type in self .base_node_class_mappings .keys ():
223223 import_statements .add (import_statement )
224224 if class_type not in self .base_node_class_mappings .keys ():
@@ -232,7 +232,7 @@ def generate_workflow(self, load_order: List, filename: str = 'generated_code_wo
232232 inputs = {key : value for key , value in inputs .items () if key in class_def_params }
233233
234234 # Create executed variable and generate code
235- executed_variables [idx ] = f'{ class_type .lower ()} _{ idx } '
235+ executed_variables [idx ] = f'{ class_type .lower (). strip () } _{ idx } '
236236 inputs = self .update_inputs (inputs , executed_variables )
237237
238238 if is_special_function :
@@ -302,14 +302,16 @@ def assemble_python_code(self, import_statements: set, speical_functions_code: L
302302 Returns:
303303 str: Generated final code as a string.
304304 """
305- # Get the source code of the function as a string
306- add_comfyui_directories_to_sys_path_code = inspect .getsource (add_comfyui_directories_to_sys_path )
305+ # Get the source code of the utils functions as a string
306+ func_strings = []
307+ for func in [add_comfyui_directory_to_sys_path , get_value_at_index ]:
308+ func_strings .append (f'\n { inspect .getsource (func )} ' )
307309 # Define static import statements required for the script
308- static_imports = ['import os' , 'import random' , 'import sys' , 'import torch' , f' \n { add_comfyui_directories_to_sys_path_code } ' ,
309- ' \n \n add_comfyui_directories_to_sys_path ()' ]
310+ static_imports = ['import os' , 'import random' , 'import sys' , 'from typing import Sequence, Mapping, Any, Union ' ,
311+ 'import torch' ] + func_strings + [ ' \n \n add_comfyui_directory_to_sys_path ()' ]
310312 # Check if custom nodes should be included
311313 if custom_nodes :
312- static_imports .append (' \n from utils import import_custom_nodes, get_value_at_index \n ' )
314+ static_imports .append (f' \n { inspect . getsource ( import_custom_nodes ) } \n ' )
313315 custom_nodes = 'import_custom_nodes()\n \t '
314316 else :
315317 custom_nodes = ''
@@ -336,9 +338,9 @@ def get_class_info(self, class_type: str) -> Tuple[str, str, str]:
336338 """
337339 import_statement = class_type
338340 if class_type in self .base_node_class_mappings .keys ():
339- class_code = f'{ class_type .lower ()} = { class_type } ()'
341+ class_code = f'{ class_type .lower (). strip () } = { class_type . strip () } ()'
340342 else :
341- class_code = f'{ class_type .lower ()} = NODE_CLASS_MAPPINGS["{ class_type } "]()'
343+ class_code = f'{ class_type .lower (). strip () } = NODE_CLASS_MAPPINGS["{ class_type } "]()'
342344
343345 return class_type , import_statement , class_code
344346
0 commit comments