Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serve workflow templates from custom_nodes #6193

Merged

Conversation

bezo97
Copy link
Contributor

@bezo97 bezo97 commented Dec 23, 2024

This PR prepares the following feature request: Comfy-Org/ComfyUI_frontend#1008
Related frontend PR: Comfy-Org/ComfyUI_frontend#2032

Implementation details:

  • @routes.get("/workflow_templates") - This endpoint returns a map of custom_nodes names and their associated workflow template files. The ones without templates are omitted. Example:
{
    "ComfyUI-LTXTricks": [
        "example_ltxv_stg",
        "example_ltx_flow_edit",
        "example_ltx_interpolation",
        "example_ltx_inversion",
        "example_ltx_iv2v",
        "example_ltx_rf_edit"
    ],
    "ComfyUI_Noise": [
        "unsample_example",
        "variations_example"
    ]
}
  • LOADED_MODULE_DIRS where we keep track of all successfully loaded custom_nodes and their directories (even when there is no class mapping and web directory)
  • files are served from each custom_nodes's specific subfolder if exists, like this: custom_nodes/*/example_workflows/*

Question to reviewers:

  • Is serving from the /example_workflows folders sufficient or shall we support existing folder structures of popular custom_node repos by allowing /examples, /workflows, etc.?

server.py Outdated
@@ -250,6 +250,16 @@ async def get_extensions(request):
name) + "/" + os.path.relpath(f, dir).replace("\\", "/"), files)))

return web.json_response(extensions)

@routes.get("/workflow_templates")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have a plan to eventually move ComfyUI-Manager's custom node management features to core. Can we move this endpoint to a separate file app/custom_node_manager.py?

server.py Outdated

@routes.get("/workflow_templates")
async def get_workflow_templates(request):
files = glob.glob(os.path.join(folder_paths.custom_nodes_directory, '*/example_workflows/*.json'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just call folder_paths.get_folder_paths("custom_nodes") here instead of adding a new global variable in folder_paths.

huchenlei
huchenlei previously approved these changes Dec 26, 2024
Copy link
Collaborator

@huchenlei huchenlei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit.

folder_paths.py Outdated
temp_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "temp")
input_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "input")
user_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "user")
output_directory = os.path.join(base_path, "output")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think these changes are related to this PR although they seem to be good.

Let's revert them for now so that we are sure that this PR does not break anything related.

huchenlei
huchenlei previously approved these changes Dec 26, 2024
Copy link
Collaborator

@huchenlei huchenlei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit.

@huchenlei huchenlei added Good PR This PR looks good to go, it needs comfy's final review. Important labels Dec 27, 2024
@huchenlei
Copy link
Collaborator

Note: test failure is due to python 3.8, which is fixed in 160ca08

@bezo97 Can you rebase the PR?

@comfyanonymous PTAL

@routes.get("/workflow_templates")
async def get_workflow_templates(request):
"""Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted."""
files = glob.glob(os.path.join(folder_paths.get_folder_paths("custom_nodes")[0], '*/example_workflows/*.json'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only seems to take into account the first custom node path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry didn't realize the logic that there could be more, fixed now

@comfyanonymous comfyanonymous merged commit 96697c4 into comfyanonymous:master Dec 28, 2024
@bezo97 bezo97 deleted the feature/custom_workflow_templates branch December 28, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good PR This PR looks good to go, it needs comfy's final review. Important
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants