-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_a_node.py
59 lines (53 loc) · 1.49 KB
/
add_a_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: MIT
#
# The Comfy Catapult project requires contributions made to this file be licensed
# under the MIT license or a compatible open source license. See LICENSE.md for
# the license text.
# SNIPPETSTART
from pathlib import Path
from comfy_catapult.comfy_schema import (APIWorkflow, APIWorkflowNodeInfo,
APIWorkflowNodeMeta)
from comfy_catapult.comfy_utils import GenerateNewNodeID
api_workflow_json_str: str = """
{
"1": {
"inputs": {
"image": "{remote_image_path} [input]",
"upload": "image"
},
"class_type": "LoadImage",
"_meta": {
"title": "My Loader Title"
}
},
"25": {
"inputs": {
"images": [
"8",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
}
}
"""
api_workflow: APIWorkflow = APIWorkflow.model_validate_json(
api_workflow_json_str)
path_to_comfy_input = Path('/path/to/ComfyUI/input')
path_to_image = path_to_comfy_input / 'image.jpg'
rel_path_to_image = path_to_image.relative_to(path_to_comfy_input)
# Add a new LoadImage node to the workflow.
new_node_id = GenerateNewNodeID(workflow=api_workflow)
api_workflow.root[new_node_id] = APIWorkflowNodeInfo(
inputs={
'image': f'{rel_path_to_image} [input]',
'upload': 'image',
},
class_type='LoadImage',
_meta=APIWorkflowNodeMeta(title='My Loader Title'))
print(api_workflow.model_dump_json())
# SNIPPETEND