Coercer commited on
Commit
f83fb1d
·
verified ·
1 Parent(s): cb19e78

Upload FastImageEdit.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. FastImageEdit.py +635 -0
FastImageEdit.py ADDED
@@ -0,0 +1,635 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import sys
4
+ import json
5
+ import argparse
6
+ import contextlib
7
+ from typing import Sequence, Mapping, Any, Union
8
+ import torch
9
+ from random import randrange
10
+
11
+
12
+ def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
13
+ """Returns the value at the given index of a sequence or mapping.
14
+
15
+ If the object is a sequence (like list or string), returns the value at the given index.
16
+ If the object is a mapping (like a dictionary), returns the value at the index-th key.
17
+
18
+ Some return a dictionary, in these cases, we look for the "results" key
19
+
20
+ Args:
21
+ obj (Union[Sequence, Mapping]): The object to retrieve the value from.
22
+ index (int): The index of the value to retrieve.
23
+
24
+ Returns:
25
+ Any: The value at the given index.
26
+
27
+ Raises:
28
+ IndexError: If the index is out of bounds for the object and the object is not a mapping.
29
+ """
30
+ try:
31
+ return obj[index]
32
+ except KeyError:
33
+ return obj["result"][index]
34
+
35
+
36
+ def find_path(name: str, path: str = None) -> str:
37
+ """
38
+ Recursively looks at parent folders starting from the given path until it finds the given name.
39
+ Returns the path as a Path object if found, or None otherwise.
40
+ """
41
+ # If no path is given, use the current working directory
42
+ if path is None:
43
+ if args is None or args.comfyui_directory is None:
44
+ path = os.getcwd()
45
+ else:
46
+ path = args.comfyui_directory
47
+
48
+ # Check if the current directory contains the name
49
+ if name in os.listdir(path):
50
+ path_name = os.path.join(path, name)
51
+ print(f"{name} found: {path_name}")
52
+ return path_name
53
+
54
+ # Get the parent directory
55
+ parent_directory = os.path.dirname(path)
56
+
57
+ # If the parent directory is the same as the current directory, we've reached the root and stop the search
58
+ if parent_directory == path:
59
+ return None
60
+
61
+ # Recursively call the function with the parent directory
62
+ return find_path(name, parent_directory)
63
+
64
+
65
+ def add_comfyui_directory_to_sys_path() -> None:
66
+ """
67
+ Add 'ComfyUI' to the sys.path
68
+ """
69
+ comfyui_path = find_path("ComfyUI")
70
+ if comfyui_path is not None and os.path.isdir(comfyui_path):
71
+ sys.path.append(comfyui_path)
72
+
73
+ manager_path = os.path.join(
74
+ comfyui_path, "custom_nodes", "ComfyUI-Manager", "glob"
75
+ )
76
+
77
+ if os.path.isdir(manager_path) and os.listdir(manager_path):
78
+ sys.path.append(manager_path)
79
+ global has_manager
80
+ has_manager = True
81
+
82
+ import __main__
83
+
84
+ if getattr(__main__, "__file__", None) is None:
85
+ __main__.__file__ = os.path.join(comfyui_path, "main.py")
86
+
87
+ print(f"'{comfyui_path}' added to sys.path")
88
+
89
+
90
+ def add_extra_model_paths() -> None:
91
+ """
92
+ Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
93
+ """
94
+ from comfy.options import enable_args_parsing
95
+
96
+ enable_args_parsing()
97
+ from utils.extra_config import load_extra_path_config
98
+
99
+ extra_model_paths = find_path("extra_model_paths.yaml")
100
+
101
+ if extra_model_paths is not None:
102
+ load_extra_path_config(extra_model_paths)
103
+ else:
104
+ print("Could not find the extra_model_paths config file.")
105
+
106
+
107
+ def import_custom_nodes() -> None:
108
+ """Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
109
+
110
+ This function sets up a new asyncio event loop, initializes the PromptServer,
111
+ creates a PromptQueue, and initializes the custom nodes.
112
+ """
113
+ if has_manager:
114
+ try:
115
+ import manager_core as manager
116
+ except ImportError:
117
+ print("Could not import manager_core, proceeding without it.")
118
+ return
119
+ else:
120
+ if hasattr(manager, "get_config"):
121
+ print("Patching manager_core.get_config to enforce offline mode.")
122
+ try:
123
+ get_config = manager.get_config
124
+
125
+ def _get_config(*args, **kwargs):
126
+ config = get_config(*args, **kwargs)
127
+ config["network_mode"] = "offline"
128
+ return config
129
+
130
+ manager.get_config = _get_config
131
+ except Exception as e:
132
+ print("Failed to patch manager_core.get_config:", e)
133
+
134
+ import asyncio
135
+ import execution
136
+ from nodes import init_extra_nodes
137
+ import server
138
+
139
+ # Creating a new event loop and setting it as the default loop
140
+ loop = asyncio.new_event_loop()
141
+ asyncio.set_event_loop(loop)
142
+
143
+ async def inner():
144
+ # Creating an instance of PromptServer with the loop
145
+ server_instance = server.PromptServer(loop)
146
+ execution.PromptQueue(server_instance)
147
+
148
+ # Initializing custom nodes
149
+ await init_extra_nodes(init_custom_nodes=True)
150
+
151
+ loop.run_until_complete(inner())
152
+
153
+
154
+ def save_image_wrapper(context, cls):
155
+ if args.output is None:
156
+ return cls
157
+
158
+ from PIL import Image, ImageOps, ImageSequence
159
+ from PIL.PngImagePlugin import PngInfo
160
+
161
+ import numpy as np
162
+
163
+ class WrappedSaveImage(cls):
164
+ counter = 0
165
+
166
+ def save_images(
167
+ self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None
168
+ ):
169
+ if args.output is None:
170
+ return super().save_images(
171
+ images, filename_prefix, prompt, extra_pnginfo
172
+ )
173
+ else:
174
+ if len(images) > 1 and args.output == "-":
175
+ raise ValueError("Cannot save multiple images to stdout")
176
+ filename_prefix += self.prefix_append
177
+
178
+ results = list()
179
+ for batch_number, image in enumerate(images):
180
+ i = 255.0 * image.cpu().numpy()
181
+ img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
182
+ metadata = None
183
+ if not args.disable_metadata:
184
+ metadata = PngInfo()
185
+ if prompt is not None:
186
+ metadata.add_text("prompt", json.dumps(prompt))
187
+ if extra_pnginfo is not None:
188
+ for x in extra_pnginfo:
189
+ metadata.add_text(x, json.dumps(extra_pnginfo[x]))
190
+
191
+ if args.output == "-":
192
+ # Hack to briefly restore stdout
193
+ if context is not None:
194
+ context.__exit__(None, None, None)
195
+ try:
196
+ img.save(
197
+ sys.stdout.buffer,
198
+ format="png",
199
+ pnginfo=metadata,
200
+ compress_level=self.compress_level,
201
+ )
202
+ finally:
203
+ if context is not None:
204
+ context.__enter__()
205
+ else:
206
+ subfolder = ""
207
+ if len(images) == 1:
208
+ if os.path.isdir(args.output):
209
+ subfolder = args.output
210
+ file = "output.png"
211
+ else:
212
+ subfolder, file = os.path.split(args.output)
213
+ if subfolder == "":
214
+ subfolder = os.getcwd()
215
+ else:
216
+ if os.path.isdir(args.output):
217
+ subfolder = args.output
218
+ file = filename_prefix
219
+ else:
220
+ subfolder, file = os.path.split(args.output)
221
+
222
+ if subfolder == "":
223
+ subfolder = os.getcwd()
224
+
225
+ files = os.listdir(subfolder)
226
+ file_pattern = file
227
+ while True:
228
+ filename_with_batch_num = file_pattern.replace(
229
+ "%batch_num%", str(batch_number)
230
+ )
231
+ file = (
232
+ f"{filename_with_batch_num}_{self.counter:05}.png"
233
+ )
234
+ self.counter += 1
235
+
236
+ if file not in files:
237
+ break
238
+
239
+ img.save(
240
+ os.path.join(subfolder, file),
241
+ pnginfo=metadata,
242
+ compress_level=self.compress_level,
243
+ )
244
+ print("Saved image to", os.path.join(subfolder, file))
245
+ results.append(
246
+ {
247
+ "filename": file,
248
+ "subfolder": subfolder,
249
+ "type": self.type,
250
+ }
251
+ )
252
+
253
+ return {"ui": {"images": results}}
254
+
255
+ return WrappedSaveImage
256
+
257
+
258
+ def parse_arg(s: Any, default: Any = None) -> Any:
259
+ """Parses a JSON string, returning it unchanged if the parsing fails."""
260
+ if __name__ == "__main__" or not isinstance(s, str):
261
+ return s
262
+
263
+ try:
264
+ return json.loads(s)
265
+ except json.JSONDecodeError:
266
+ return s
267
+
268
+
269
+ parser = argparse.ArgumentParser(
270
+ description="A converted ComfyUI workflow. Node inputs listed below. Values passed should be valid JSON (assumes string if not valid JSON)."
271
+ )
272
+ parser.add_argument(
273
+ "--ckpt_name1",
274
+ default="SDXLCheckpoint.safetensors",
275
+ help='Argument 0, input `ckpt_name` for node "Load Checkpoint" id 14 (autogenerated)',
276
+ )
277
+
278
+ parser.add_argument(
279
+ "--lora_name2",
280
+ default="dmd2_sdxl_4step_lora_fp16.safetensors",
281
+ help='Argument 2, input `lora_name` for node "Load LoRA" id 17 (autogenerated)',
282
+ )
283
+
284
+ parser.add_argument(
285
+ "--strength_model3",
286
+ default=1,
287
+ help='Argument 3, input `strength_model` for node "Load LoRA" id 17 (autogenerated)',
288
+ )
289
+
290
+ parser.add_argument(
291
+ "--strength_clip4",
292
+ default=1,
293
+ help='Argument 4, input `strength_clip` for node "Load LoRA" id 17 (autogenerated)',
294
+ )
295
+
296
+ parser.add_argument(
297
+ "--text5",
298
+ default="Xx_negative_xX",
299
+ help='Argument 0, input `text` for node "CLIP Text Encode (Prompt)" id 7 (autogenerated)',
300
+ )
301
+
302
+ parser.add_argument(
303
+ "--text6",
304
+ default="Xx_positive_xX",
305
+ help='Argument 0, input `text` for node "CLIPTextEncode with BREAK syntax" id 15 (autogenerated)',
306
+ )
307
+
308
+ parser.add_argument(
309
+ "--image7",
310
+ default="example.png",
311
+ help='Argument 0, input `image` for node "Load Image" id 19 (autogenerated)',
312
+ )
313
+
314
+ parser.add_argument(
315
+ "--block_number8",
316
+ default=3,
317
+ help='Argument 1, input `block_number` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
318
+ )
319
+
320
+ parser.add_argument(
321
+ "--downscale_factor9",
322
+ default=2,
323
+ help='Argument 2, input `downscale_factor` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
324
+ )
325
+
326
+ parser.add_argument(
327
+ "--start_percent10",
328
+ default=0,
329
+ help='Argument 3, input `start_percent` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
330
+ )
331
+
332
+ parser.add_argument(
333
+ "--end_percent11",
334
+ default=0.5000000000000001,
335
+ help='Argument 4, input `end_percent` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
336
+ )
337
+
338
+ parser.add_argument(
339
+ "--downscale_after_skip12",
340
+ default=True,
341
+ help='Argument 5, input `downscale_after_skip` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
342
+ )
343
+
344
+ parser.add_argument(
345
+ "--downscale_method13",
346
+ default="bicubic",
347
+ help='Argument 6, input `downscale_method` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
348
+ )
349
+
350
+ parser.add_argument(
351
+ "--upscale_method14",
352
+ default="bicubic",
353
+ help='Argument 7, input `upscale_method` for node "PatchModelAddDownscale (Kohya Deep Shrink)" id 16 (autogenerated)',
354
+ )
355
+
356
+ parser.add_argument(
357
+ "--seed15",
358
+ default=64836095259134,
359
+ help='Argument 1, input `seed` for node "KSampler" id 3 (autogenerated)',
360
+ )
361
+
362
+ parser.add_argument(
363
+ "--steps16",
364
+ default=8,
365
+ help='Argument 2, input `steps` for node "KSampler" id 3 (autogenerated)',
366
+ )
367
+
368
+ parser.add_argument(
369
+ "--cfg17",
370
+ default=1,
371
+ help='Argument 3, input `cfg` for node "KSampler" id 3 (autogenerated)',
372
+ )
373
+
374
+ parser.add_argument(
375
+ "--sampler_name18",
376
+ default="lcm",
377
+ help='Argument 4, input `sampler_name` for node "KSampler" id 3 (autogenerated)',
378
+ )
379
+
380
+ parser.add_argument(
381
+ "--scheduler19",
382
+ default="karras",
383
+ help='Argument 5, input `scheduler` for node "KSampler" id 3 (autogenerated)',
384
+ )
385
+
386
+ parser.add_argument(
387
+ "--denoise20",
388
+ default=0.87,
389
+ help='Argument 9, input `denoise` for node "KSampler" id 3 (autogenerated)',
390
+ )
391
+
392
+ parser.add_argument(
393
+ "--filename_prefix21",
394
+ default="Fast",
395
+ help='Argument 1, input `filename_prefix` for node "Save Image" id 9 (autogenerated)',
396
+ )
397
+
398
+ parser.add_argument(
399
+ "--queue-size",
400
+ "-q",
401
+ type=int,
402
+ default=1,
403
+ help="How many times the workflow will be executed (default: 1)",
404
+ )
405
+
406
+ parser.add_argument(
407
+ "--comfyui-directory",
408
+ "-c",
409
+ default=None,
410
+ help="Where to look for ComfyUI (default: current directory)",
411
+ )
412
+
413
+ parser.add_argument(
414
+ "--output",
415
+ "-o",
416
+ default=None,
417
+ help="The location to save the output image. Either a file path, a directory, or - for stdout (default: the ComfyUI output directory)",
418
+ )
419
+
420
+ parser.add_argument(
421
+ "--disable-metadata",
422
+ action="store_true",
423
+ help="Disables writing workflow metadata to the outputs",
424
+ )
425
+
426
+
427
+ comfy_args = [sys.argv[0]]
428
+ if __name__ == "__main__" and "--" in sys.argv:
429
+ idx = sys.argv.index("--")
430
+ comfy_args += sys.argv[idx + 1 :]
431
+ sys.argv = sys.argv[:idx]
432
+
433
+ args = None
434
+ if __name__ == "__main__":
435
+ args = parser.parse_args()
436
+ sys.argv = comfy_args
437
+ if args is not None and args.output is not None and args.output == "-":
438
+ ctx = contextlib.redirect_stdout(sys.stderr)
439
+ else:
440
+ ctx = contextlib.nullcontext()
441
+
442
+ PROMPT_DATA = json.loads(
443
+ '{"3": {"inputs": {"seed": 64836095259134, "steps": 8, "cfg": 1, "sampler_name": "lcm", "scheduler": "karras", "denoise": 0.87, "model": ["16", 0], "positive": ["15", 0], "negative": ["7", 0], "latent_image": ["18", 0]}, "class_type": "KSampler", "_meta": {"title": "KSampler"}}, "7": {"inputs": {"text": "Xx_negative_xX", "clip": ["17", 1]}, "class_type": "CLIPTextEncode", "_meta": {"title": "CLIP Text Encode (Prompt)"}}, "8": {"inputs": {"samples": ["3", 0], "vae": ["14", 2]}, "class_type": "VAEDecode", "_meta": {"title": "VAE Decode"}}, "9": {"inputs": {"filename_prefix": "Fast", "images": ["8", 0]}, "class_type": "SaveImage", "_meta": {"title": "Save Image"}}, "14": {"inputs": {"ckpt_name": "SDXLCheckpoint.safetensors"}, "class_type": "CheckpointLoaderSimple", "_meta": {"title": "Load Checkpoint"}}, "15": {"inputs": {"text": "Xx_positive_xX", "clip": ["17", 1]}, "class_type": "CLIPTextEncodeWithBreak", "_meta": {"title": "CLIPTextEncode with BREAK syntax"}}, "16": {"inputs": {"block_number": 3, "downscale_factor": 2, "start_percent": 0, "end_percent": 0.5000000000000001, "downscale_after_skip": true, "downscale_method": "bicubic", "upscale_method": "bicubic", "model": ["17", 0]}, "class_type": "PatchModelAddDownscale", "_meta": {"title": "PatchModelAddDownscale (Kohya Deep Shrink)"}}, "17": {"inputs": {"lora_name": "dmd2_sdxl_4step_lora_fp16.safetensors", "strength_model": 1, "strength_clip": 1, "model": ["14", 0], "clip": ["14", 1]}, "class_type": "LoraLoader", "_meta": {"title": "Load LoRA"}}, "18": {"inputs": {"pixels": ["19", 0], "vae": ["14", 2]}, "class_type": "VAEEncode", "_meta": {"title": "VAE Encode"}}, "19": {"inputs": {"image": "example.png"}, "class_type": "LoadImage", "_meta": {"title": "Load Image"}}}'
444
+ )
445
+
446
+
447
+ def import_custom_nodes() -> None:
448
+ """Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
449
+
450
+ This function sets up a new asyncio event loop, initializes the PromptServer,
451
+ creates a PromptQueue, and initializes the custom nodes.
452
+ """
453
+ if has_manager:
454
+ try:
455
+ import manager_core as manager
456
+ except ImportError:
457
+ print("Could not import manager_core, proceeding without it.")
458
+ return
459
+ else:
460
+ if hasattr(manager, "get_config"):
461
+ print("Patching manager_core.get_config to enforce offline mode.")
462
+ try:
463
+ get_config = manager.get_config
464
+
465
+ def _get_config(*args, **kwargs):
466
+ config = get_config(*args, **kwargs)
467
+ config["network_mode"] = "offline"
468
+ return config
469
+
470
+ manager.get_config = _get_config
471
+ except Exception as e:
472
+ print("Failed to patch manager_core.get_config:", e)
473
+
474
+ import asyncio
475
+ import execution
476
+ from nodes import init_extra_nodes
477
+ import server
478
+
479
+ # Creating a new event loop and setting it as the default loop
480
+ loop = asyncio.new_event_loop()
481
+ asyncio.set_event_loop(loop)
482
+
483
+ async def inner():
484
+ # Creating an instance of PromptServer with the loop
485
+ server_instance = server.PromptServer(loop)
486
+ execution.PromptQueue(server_instance)
487
+
488
+ # Initializing custom nodes
489
+ await init_extra_nodes(init_custom_nodes=True)
490
+
491
+ loop.run_until_complete(inner())
492
+
493
+
494
+ _custom_nodes_imported = False
495
+ _custom_path_added = False
496
+
497
+
498
+ def main(*func_args, **func_kwargs):
499
+ global args, _custom_nodes_imported, _custom_path_added
500
+ if __name__ == "__main__":
501
+ if args is None:
502
+ args = parser.parse_args()
503
+ else:
504
+ defaults = dict(
505
+ (arg, parser.get_default(arg))
506
+ for arg in ["queue_size", "comfyui_directory", "output", "disable_metadata"]
507
+ + [
508
+ "ckpt_name1",
509
+ "lora_name2",
510
+ "strength_model3",
511
+ "strength_clip4",
512
+ "text5",
513
+ "text6",
514
+ "image7",
515
+ "block_number8",
516
+ "downscale_factor9",
517
+ "start_percent10",
518
+ "end_percent11",
519
+ "downscale_after_skip12",
520
+ "downscale_method13",
521
+ "upscale_method14",
522
+ "seed15",
523
+ "steps16",
524
+ "cfg17",
525
+ "sampler_name18",
526
+ "scheduler19",
527
+ "denoise20",
528
+ "filename_prefix21",
529
+ ]
530
+ )
531
+
532
+ all_args = dict()
533
+ all_args.update(defaults)
534
+ all_args.update(func_kwargs)
535
+
536
+ args = argparse.Namespace(**all_args)
537
+
538
+ with ctx:
539
+ if not _custom_path_added:
540
+ add_comfyui_directory_to_sys_path()
541
+ add_extra_model_paths()
542
+
543
+ _custom_path_added = True
544
+
545
+ if not _custom_nodes_imported:
546
+ import_custom_nodes()
547
+
548
+ _custom_nodes_imported = True
549
+
550
+ from nodes import NODE_CLASS_MAPPINGS
551
+
552
+ with torch.inference_mode(), ctx:
553
+ checkpointloadersimple = NODE_CLASS_MAPPINGS["CheckpointLoaderSimple"]()
554
+ checkpointloadersimple_14 = checkpointloadersimple.load_checkpoint(
555
+ ckpt_name=parse_arg(args.ckpt_name1)
556
+ )
557
+
558
+ loraloader = NODE_CLASS_MAPPINGS["LoraLoader"]()
559
+ loraloader_17 = loraloader.load_lora(
560
+ lora_name=parse_arg(args.lora_name2),
561
+ strength_model=parse_arg(args.strength_model3),
562
+ strength_clip=parse_arg(args.strength_clip4),
563
+ model=get_value_at_index(checkpointloadersimple_14, 0),
564
+ clip=get_value_at_index(checkpointloadersimple_14, 1),
565
+ )
566
+
567
+ cliptextencode = NODE_CLASS_MAPPINGS["CLIPTextEncode"]()
568
+ cliptextencode_7 = cliptextencode.encode(
569
+ text=parse_arg(args.text5), clip=get_value_at_index(loraloader_17, 1)
570
+ )
571
+
572
+ cliptextencodewithbreak = NODE_CLASS_MAPPINGS["CLIPTextEncodeWithBreak"]()
573
+ cliptextencodewithbreak_15 = cliptextencodewithbreak.encode(
574
+ text=parse_arg(args.text6), clip=get_value_at_index(loraloader_17, 1)
575
+ )
576
+
577
+ loadimage = NODE_CLASS_MAPPINGS["LoadImage"]()
578
+ loadimage_19 = loadimage.load_image(image=parse_arg(args.image7))
579
+
580
+ vaeencode = NODE_CLASS_MAPPINGS["VAEEncode"]()
581
+ vaeencode_18 = vaeencode.encode(
582
+ pixels=get_value_at_index(loadimage_19, 0),
583
+ vae=get_value_at_index(checkpointloadersimple_14, 2),
584
+ )
585
+
586
+ patchmodeladddownscale = NODE_CLASS_MAPPINGS["PatchModelAddDownscale"]()
587
+ ksampler = NODE_CLASS_MAPPINGS["KSampler"]()
588
+ vaedecode = NODE_CLASS_MAPPINGS["VAEDecode"]()
589
+ saveimage = save_image_wrapper(ctx, NODE_CLASS_MAPPINGS["SaveImage"])()
590
+ for q in range(args.queue_size):
591
+ patchmodeladddownscale_16 = patchmodeladddownscale.patch(
592
+ block_number=parse_arg(args.block_number8),
593
+ downscale_factor=parse_arg(args.downscale_factor9),
594
+ start_percent=parse_arg(args.start_percent10),
595
+ end_percent=parse_arg(args.end_percent11),
596
+ downscale_after_skip=parse_arg(args.downscale_after_skip12),
597
+ downscale_method=parse_arg(args.downscale_method13),
598
+ upscale_method=parse_arg(args.upscale_method14),
599
+ model=get_value_at_index(loraloader_17, 0),
600
+ )
601
+
602
+ ksampler_3 = ksampler.sample(
603
+ seed=randrange(1000000000),
604
+ steps=parse_arg(args.steps16),
605
+ cfg=parse_arg(args.cfg17),
606
+ sampler_name=parse_arg(args.sampler_name18),
607
+ scheduler=parse_arg(args.scheduler19),
608
+ denoise=(90.0+randrange(9))/100.0,
609
+ model=get_value_at_index(patchmodeladddownscale_16, 0),
610
+ positive=get_value_at_index(cliptextencodewithbreak_15, 0),
611
+ negative=get_value_at_index(cliptextencode_7, 0),
612
+ latent_image=get_value_at_index(vaeencode_18, 0),
613
+ )
614
+
615
+ vaedecode_8 = vaedecode.decode(
616
+ samples=get_value_at_index(ksampler_3, 0),
617
+ vae=get_value_at_index(checkpointloadersimple_14, 2),
618
+ )
619
+
620
+ if __name__ != "__main__":
621
+ return dict(
622
+ filename_prefix=parse_arg(args.filename_prefix21),
623
+ images=get_value_at_index(vaedecode_8, 0),
624
+ prompt=PROMPT_DATA,
625
+ )
626
+ else:
627
+ saveimage_9 = saveimage.save_images(
628
+ filename_prefix=parse_arg(args.filename_prefix21),
629
+ images=get_value_at_index(vaedecode_8, 0),
630
+ prompt=PROMPT_DATA,
631
+ )
632
+
633
+
634
+ if __name__ == "__main__":
635
+ main()