CoolFace
Apppublic

nef7/my-comfyui-workflow

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
custom_node_manager.py35 linesDownload Raw Back to app
1from __future__ import annotations2 3import os4import folder_paths5import glob6from aiohttp import web7 8class CustomNodeManager:9    """10    Placeholder to refactor the custom node management features from ComfyUI-Manager.11    Currently it only contains the custom workflow templates feature.12    """13    def add_routes(self, routes, webapp, loadedModules):14 15        @routes.get("/workflow_templates")16        async def get_workflow_templates(request):17            """Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted."""18            files = [19                file20                for folder in folder_paths.get_folder_paths("custom_nodes")21                for file in glob.glob(os.path.join(folder, '*/example_workflows/*.json'))22            ]23            workflow_templates_dict = {} # custom_nodes folder name -> example workflow names24            for file in files:25                custom_nodes_name = os.path.basename(os.path.dirname(os.path.dirname(file)))26                workflow_name = os.path.splitext(os.path.basename(file))[0]27                workflow_templates_dict.setdefault(custom_nodes_name, []).append(workflow_name)28            return web.json_response(workflow_templates_dict)29 30        # Serve workflow templates from custom nodes.31        for module_name, module_dir in loadedModules:32            workflows_dir = os.path.join(module_dir, 'example_workflows')33            if os.path.exists(workflows_dir):34                webapp.add_routes([web.static('/api/workflow_templates/' + module_name, workflows_dir)])35