File size: 1,014 Bytes
1e3b872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
def trace_inputs(node, workflow, path=None, tags=None):
    if tags is None:
        tags = []

    class_type = node["class_type"]
    inputs = node["inputs"]

    # 添加类类型到路径中
    if path is None:
        path = [class_type]
    else:
        path.append(class_type)

    for key, value in inputs.items():
        new_path = path + [key]
        if isinstance(value, list):
            ref_id, _ = value
            ref_node = workflow[str(ref_id)]
            trace_inputs(ref_node, workflow, new_path, tags)
        else:
            tag = f"{'->'.join(new_path[-4:])}::{value}"
            tags.append(tag)

    return tags


def parse_workflow(workflow):
    # TODO: only parse from eagle node!!!
    image_nodes = [
        node for node in workflow.values() if node["class_type"] == "PreviewImage"
    ]
    image_node = image_nodes[0]
    tags = trace_inputs(image_node, workflow)
    print("Image Node Tags:")
    tags = list(set(tags))
    tags.sort()
    # // raw info
    return tags