@@ -10,74 +10,18 @@ The `ComfyUI-to-Python-Extension` is a powerful tool that translates ComfyUI wor
10
10
** To this:**
11
11
12
12
```
13
- import os
14
13
import random
15
- import sys
16
- from typing import Sequence, Mapping, Any, Union
17
14
import torch
15
+ import sys
18
16
19
-
20
- def add_comfyui_directory_to_sys_path() -> None:
21
- """
22
- Recursively looks at parent folders starting from the current working directory until it finds 'ComfyUI'.
23
- Once found, the directory is added to sys.path.
24
- """
25
- start_path = os.getcwd() # Get the current working directory
26
-
27
- def search_directory(path: str) -> None:
28
- # Check if the current directory contains 'ComfyUI'
29
- if "ComfyUI" in os.listdir(path):
30
- directory_path = os.path.join(path, "ComfyUI")
31
- sys.path.append(directory_path)
32
- print(f"ComfyUI found and added to sys.path: {directory_path}")
33
-
34
- # Get the parent directory
35
- parent_directory = os.path.dirname(path)
36
-
37
- # If the parent directory is the same as the current directory, we've reached the root and stop the search
38
- if parent_directory == path:
39
- return
40
-
41
- # Recursively call the function with the parent directory
42
- search_directory(parent_directory)
43
-
44
- # Start the search from the current working directory
45
- search_directory(start_path)
46
-
47
-
48
- def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
49
- """Returns the value at the given index of a sequence or mapping.
50
-
51
- If the object is a sequence (like list or string), returns the value at the given index.
52
- If the object is a mapping (like a dictionary), returns the value at the index-th key.
53
-
54
- Some return a dictionary, in these cases, we look for the "results" key
55
-
56
- Args:
57
- obj (Union[Sequence, Mapping]): The object to retrieve the value from.
58
- index (int): The index of the value to retrieve.
59
-
60
- Returns:
61
- Any: The value at the given index.
62
-
63
- Raises:
64
- IndexError: If the index is out of bounds for the object and the object is not a mapping.
65
- """
66
- try:
67
- return obj[index]
68
- except KeyError:
69
- return obj["result"][index]
70
-
71
-
72
- add_comfyui_directory_to_sys_path()
17
+ sys.path.append("../")
73
18
from nodes import (
74
- CLIPTextEncode,
75
- KSamplerAdvanced,
76
- CheckpointLoaderSimple,
77
19
VAEDecode,
78
- SaveImage ,
20
+ KSamplerAdvanced ,
79
21
EmptyLatentImage,
80
- NODE_CLASS_MAPPINGS,
22
+ SaveImage,
23
+ CheckpointLoaderSimple,
24
+ CLIPTextEncode,
81
25
)
82
26
83
27
@@ -95,26 +39,25 @@ def main():
95
39
96
40
cliptextencode = CLIPTextEncode()
97
41
cliptextencode_6 = cliptextencode.encode(
98
- text="Kylo Ren trapped inside of a Mark Rothko painting ",
99
- clip=get_value_at_index( checkpointloadersimple_4, 1) ,
42
+ text="evening sunset scenery blue sky nature, glass bottle with a galaxy in it ",
43
+ clip=checkpointloadersimple_4[1] ,
100
44
)
101
45
102
46
cliptextencode_7 = cliptextencode.encode(
103
- text="text, watermark", clip=get_value_at_index( checkpointloadersimple_4, 1)
47
+ text="text, watermark", clip=checkpointloadersimple_4[1]
104
48
)
105
49
106
50
checkpointloadersimple_12 = checkpointloadersimple.load_checkpoint(
107
51
ckpt_name="sd_xl_refiner_1.0.safetensors"
108
52
)
109
53
110
54
cliptextencode_15 = cliptextencode.encode(
111
- text="Kylo Ren trapped inside of a Mark Rothko painting ",
112
- clip=get_value_at_index( checkpointloadersimple_12, 1) ,
55
+ text="evening sunset scenery blue sky nature, glass bottle with a galaxy in it ",
56
+ clip=checkpointloadersimple_12[1] ,
113
57
)
114
58
115
59
cliptextencode_16 = cliptextencode.encode(
116
- text="text, watermark",
117
- clip=get_value_at_index(checkpointloadersimple_12, 1),
60
+ text="text, watermark", clip=checkpointloadersimple_12[1]
118
61
)
119
62
120
63
ksampleradvanced = KSamplerAdvanced()
@@ -132,10 +75,10 @@ def main():
132
75
start_at_step=0,
133
76
end_at_step=20,
134
77
return_with_leftover_noise="enable",
135
- model=get_value_at_index( checkpointloadersimple_4, 0) ,
136
- positive=get_value_at_index( cliptextencode_6, 0) ,
137
- negative=get_value_at_index( cliptextencode_7, 0) ,
138
- latent_image=get_value_at_index( emptylatentimage_5, 0) ,
78
+ model=checkpointloadersimple_4[0] ,
79
+ positive=cliptextencode_6[0] ,
80
+ negative=cliptextencode_7[0] ,
81
+ latent_image=emptylatentimage_5[0] ,
139
82
)
140
83
141
84
ksampleradvanced_11 = ksampleradvanced.sample(
@@ -148,19 +91,18 @@ def main():
148
91
start_at_step=20,
149
92
end_at_step=10000,
150
93
return_with_leftover_noise="disable",
151
- model=get_value_at_index( checkpointloadersimple_12, 0) ,
152
- positive=get_value_at_index( cliptextencode_15, 0) ,
153
- negative=get_value_at_index( cliptextencode_16, 0) ,
154
- latent_image=get_value_at_index( ksampleradvanced_10, 0) ,
94
+ model=checkpointloadersimple_12[0] ,
95
+ positive=cliptextencode_15[0] ,
96
+ negative=cliptextencode_16[0] ,
97
+ latent_image=ksampleradvanced_10[0] ,
155
98
)
156
99
157
100
vaedecode_17 = vaedecode.decode(
158
- samples=get_value_at_index(ksampleradvanced_11, 0),
159
- vae=get_value_at_index(checkpointloadersimple_12, 2),
101
+ samples=ksampleradvanced_11[0], vae=checkpointloadersimple_12[2]
160
102
)
161
103
162
104
saveimage_19 = saveimage.save_images(
163
- filename_prefix="ComfyUI", images=get_value_at_index( vaedecode_17, 0)
105
+ filename_prefix="ComfyUI", images=vaedecode_17[0]
164
106
)
165
107
166
108
0 commit comments