Crockrocks12 commited on
Commit
a939cd7
·
verified ·
1 Parent(s): c3227a6

Delete supirworkflow_api.py

Browse files
Files changed (1) hide show
  1. supirworkflow_api.py +0 -229
supirworkflow_api.py DELETED
@@ -1,229 +0,0 @@
1
- import os
2
- import random
3
- import sys
4
- from typing import Sequence, Mapping, Any, Union
5
- import torch
6
-
7
-
8
- def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
9
- """Returns the value at the given index of a sequence or mapping.
10
-
11
- If the object is a sequence (like list or string), returns the value at the given index.
12
- If the object is a mapping (like a dictionary), returns the value at the index-th key.
13
-
14
- Some return a dictionary, in these cases, we look for the "results" key
15
-
16
- Args:
17
- obj (Union[Sequence, Mapping]): The object to retrieve the value from.
18
- index (int): The index of the value to retrieve.
19
-
20
- Returns:
21
- Any: The value at the given index.
22
-
23
- Raises:
24
- IndexError: If the index is out of bounds for the object and the object is not a mapping.
25
- """
26
- try:
27
- return obj[index]
28
- except KeyError:
29
- return obj["result"][index]
30
-
31
-
32
- def find_path(name: str, path: str = None) -> str:
33
- """
34
- Recursively looks at parent folders starting from the given path until it finds the given name.
35
- Returns the path as a Path object if found, or None otherwise.
36
- """
37
- # If no path is given, use the current working directory
38
- if path is None:
39
- path = os.getcwd()
40
-
41
- # Check if the current directory contains the name
42
- if name in os.listdir(path):
43
- path_name = os.path.join(path, name)
44
- print(f"{name} found: {path_name}")
45
- return path_name
46
-
47
- # Get the parent directory
48
- parent_directory = os.path.dirname(path)
49
-
50
- # If the parent directory is the same as the current directory, we've reached the root and stop the search
51
- if parent_directory == path:
52
- return None
53
-
54
- # Recursively call the function with the parent directory
55
- return find_path(name, parent_directory)
56
-
57
-
58
- def add_comfyui_directory_to_sys_path() -> None:
59
- """
60
- Add 'ComfyUI' to the sys.path
61
- """
62
- comfyui_path = find_path("ComfyUI")
63
- if comfyui_path is not None and os.path.isdir(comfyui_path):
64
- sys.path.append(comfyui_path)
65
- print(f"'{comfyui_path}' added to sys.path")
66
-
67
-
68
- def add_extra_model_paths() -> None:
69
- """
70
- Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
71
- """
72
- from main import load_extra_path_config
73
-
74
- extra_model_paths = find_path("extra_model_paths.yaml")
75
-
76
- if extra_model_paths is not None:
77
- load_extra_path_config(extra_model_paths)
78
- else:
79
- print("Could not find the extra_model_paths config file.")
80
-
81
-
82
- add_comfyui_directory_to_sys_path()
83
- add_extra_model_paths()
84
-
85
-
86
- def import_custom_nodes() -> None:
87
- """Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
88
-
89
- This function sets up a new asyncio event loop, initializes the PromptServer,
90
- creates a PromptQueue, and initializes the custom nodes.
91
- """
92
- import asyncio
93
- import execution
94
- from nodes import init_custom_nodes
95
- import server
96
-
97
- # Creating a new event loop and setting it as the default loop
98
- loop = asyncio.new_event_loop()
99
- asyncio.set_event_loop(loop)
100
-
101
- # Creating an instance of PromptServer with the loop
102
- server_instance = server.PromptServer(loop)
103
- execution.PromptQueue(server_instance)
104
-
105
- # Initializing custom nodes
106
- init_custom_nodes()
107
-
108
-
109
- from nodes import SaveImage, NODE_CLASS_MAPPINGS, LoadImage
110
-
111
-
112
- def main():
113
- import_custom_nodes()
114
- with torch.inference_mode():
115
- loadimage = LoadImage()
116
- loadimage_13 = loadimage.load_image(image="tree-736885_640.jpg")
117
-
118
- supir_model_loader = NODE_CLASS_MAPPINGS["SUPIR_model_loader"]()
119
- supir_model_loader_58 = supir_model_loader.process(
120
- supir_model="supir-voq.ckpt",
121
- sdxl_model="juggernautxl.safetensors",
122
- fp8_unet=False,
123
- diffusion_dtype="auto",
124
- )
125
-
126
- imageresize = NODE_CLASS_MAPPINGS["ImageResize+"]()
127
- imageresize_18 = imageresize.execute(
128
- width=1280,
129
- height=1280,
130
- interpolation="lanczos",
131
- keep_proportion=False,
132
- condition="always",
133
- multiple_of=0,
134
- image=get_value_at_index(loadimage_13, 0),
135
- )
136
-
137
- supir_first_stage = NODE_CLASS_MAPPINGS["SUPIR_first_stage"]()
138
- supir_first_stage_7 = supir_first_stage.process(
139
- use_tiled_vae=True,
140
- encoder_tile_size=512,
141
- decoder_tile_size=512,
142
- encoder_dtype="auto",
143
- SUPIR_VAE=get_value_at_index(supir_model_loader_58, 1),
144
- image=get_value_at_index(imageresize_18, 0),
145
- )
146
-
147
- supir_encode = NODE_CLASS_MAPPINGS["SUPIR_encode"]()
148
- supir_encode_21 = supir_encode.encode(
149
- use_tiled_vae=True,
150
- encoder_tile_size=512,
151
- encoder_dtype="auto",
152
- SUPIR_VAE=get_value_at_index(supir_first_stage_7, 0),
153
- image=get_value_at_index(supir_first_stage_7, 1),
154
- )
155
-
156
- supir_conditioner = NODE_CLASS_MAPPINGS["SUPIR_conditioner"]()
157
- supir_sample = NODE_CLASS_MAPPINGS["SUPIR_sample"]()
158
- supir_decode = NODE_CLASS_MAPPINGS["SUPIR_decode"]()
159
- image_comparer_rgthree = NODE_CLASS_MAPPINGS["Image Comparer (rgthree)"]()
160
- playsoundpysssss = NODE_CLASS_MAPPINGS["PlaySound|pysssss"]()
161
- colormatch = NODE_CLASS_MAPPINGS["ColorMatch"]()
162
- saveimage = SaveImage()
163
-
164
- for q in range(10):
165
- supir_conditioner_12 = supir_conditioner.condition(
166
- positive_prompt="a red car, high quality, detailed",
167
- negative_prompt="bad quality, blurry, messy",
168
- SUPIR_model=get_value_at_index(supir_model_loader_58, 0),
169
- latents=get_value_at_index(supir_first_stage_7, 2),
170
- )
171
-
172
- supir_sample_8 = supir_sample.sample(
173
- seed=random.randint(1, 2**64),
174
- steps=10,
175
- cfg_scale_start=5,
176
- cfg_scale_end=5,
177
- EDM_s_churn=5,
178
- s_noise=1.003,
179
- DPMPP_eta=1,
180
- control_scale_start=0.9,
181
- control_scale_end=0.9500000000000001,
182
- restore_cfg=10,
183
- keep_model_loaded=False,
184
- sampler="RestoreDPMPP2MSampler",
185
- sampler_tile_size=1024,
186
- sampler_tile_stride=512,
187
- SUPIR_model=get_value_at_index(supir_model_loader_58, 0),
188
- latents=get_value_at_index(supir_encode_21, 0),
189
- positive=get_value_at_index(supir_conditioner_12, 0),
190
- negative=get_value_at_index(supir_conditioner_12, 1),
191
- )
192
-
193
- supir_decode_9 = supir_decode.decode(
194
- use_tiled_vae=True,
195
- decoder_tile_size=512,
196
- SUPIR_VAE=get_value_at_index(supir_model_loader_58, 1),
197
- latents=get_value_at_index(supir_sample_8, 0),
198
- )
199
-
200
- image_comparer_rgthree_15 = image_comparer_rgthree.compare_images(
201
- image_a=get_value_at_index(loadimage_13, 0),
202
- image_b=get_value_at_index(supir_first_stage_7, 1),
203
- )
204
-
205
- playsoundpysssss_38 = playsoundpysssss.nop(
206
- mode="always",
207
- volume=0.5,
208
- file="notify.mp3",
209
- any=get_value_at_index(supir_decode_9, 0),
210
- )
211
-
212
- colormatch_57 = colormatch.colormatch(
213
- method="mkl",
214
- image_ref=get_value_at_index(loadimage_13, 0),
215
- image_target=get_value_at_index(supir_decode_9, 0),
216
- )
217
-
218
- saveimage_39 = saveimage.save_images(
219
- filename_prefix="SUPIR_", images=get_value_at_index(colormatch_57, 0)
220
- )
221
-
222
- image_comparer_rgthree_59 = image_comparer_rgthree.compare_images(
223
- image_a=get_value_at_index(colormatch_57, 0),
224
- image_b=get_value_at_index(loadimage_13, 0),
225
- )
226
-
227
-
228
- if __name__ == "__main__":
229
- main()