Spaces:
Running on Zero
Running on Zero
Deploy GitHub a51e6f6df2b2d5093fd2526a7953c2ee6a422e37
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +17 -0
- LICENSE +674 -0
- NOTICE.md +24 -0
- README.md +338 -8
- app.py +127 -0
- chain_injectors/__init__.py +50 -0
- chain_injectors/anima_controlnet_lllite_injector.py +53 -0
- chain_injectors/boogu_image_edit_injector.py +73 -0
- chain_injectors/conditioning_injector.py +81 -0
- chain_injectors/controlnet_injector.py +60 -0
- chain_injectors/diffsynth_controlnet_injector.py +75 -0
- chain_injectors/flux1_ipadapter_injector.py +46 -0
- chain_injectors/hidream_o1_reference_injector.py +54 -0
- chain_injectors/hidream_o1_smoothing_injector.py +39 -0
- chain_injectors/ipadapter_injector.py +151 -0
- chain_injectors/joyai_image_injector.py +63 -0
- chain_injectors/krea2_controlnet_injector.py +78 -0
- chain_injectors/krea2_identity_edit_injector.py +173 -0
- chain_injectors/krea2_style_reference_injector.py +168 -0
- chain_injectors/lora_injector.py +67 -0
- chain_injectors/pid_injector.py +292 -0
- chain_injectors/qwen_image_edit_injector.py +113 -0
- chain_injectors/reference_image_injector.py +64 -0
- chain_injectors/reference_latent_injector.py +157 -0
- chain_injectors/sd3_ipadapter_injector.py +66 -0
- chain_injectors/style_injector.py +71 -0
- chain_injectors/vae_injector.py +30 -0
- comfy_integration/__init__.py +0 -0
- comfy_integration/nodes.py +44 -0
- comfy_integration/setup.py +161 -0
- core/__init__.py +0 -0
- core/execution_plan.py +450 -0
- core/generation_logic.py +10 -0
- core/model_capabilities.py +22 -0
- core/model_manager.py +63 -0
- core/pipelines/__init__.py +0 -0
- core/pipelines/base_pipeline.py +55 -0
- core/pipelines/pipeline_input_processor.py +580 -0
- core/pipelines/sd_image_pipeline.py +364 -0
- core/pipelines/workflow_executor.py +140 -0
- core/pipelines/workflow_recipes/_partials/_base_sampler.yaml +28 -0
- core/pipelines/workflow_recipes/_partials/conditioning/anima.yaml +70 -0
- core/pipelines/workflow_recipes/_partials/conditioning/auraflow.yaml +56 -0
- core/pipelines/workflow_recipes/_partials/conditioning/boogu-image.yaml +67 -0
- core/pipelines/workflow_recipes/_partials/conditioning/chroma1-radiance.yaml +67 -0
- core/pipelines/workflow_recipes/_partials/conditioning/chroma1.yaml +73 -0
- core/pipelines/workflow_recipes/_partials/conditioning/cosmos-predict2.yaml +55 -0
- core/pipelines/workflow_recipes/_partials/conditioning/ernie-image.yaml +66 -0
- core/pipelines/workflow_recipes/_partials/conditioning/flux1.yaml +76 -0
- core/pipelines/workflow_recipes/_partials/conditioning/flux2-kv.yaml +108 -0
.gitignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.py[cod]
|
| 3 |
+
.pytest_cache/
|
| 4 |
+
.coverage
|
| 5 |
+
.venv/
|
| 6 |
+
.env
|
| 7 |
+
local/
|
| 8 |
+
|
| 9 |
+
_vendor/
|
| 10 |
+
custom_nodes/
|
| 11 |
+
models/
|
| 12 |
+
input/
|
| 13 |
+
output/
|
| 14 |
+
ComfyUI_temp/
|
| 15 |
+
|
| 16 |
+
*.log
|
| 17 |
+
.DS_Store
|
LICENSE
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works.
|
| 12 |
+
|
| 13 |
+
The licenses for most software and other practical works are designed
|
| 14 |
+
to take away your freedom to share and change the works. By contrast,
|
| 15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 16 |
+
share and change all versions of a program--to make sure it remains free
|
| 17 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 18 |
+
GNU General Public License for most of our software; it applies also to
|
| 19 |
+
any other work released this way by its authors. You can apply it to
|
| 20 |
+
your programs, too.
|
| 21 |
+
|
| 22 |
+
When we speak of free software, we are referring to freedom, not
|
| 23 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 24 |
+
have the freedom to distribute copies of free software (and charge for
|
| 25 |
+
them if you wish), that you receive source code or can get it if you
|
| 26 |
+
want it, that you can change the software or use pieces of it in new
|
| 27 |
+
free programs, and that you know you can do these things.
|
| 28 |
+
|
| 29 |
+
To protect your rights, we need to prevent others from denying you
|
| 30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 31 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 32 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 33 |
+
|
| 34 |
+
For example, if you distribute copies of such a program, whether
|
| 35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 36 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 37 |
+
or can get the source code. And you must show them these terms so they
|
| 38 |
+
know their rights.
|
| 39 |
+
|
| 40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 43 |
+
|
| 44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 45 |
+
that there is no warranty for this free software. For both users' and
|
| 46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 47 |
+
changed, so that their problems will not be attributed erroneously to
|
| 48 |
+
authors of previous versions.
|
| 49 |
+
|
| 50 |
+
Some devices are designed to deny users access to install or run
|
| 51 |
+
modified versions of the software inside them, although the manufacturer
|
| 52 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 53 |
+
protecting users' freedom to change the software. The systematic
|
| 54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 56 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 57 |
+
products. If such problems arise substantially in other domains, we
|
| 58 |
+
stand ready to extend this provision to those domains in future versions
|
| 59 |
+
of the GPL, as needed to protect the freedom of users.
|
| 60 |
+
|
| 61 |
+
Finally, every program is threatened constantly by software patents.
|
| 62 |
+
States should not allow patents to restrict development and use of
|
| 63 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 64 |
+
avoid the special danger that patents applied to a free program could
|
| 65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 66 |
+
patents cannot be used to render the program non-free.
|
| 67 |
+
|
| 68 |
+
The precise terms and conditions for copying, distribution and
|
| 69 |
+
modification follow.
|
| 70 |
+
|
| 71 |
+
TERMS AND CONDITIONS
|
| 72 |
+
|
| 73 |
+
0. Definitions.
|
| 74 |
+
|
| 75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 76 |
+
|
| 77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 78 |
+
works, such as semiconductor masks.
|
| 79 |
+
|
| 80 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 82 |
+
"recipients" may be individuals or organizations.
|
| 83 |
+
|
| 84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 85 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 86 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 87 |
+
earlier work or a work "based on" the earlier work.
|
| 88 |
+
|
| 89 |
+
A "covered work" means either the unmodified Program or a work based
|
| 90 |
+
on the Program.
|
| 91 |
+
|
| 92 |
+
To "propagate" a work means to do anything with it that, without
|
| 93 |
+
permission, would make you directly or secondarily liable for
|
| 94 |
+
infringement under applicable copyright law, except executing it on a
|
| 95 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 96 |
+
distribution (with or without modification), making available to the
|
| 97 |
+
public, and in some countries other activities as well.
|
| 98 |
+
|
| 99 |
+
To "convey" a work means any kind of propagation that enables other
|
| 100 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 102 |
+
|
| 103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 104 |
+
to the extent that it includes a convenient and prominently visible
|
| 105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 106 |
+
tells the user that there is no warranty for the work (except to the
|
| 107 |
+
extent that warranties are provided), that licensees may convey the
|
| 108 |
+
work under this License, and how to view a copy of this License. If
|
| 109 |
+
the interface presents a list of user commands or options, such as a
|
| 110 |
+
menu, a prominent item in the list meets this criterion.
|
| 111 |
+
|
| 112 |
+
1. Source Code.
|
| 113 |
+
|
| 114 |
+
The "source code" for a work means the preferred form of the work
|
| 115 |
+
for making modifications to it. "Object code" means any non-source
|
| 116 |
+
form of a work.
|
| 117 |
+
|
| 118 |
+
A "Standard Interface" means an interface that either is an official
|
| 119 |
+
standard defined by a recognized standards body, or, in the case of
|
| 120 |
+
interfaces specified for a particular programming language, one that
|
| 121 |
+
is widely used among developers working in that language.
|
| 122 |
+
|
| 123 |
+
The "System Libraries" of an executable work include anything, other
|
| 124 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 125 |
+
packaging a Major Component, but which is not part of that Major
|
| 126 |
+
Component, and (b) serves only to enable use of the work with that
|
| 127 |
+
Major Component, or to implement a Standard Interface for which an
|
| 128 |
+
implementation is available to the public in source code form. A
|
| 129 |
+
"Major Component", in this context, means a major essential component
|
| 130 |
+
(kernel, window system, and so on) of the specific operating system
|
| 131 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 132 |
+
produce the work, or an object code interpreter used to run it.
|
| 133 |
+
|
| 134 |
+
The "Corresponding Source" for a work in object code form means all
|
| 135 |
+
the source code needed to generate, install, and (for an executable
|
| 136 |
+
work) run the object code and to modify the work, including scripts to
|
| 137 |
+
control those activities. However, it does not include the work's
|
| 138 |
+
System Libraries, or general-purpose tools or generally available free
|
| 139 |
+
programs which are used unmodified in performing those activities but
|
| 140 |
+
which are not part of the work. For example, Corresponding Source
|
| 141 |
+
includes interface definition files associated with source files for
|
| 142 |
+
the work, and the source code for shared libraries and dynamically
|
| 143 |
+
linked subprograms that the work is specifically designed to require,
|
| 144 |
+
such as by intimate data communication or control flow between those
|
| 145 |
+
subprograms and other parts of the work.
|
| 146 |
+
|
| 147 |
+
The Corresponding Source need not include anything that users
|
| 148 |
+
can regenerate automatically from other parts of the Corresponding
|
| 149 |
+
Source.
|
| 150 |
+
|
| 151 |
+
The Corresponding Source for a work in source code form is that
|
| 152 |
+
same work.
|
| 153 |
+
|
| 154 |
+
2. Basic Permissions.
|
| 155 |
+
|
| 156 |
+
All rights granted under this License are granted for the term of
|
| 157 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 158 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 159 |
+
permission to run the unmodified Program. The output from running a
|
| 160 |
+
covered work is covered by this License only if the output, given its
|
| 161 |
+
content, constitutes a covered work. This License acknowledges your
|
| 162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 163 |
+
|
| 164 |
+
You may make, run and propagate covered works that you do not
|
| 165 |
+
convey, without conditions so long as your license otherwise remains
|
| 166 |
+
in force. You may convey covered works to others for the sole purpose
|
| 167 |
+
of having them make modifications exclusively for you, or provide you
|
| 168 |
+
with facilities for running those works, provided that you comply with
|
| 169 |
+
the terms of this License in conveying all material for which you do
|
| 170 |
+
not control copyright. Those thus making or running the covered works
|
| 171 |
+
for you must do so exclusively on your behalf, under your direction
|
| 172 |
+
and control, on terms that prohibit them from making any copies of
|
| 173 |
+
your copyrighted material outside their relationship with you.
|
| 174 |
+
|
| 175 |
+
Conveying under any other circumstances is permitted solely under
|
| 176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 177 |
+
makes it unnecessary.
|
| 178 |
+
|
| 179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 180 |
+
|
| 181 |
+
No covered work shall be deemed part of an effective technological
|
| 182 |
+
measure under any applicable law fulfilling obligations under article
|
| 183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 184 |
+
similar laws prohibiting or restricting circumvention of such
|
| 185 |
+
measures.
|
| 186 |
+
|
| 187 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 188 |
+
circumvention of technological measures to the extent such circumvention
|
| 189 |
+
is effected by exercising rights under this License with respect to
|
| 190 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 191 |
+
modification of the work as a means of enforcing, against the work's
|
| 192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 193 |
+
technological measures.
|
| 194 |
+
|
| 195 |
+
4. Conveying Verbatim Copies.
|
| 196 |
+
|
| 197 |
+
You may convey verbatim copies of the Program's source code as you
|
| 198 |
+
receive it, in any medium, provided that you conspicuously and
|
| 199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 200 |
+
keep intact all notices stating that this License and any
|
| 201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 202 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 203 |
+
recipients a copy of this License along with the Program.
|
| 204 |
+
|
| 205 |
+
You may charge any price or no price for each copy that you convey,
|
| 206 |
+
and you may offer support or warranty protection for a fee.
|
| 207 |
+
|
| 208 |
+
5. Conveying Modified Source Versions.
|
| 209 |
+
|
| 210 |
+
You may convey a work based on the Program, or the modifications to
|
| 211 |
+
produce it from the Program, in the form of source code under the
|
| 212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 213 |
+
|
| 214 |
+
a) The work must carry prominent notices stating that you modified
|
| 215 |
+
it, and giving a relevant date.
|
| 216 |
+
|
| 217 |
+
b) The work must carry prominent notices stating that it is
|
| 218 |
+
released under this License and any conditions added under section
|
| 219 |
+
7. This requirement modifies the requirement in section 4 to
|
| 220 |
+
"keep intact all notices".
|
| 221 |
+
|
| 222 |
+
c) You must license the entire work, as a whole, under this
|
| 223 |
+
License to anyone who comes into possession of a copy. This
|
| 224 |
+
License will therefore apply, along with any applicable section 7
|
| 225 |
+
additional terms, to the whole of the work, and all its parts,
|
| 226 |
+
regardless of how they are packaged. This License gives no
|
| 227 |
+
permission to license the work in any other way, but it does not
|
| 228 |
+
invalidate such permission if you have separately received it.
|
| 229 |
+
|
| 230 |
+
d) If the work has interactive user interfaces, each must display
|
| 231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 233 |
+
work need not make them do so.
|
| 234 |
+
|
| 235 |
+
A compilation of a covered work with other separate and independent
|
| 236 |
+
works, which are not by their nature extensions of the covered work,
|
| 237 |
+
and which are not combined with it such as to form a larger program,
|
| 238 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 240 |
+
used to limit the access or legal rights of the compilation's users
|
| 241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 242 |
+
in an aggregate does not cause this License to apply to the other
|
| 243 |
+
parts of the aggregate.
|
| 244 |
+
|
| 245 |
+
6. Conveying Non-Source Forms.
|
| 246 |
+
|
| 247 |
+
You may convey a covered work in object code form under the terms
|
| 248 |
+
of sections 4 and 5, provided that you also convey the
|
| 249 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 250 |
+
in one of these ways:
|
| 251 |
+
|
| 252 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 253 |
+
(including a physical distribution medium), accompanied by the
|
| 254 |
+
Corresponding Source fixed on a durable physical medium
|
| 255 |
+
customarily used for software interchange.
|
| 256 |
+
|
| 257 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 258 |
+
(including a physical distribution medium), accompanied by a
|
| 259 |
+
written offer, valid for at least three years and valid for as
|
| 260 |
+
long as you offer spare parts or customer support for that product
|
| 261 |
+
model, to give anyone who possesses the object code either (1) a
|
| 262 |
+
copy of the Corresponding Source for all the software in the
|
| 263 |
+
product that is covered by this License, on a durable physical
|
| 264 |
+
medium customarily used for software interchange, for a price no
|
| 265 |
+
more than your reasonable cost of physically performing this
|
| 266 |
+
conveying of source, or (2) access to copy the
|
| 267 |
+
Corresponding Source from a network server at no charge.
|
| 268 |
+
|
| 269 |
+
c) Convey individual copies of the object code with a copy of the
|
| 270 |
+
written offer to provide the Corresponding Source. This
|
| 271 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 272 |
+
only if you received the object code with such an offer, in accord
|
| 273 |
+
with subsection 6b.
|
| 274 |
+
|
| 275 |
+
d) Convey the object code by offering access from a designated
|
| 276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 277 |
+
Corresponding Source in the same way through the same place at no
|
| 278 |
+
further charge. You need not require recipients to copy the
|
| 279 |
+
Corresponding Source along with the object code. If the place to
|
| 280 |
+
copy the object code is a network server, the Corresponding Source
|
| 281 |
+
may be on a different server (operated by you or a third party)
|
| 282 |
+
that supports equivalent copying facilities, provided you maintain
|
| 283 |
+
clear directions next to the object code saying where to find the
|
| 284 |
+
Corresponding Source. Regardless of what server hosts the
|
| 285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 286 |
+
available for as long as needed to satisfy these requirements.
|
| 287 |
+
|
| 288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 289 |
+
you inform other peers where the object code and Corresponding
|
| 290 |
+
Source of the work are being offered to the general public at no
|
| 291 |
+
charge under subsection 6d.
|
| 292 |
+
|
| 293 |
+
A separable portion of the object code, whose source code is excluded
|
| 294 |
+
from the Corresponding Source as a System Library, need not be
|
| 295 |
+
included in conveying the object code work.
|
| 296 |
+
|
| 297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 298 |
+
tangible personal property which is normally used for personal, family,
|
| 299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 302 |
+
product received by a particular user, "normally used" refers to a
|
| 303 |
+
typical or common use of that class of product, regardless of the status
|
| 304 |
+
of the particular user or of the way in which the particular user
|
| 305 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 306 |
+
is a consumer product regardless of whether the product has substantial
|
| 307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 308 |
+
the only significant mode of use of the product.
|
| 309 |
+
|
| 310 |
+
"Installation Information" for a User Product means any methods,
|
| 311 |
+
procedures, authorization keys, or other information required to install
|
| 312 |
+
and execute modified versions of a covered work in that User Product from
|
| 313 |
+
a modified version of its Corresponding Source. The information must
|
| 314 |
+
suffice to ensure that the continued functioning of the modified object
|
| 315 |
+
code is in no case prevented or interfered with solely because
|
| 316 |
+
modification has been made.
|
| 317 |
+
|
| 318 |
+
If you convey an object code work under this section in, or with, or
|
| 319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 320 |
+
part of a transaction in which the right of possession and use of the
|
| 321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 322 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 323 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 324 |
+
by the Installation Information. But this requirement does not apply
|
| 325 |
+
if neither you nor any third party retains the ability to install
|
| 326 |
+
modified object code on the User Product (for example, the work has
|
| 327 |
+
been installed in ROM).
|
| 328 |
+
|
| 329 |
+
The requirement to provide Installation Information does not include a
|
| 330 |
+
requirement to continue to provide support service, warranty, or updates
|
| 331 |
+
for a work that has been modified or installed by the recipient, or for
|
| 332 |
+
the User Product in which it has been modified or installed. Access to a
|
| 333 |
+
network may be denied when the modification itself materially and
|
| 334 |
+
adversely affects the operation of the network or violates the rules and
|
| 335 |
+
protocols for communication across the network.
|
| 336 |
+
|
| 337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 338 |
+
in accord with this section must be in a format that is publicly
|
| 339 |
+
documented (and with an implementation available to the public in
|
| 340 |
+
source code form), and must require no special password or key for
|
| 341 |
+
unpacking, reading or copying.
|
| 342 |
+
|
| 343 |
+
7. Additional Terms.
|
| 344 |
+
|
| 345 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 346 |
+
License by making exceptions from one or more of its conditions.
|
| 347 |
+
Additional permissions that are applicable to the entire Program shall
|
| 348 |
+
be treated as though they were included in this License, to the extent
|
| 349 |
+
that they are valid under applicable law. If additional permissions
|
| 350 |
+
apply only to part of the Program, that part may be used separately
|
| 351 |
+
under those permissions, but the entire Program remains governed by
|
| 352 |
+
this License without regard to the additional permissions.
|
| 353 |
+
|
| 354 |
+
When you convey a copy of a covered work, you may at your option
|
| 355 |
+
remove any additional permissions from that copy, or from any part of
|
| 356 |
+
it. (Additional permissions may be written to require their own
|
| 357 |
+
removal in certain cases when you modify the work.) You may place
|
| 358 |
+
additional permissions on material, added by you to a covered work,
|
| 359 |
+
for which you have or can give appropriate copyright permission.
|
| 360 |
+
|
| 361 |
+
Notwithstanding any other provision of this License, for material you
|
| 362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 363 |
+
that material) supplement the terms of this License with terms:
|
| 364 |
+
|
| 365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 366 |
+
terms of sections 15 and 16 of this License; or
|
| 367 |
+
|
| 368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 369 |
+
author attributions in that material or in the Appropriate Legal
|
| 370 |
+
Notices displayed by works containing it; or
|
| 371 |
+
|
| 372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 373 |
+
requiring that modified versions of such material be marked in
|
| 374 |
+
reasonable ways as different from the original version; or
|
| 375 |
+
|
| 376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 377 |
+
authors of the material; or
|
| 378 |
+
|
| 379 |
+
e) Declining to grant rights under trademark law for use of some
|
| 380 |
+
trade names, trademarks, or service marks; or
|
| 381 |
+
|
| 382 |
+
f) Requiring indemnification of licensors and authors of that
|
| 383 |
+
material by anyone who conveys the material (or modified versions of
|
| 384 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 385 |
+
any liability that these contractual assumptions directly impose on
|
| 386 |
+
those licensors and authors.
|
| 387 |
+
|
| 388 |
+
All other non-permissive additional terms are considered "further
|
| 389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 390 |
+
received it, or any part of it, contains a notice stating that it is
|
| 391 |
+
governed by this License along with a term that is a further
|
| 392 |
+
restriction, you may remove that term. If a license document contains
|
| 393 |
+
a further restriction but permits relicensing or conveying under this
|
| 394 |
+
License, you may add to a covered work material governed by the terms
|
| 395 |
+
of that license document, provided that the further restriction does
|
| 396 |
+
not survive such relicensing or conveying.
|
| 397 |
+
|
| 398 |
+
If you add terms to a covered work in accord with this section, you
|
| 399 |
+
must place, in the relevant source files, a statement of the
|
| 400 |
+
additional terms that apply to those files, or a notice indicating
|
| 401 |
+
where to find the applicable terms.
|
| 402 |
+
|
| 403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 404 |
+
form of a separately written license, or stated as exceptions;
|
| 405 |
+
the above requirements apply either way.
|
| 406 |
+
|
| 407 |
+
8. Termination.
|
| 408 |
+
|
| 409 |
+
You may not propagate or modify a covered work except as expressly
|
| 410 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 411 |
+
modify it is void, and will automatically terminate your rights under
|
| 412 |
+
this License (including any patent licenses granted under the third
|
| 413 |
+
paragraph of section 11).
|
| 414 |
+
|
| 415 |
+
However, if you cease all violation of this License, then your
|
| 416 |
+
license from a particular copyright holder is reinstated (a)
|
| 417 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 419 |
+
holder fails to notify you of the violation by some reasonable means
|
| 420 |
+
prior to 60 days after the cessation.
|
| 421 |
+
|
| 422 |
+
Moreover, your license from a particular copyright holder is
|
| 423 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 424 |
+
violation by some reasonable means, this is the first time you have
|
| 425 |
+
received notice of violation of this License (for any work) from that
|
| 426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 427 |
+
your receipt of the notice.
|
| 428 |
+
|
| 429 |
+
Termination of your rights under this section does not terminate the
|
| 430 |
+
licenses of parties who have received copies or rights from you under
|
| 431 |
+
this License. If your rights have been terminated and not permanently
|
| 432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 433 |
+
material under section 10.
|
| 434 |
+
|
| 435 |
+
9. Acceptance Not Required for Having Copies.
|
| 436 |
+
|
| 437 |
+
You are not required to accept this License in order to receive or
|
| 438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 440 |
+
to receive a copy likewise does not require acceptance. However,
|
| 441 |
+
nothing other than this License grants you permission to propagate or
|
| 442 |
+
modify any covered work. These actions infringe copyright if you do
|
| 443 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 444 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 445 |
+
|
| 446 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 447 |
+
|
| 448 |
+
Each time you convey a covered work, the recipient automatically
|
| 449 |
+
receives a license from the original licensors, to run, modify and
|
| 450 |
+
propagate that work, subject to this License. You are not responsible
|
| 451 |
+
for enforcing compliance by third parties with this License.
|
| 452 |
+
|
| 453 |
+
An "entity transaction" is a transaction transferring control of an
|
| 454 |
+
organization, or substantially all assets of one, or subdividing an
|
| 455 |
+
organization, or merging organizations. If propagation of a covered
|
| 456 |
+
work results from an entity transaction, each party to that
|
| 457 |
+
transaction who receives a copy of the work also receives whatever
|
| 458 |
+
licenses to the work the party's predecessor in interest had or could
|
| 459 |
+
give under the previous paragraph, plus a right to possession of the
|
| 460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 461 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 462 |
+
|
| 463 |
+
You may not impose any further restrictions on the exercise of the
|
| 464 |
+
rights granted or affirmed under this License. For example, you may
|
| 465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 466 |
+
rights granted under this License, and you may not initiate litigation
|
| 467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 468 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 469 |
+
sale, or importing the Program or any portion of it.
|
| 470 |
+
|
| 471 |
+
11. Patents.
|
| 472 |
+
|
| 473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 474 |
+
License of the Program or a work on which the Program is based. The
|
| 475 |
+
work thus licensed is called the contributor's "contributor version".
|
| 476 |
+
|
| 477 |
+
A contributor's "essential patent claims" are all patent claims
|
| 478 |
+
owned or controlled by the contributor, whether already acquired or
|
| 479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 480 |
+
by this License, of making, using, or selling its contributor version,
|
| 481 |
+
but do not include claims that would be infringed only as a
|
| 482 |
+
consequence of further modification of the contributor version. For
|
| 483 |
+
purposes of this definition, "control" includes the right to grant
|
| 484 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 485 |
+
this License.
|
| 486 |
+
|
| 487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 488 |
+
patent license under the contributor's essential patent claims, to
|
| 489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 490 |
+
propagate the contents of its contributor version.
|
| 491 |
+
|
| 492 |
+
In the following three paragraphs, a "patent license" is any express
|
| 493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 494 |
+
(such as an express permission to practice a patent or covenant not to
|
| 495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 496 |
+
party means to make such an agreement or commitment not to enforce a
|
| 497 |
+
patent against the party.
|
| 498 |
+
|
| 499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 500 |
+
and the Corresponding Source of the work is not available for anyone
|
| 501 |
+
to copy, free of charge and under the terms of this License, through a
|
| 502 |
+
publicly available network server or other readily accessible means,
|
| 503 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 506 |
+
consistent with the requirements of this License, to extend the patent
|
| 507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 508 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 509 |
+
covered work in a country, or your recipient's use of the covered work
|
| 510 |
+
in a country, would infringe one or more identifiable patents in that
|
| 511 |
+
country that you have reason to believe are valid.
|
| 512 |
+
|
| 513 |
+
If, pursuant to or in connection with a single transaction or
|
| 514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 515 |
+
covered work, and grant a patent license to some of the parties
|
| 516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 517 |
+
or convey a specific copy of the covered work, then the patent license
|
| 518 |
+
you grant is automatically extended to all recipients of the covered
|
| 519 |
+
work and works based on it.
|
| 520 |
+
|
| 521 |
+
A patent license is "discriminatory" if it does not include within
|
| 522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 524 |
+
specifically granted under this License. You may not convey a covered
|
| 525 |
+
work if you are a party to an arrangement with a third party that is
|
| 526 |
+
in the business of distributing software, under which you make payment
|
| 527 |
+
to the third party based on the extent of your activity of conveying
|
| 528 |
+
the work, and under which the third party grants, to any of the
|
| 529 |
+
parties who would receive the covered work from you, a discriminatory
|
| 530 |
+
patent license (a) in connection with copies of the covered work
|
| 531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 532 |
+
for and in connection with specific products or compilations that
|
| 533 |
+
contain the covered work, unless you entered into that arrangement,
|
| 534 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 535 |
+
|
| 536 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 537 |
+
any implied license or other defenses to infringement that may
|
| 538 |
+
otherwise be available to you under applicable patent law.
|
| 539 |
+
|
| 540 |
+
12. No Surrender of Others' Freedom.
|
| 541 |
+
|
| 542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 543 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 546 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 548 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 549 |
+
the Program, the only way you could satisfy both those terms and this
|
| 550 |
+
License would be to refrain entirely from conveying the Program.
|
| 551 |
+
|
| 552 |
+
13. Use with the GNU Affero General Public License.
|
| 553 |
+
|
| 554 |
+
Notwithstanding any other provision of this License, you have
|
| 555 |
+
permission to link or combine any covered work with a work licensed
|
| 556 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 557 |
+
combined work, and to convey the resulting work. The terms of this
|
| 558 |
+
License will continue to apply to the part which is the covered work,
|
| 559 |
+
but the special requirements of the GNU Affero General Public License,
|
| 560 |
+
section 13, concerning interaction through a network will apply to the
|
| 561 |
+
combination as such.
|
| 562 |
+
|
| 563 |
+
14. Revised Versions of this License.
|
| 564 |
+
|
| 565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 566 |
+
the GNU General Public License from time to time. Such new versions will
|
| 567 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 568 |
+
address new problems or concerns.
|
| 569 |
+
|
| 570 |
+
Each version is given a distinguishing version number. If the
|
| 571 |
+
Program specifies that a certain numbered version of the GNU General
|
| 572 |
+
Public License "or any later version" applies to it, you have the
|
| 573 |
+
option of following the terms and conditions either of that numbered
|
| 574 |
+
version or of any later version published by the Free Software
|
| 575 |
+
Foundation. If the Program does not specify a version number of the
|
| 576 |
+
GNU General Public License, you may choose any version ever published
|
| 577 |
+
by the Free Software Foundation.
|
| 578 |
+
|
| 579 |
+
If the Program specifies that a proxy can decide which future
|
| 580 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 581 |
+
public statement of acceptance of a version permanently authorizes you
|
| 582 |
+
to choose that version for the Program.
|
| 583 |
+
|
| 584 |
+
Later license versions may give you additional or different
|
| 585 |
+
permissions. However, no additional obligations are imposed on any
|
| 586 |
+
author or copyright holder as a result of your choosing to follow a
|
| 587 |
+
later version.
|
| 588 |
+
|
| 589 |
+
15. Disclaimer of Warranty.
|
| 590 |
+
|
| 591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 599 |
+
|
| 600 |
+
16. Limitation of Liability.
|
| 601 |
+
|
| 602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 610 |
+
SUCH DAMAGES.
|
| 611 |
+
|
| 612 |
+
17. Interpretation of Sections 15 and 16.
|
| 613 |
+
|
| 614 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 615 |
+
above cannot be given local legal effect according to their terms,
|
| 616 |
+
reviewing courts shall apply local law that most closely approximates
|
| 617 |
+
an absolute waiver of all civil liability in connection with the
|
| 618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 619 |
+
copy of the Program in return for a fee.
|
| 620 |
+
|
| 621 |
+
END OF TERMS AND CONDITIONS
|
| 622 |
+
|
| 623 |
+
How to Apply These Terms to Your New Programs
|
| 624 |
+
|
| 625 |
+
If you develop a new program, and you want it to be of the greatest
|
| 626 |
+
possible use to the public, the best way to achieve this is to make it
|
| 627 |
+
free software which everyone can redistribute and change under these terms.
|
| 628 |
+
|
| 629 |
+
To do so, attach the following notices to the program. It is safest
|
| 630 |
+
to attach them to the start of each source file to most effectively
|
| 631 |
+
state the exclusion of warranty; and each file should have at least
|
| 632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 633 |
+
|
| 634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 635 |
+
Copyright (C) <year> <name of author>
|
| 636 |
+
|
| 637 |
+
This program is free software: you can redistribute it and/or modify
|
| 638 |
+
it under the terms of the GNU General Public License as published by
|
| 639 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 640 |
+
(at your option) any later version.
|
| 641 |
+
|
| 642 |
+
This program is distributed in the hope that it will be useful,
|
| 643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 645 |
+
GNU General Public License for more details.
|
| 646 |
+
|
| 647 |
+
You should have received a copy of the GNU General Public License
|
| 648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 649 |
+
|
| 650 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 651 |
+
|
| 652 |
+
If the program does terminal interaction, make it output a short
|
| 653 |
+
notice like this when it starts in an interactive mode:
|
| 654 |
+
|
| 655 |
+
<program> Copyright (C) <year> <name of author>
|
| 656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 657 |
+
This is free software, and you are welcome to redistribute it
|
| 658 |
+
under certain conditions; type `show c' for details.
|
| 659 |
+
|
| 660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 661 |
+
parts of the General Public License. Of course, your program's commands
|
| 662 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 663 |
+
|
| 664 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 667 |
+
<https://www.gnu.org/licenses/>.
|
| 668 |
+
|
| 669 |
+
The GNU General Public License does not permit incorporating your program
|
| 670 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 671 |
+
may consider it more useful to permit linking proprietary applications with
|
| 672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 673 |
+
Public License instead of this License. But first, please read
|
| 674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
NOTICE.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 来源与修改声明
|
| 2 |
+
|
| 3 |
+
本仓库是下列 GPL-3.0 项目的修改与整合版本:
|
| 4 |
+
|
| 5 |
+
- RioShiina/ImageGen,核对版本:`3622e14a8b6587699eb3e0616c167d0c35649ca7`
|
| 6 |
+
- Dekonstruktio/Fluxus,核对版本:`4aaca1f35ace66be1fb73de9bc46d390501f4ef6`
|
| 7 |
+
- 两者共同祖先:`9dbb7e3b34150ab09eaa0b83b92c7ea7e0493860`
|
| 8 |
+
|
| 9 |
+
Fluxus 在共同祖先之后只改动 README、MCP 启用开关和界面品牌文案,未形成独立推理引擎。本修改版因此以 ImageGen 为主干,并保留 Fluxus 的 MCP 关闭选项以及 `run_imagegen`、`get_chain_schema` 兼容接口。
|
| 10 |
+
|
| 11 |
+
主要修改包括:
|
| 12 |
+
|
| 13 |
+
- 将五套重复 Gradio 页面重构为一个动态工作台;
|
| 14 |
+
- 新增中文界面、任务说明、模型语言提示与快捷模型方案;
|
| 15 |
+
- 调整模型切换语义,避免覆盖用户 Prompt;
|
| 16 |
+
- 为 UI、Gradio API 与 MCP 增加共享的有界 GPU 调度;
|
| 17 |
+
- 将 MCP 裸线程改为有界执行器,并为任务表增加锁和容量限制;
|
| 18 |
+
- 将临时文件改为 UUID,并为下载和共享目录写入增加进程锁;
|
| 19 |
+
- 固定 ComfyUI/custom nodes commit,并与应用源码隔离;
|
| 20 |
+
- 避免重复执行 ComfyUI SaveImage;
|
| 21 |
+
- 增加输入/输出像素、批量和 URL 图片约束;
|
| 22 |
+
- 增加测试、中文部署文档和 Fluxus 接口兼容层。
|
| 23 |
+
|
| 24 |
+
本仓库保留原始 `LICENSE`,整体按 GPL-3.0 分发。这里列出的模型仅在运行时按需下载,其许可证与使用限制由各模型作者决定。ComfyUI、custom nodes、SageAttention 及其他第三方依赖也继续适用各自许可证;本声明不改变这些许可。
|
README.md
CHANGED
|
@@ -1,13 +1,343 @@
|
|
| 1 |
---
|
| 2 |
-
title: ImageGen Studio
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ImageGen Studio 中文版
|
| 3 |
+
emoji: 🖼
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: "5.50.0"
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
+
python_version: "3.12.12"
|
| 10 |
+
startup_duration_timeout: 1h
|
| 11 |
+
short_description: 中文优先的多任务图片生成与编辑工作台
|
| 12 |
+
license: gpl-3.0
|
| 13 |
+
pinned: true
|
| 14 |
+
models:
|
| 15 |
+
# This Space supports a wide variety of image generation pipelines. To maintain transparency, credit the original creators, and help users explore the Hugging Face ecosystem, we list and link several types of models in our metadata:
|
| 16 |
+
# 1. **Directly Run Models:** Models and checkpoints actively loaded by our pipelines (configured via `yaml/file_list.yaml`).
|
| 17 |
+
# 2. **Upstream Base Models:** The original foundation architectures from which our optimized ports, quantized versions, or wrappers are derived.
|
| 18 |
+
# Directly Run Models
|
| 19 |
+
- AiAF/Illustrious-XL-v0.1.safetensors
|
| 20 |
+
- alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union-2.1
|
| 21 |
+
- black-forest-labs/FLUX.1-Redux-dev
|
| 22 |
+
- black-forest-labs/FLUX.2-dev-NVFP4
|
| 23 |
+
- black-forest-labs/FLUX.2-klein-4b-nvfp4
|
| 24 |
+
- black-forest-labs/FLUX.2-klein-9b-nvfp4
|
| 25 |
+
- black-forest-labs/FLUX.2-klein-9b-kv-fp8
|
| 26 |
+
- black-forest-labs/FLUX.2-klein-base-4b-nvfp4
|
| 27 |
+
- black-forest-labs/FLUX.2-klein-base-9b-nvfp4
|
| 28 |
+
- bluepen5805/4nima_pencil-XL
|
| 29 |
+
- bluepen5805/anima-models
|
| 30 |
+
- bluepen5805/anima_pencil-XL
|
| 31 |
+
- bluepen5805/blue_pencil-XL
|
| 32 |
+
- bluepen5805/illustrious_pencil-XL
|
| 33 |
+
- bluepen5805/mellow_pencil-XL
|
| 34 |
+
- bluepen5805/noob_v_pencil-XL
|
| 35 |
+
- bluepen5805/pony_pencil-XL
|
| 36 |
+
- cagliostrolab/animagine-xl-3.1
|
| 37 |
+
- cagliostrolab/animagine-xl-4.0
|
| 38 |
+
- ChenkinNoob/ChenkinNoob-XL-V0.5
|
| 39 |
+
- circlestone-labs/Anima
|
| 40 |
+
- Clybius/Chroma-fp8-scaled
|
| 41 |
+
- comfyanonymous/ControlNet-v1-1_fp16_safetensors
|
| 42 |
+
- comfyanonymous/cosmos_1.0_text_encoder_and_VAE_ComfyUI
|
| 43 |
+
- comfyanonymous/flux_text_encoders
|
| 44 |
+
- Comfy-Org/Anima-LLLite
|
| 45 |
+
- Comfy-Org/Boogu-Image
|
| 46 |
+
- Comfy-Org/ERNIE-Image
|
| 47 |
+
- Comfy-Org/FLUX.1-Krea-dev_ComfyUI
|
| 48 |
+
- Comfy-Org/flux2-dev
|
| 49 |
+
- Comfy-Org/HiDream-I1_ComfyUI
|
| 50 |
+
- Comfy-Org/HiDream-O1-Image
|
| 51 |
+
- Comfy-Org/HunyuanImage_2.1_ComfyUI
|
| 52 |
+
- Comfy-Org/Ideogram-4
|
| 53 |
+
- Comfy-Org/Krea-2
|
| 54 |
+
- Comfy-Org/Lens
|
| 55 |
+
- Comfy-Org/LongCat-Image
|
| 56 |
+
- Comfy-Org/Lumina_Image_2.0_Repackaged
|
| 57 |
+
- Comfy-Org/Mage-Flow
|
| 58 |
+
- Comfy-Org/NewBie-image-Exp0.1_repackaged
|
| 59 |
+
- Comfy-Org/Omnigen2_ComfyUI_repackaged
|
| 60 |
+
- Comfy-Org/Ovis-Image
|
| 61 |
+
- Comfy-Org/PixelDiT
|
| 62 |
+
- Comfy-Org/Qwen-Image_ComfyUI
|
| 63 |
+
- Comfy-Org/Qwen-Image-Edit_ComfyUI
|
| 64 |
+
- Comfy-Org/sigclip_vision_384
|
| 65 |
+
- Comfy-Org/stable-diffusion-3.5-fp8
|
| 66 |
+
- Comfy-Org/vae-text-encorder-for-flux-klein-4b
|
| 67 |
+
- Comfy-Org/vae-text-encorder-for-flux-klein-9b
|
| 68 |
+
- Comfy-Org/Wan_2.1_ComfyUI_repackaged
|
| 69 |
+
- Comfy-Org/z_image
|
| 70 |
+
- Comfy-Org/z_image_turbo
|
| 71 |
+
- conradlocke/krea2-identity-edit
|
| 72 |
+
- cyberdelia/CyberRealisticPony
|
| 73 |
+
- diffusionmodels1254ani/hassakuAnima
|
| 74 |
+
- diffusionmodels1254ani/kirazuriAnima_v30AnimaBase1
|
| 75 |
+
- diffusionmodels1254ani/waiANIMA
|
| 76 |
+
- duongve/AnimaYume
|
| 77 |
+
- Eugeoter/noob-sdxl-controlnet-canny
|
| 78 |
+
- Eugeoter/noob-sdxl-controlnet-depth
|
| 79 |
+
- Eugeoter/noob-sdxl-controlnet-lineart_anime
|
| 80 |
+
- Eugeoter/noob-sdxl-controlnet-lineart_realistic
|
| 81 |
+
- Eugeoter/noob-sdxl-controlnet-manga_line
|
| 82 |
+
- Eugeoter/noob-sdxl-controlnet-normal
|
| 83 |
+
- Eugeoter/noob-sdxl-controlnet-softedge_hed
|
| 84 |
+
- Eugeoter/noob-sdxl-controlnet-tile
|
| 85 |
+
- fal/AuraFlow-v0.3
|
| 86 |
+
- frankjoshua/novaAnimeXL_ilV180
|
| 87 |
+
- h94/IP-Adapter
|
| 88 |
+
- h94/IP-Adapter-FaceID
|
| 89 |
+
- InstantX/FLUX.1-dev-IP-Adapter
|
| 90 |
+
- InstantX/Qwen-Image-ControlNet-Inpainting
|
| 91 |
+
- InstantX/Qwen-Image-ControlNet-Union
|
| 92 |
+
- InstantX/SD3.5-Large-IP-Adapter
|
| 93 |
+
- jdopensource/JoyAI-Image-Edit-ComfyUI
|
| 94 |
+
- jdopensource/JoyAI-Image-Edit-Plus-ComfyUI
|
| 95 |
+
- kandinskylab/Kandinsky-5.0-T2I-Lite
|
| 96 |
+
- Kijai/flux-fp8
|
| 97 |
+
- Laxhar/noob_openpose
|
| 98 |
+
- Laxhar/noobai-XL-1.1
|
| 99 |
+
- Laxhar/noobai-XL-Vpred-1.0
|
| 100 |
+
- licyk/sd_control_collection
|
| 101 |
+
- lightx2v/Qwen-Image-2512-Lightning
|
| 102 |
+
- lightx2v/Qwen-Image-Edit-2511-Lightning
|
| 103 |
+
- LyliaEngine/Pony_Diffusion_V6_XL
|
| 104 |
+
- MIC-Lab/illustriousXLv0.1_controlnet
|
| 105 |
+
- MIC-Lab/illustriousXLv1.1_controlnet
|
| 106 |
+
- misri/hassakuXLIllustrious_v30
|
| 107 |
+
- nvidia/Cosmos-Predict2-2B-Text2Image
|
| 108 |
+
- nvidia/Cosmos-Predict2-14B-Text2Image
|
| 109 |
+
- OnomaAIResearch/Illustrious-XL-v1.0
|
| 110 |
+
- OnomaAIResearch/Illustrious-XL-v1.1
|
| 111 |
+
- OnomaAIResearch/Illustrious-XL-v2.0
|
| 112 |
+
- ostris/krea2_turbo_style_reference
|
| 113 |
+
- Patil/Krea-2-depth-controlnet
|
| 114 |
+
- RedRayz/hikari_noob_v-pred_1.2.4
|
| 115 |
+
- Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro-2.0
|
| 116 |
+
- silveroxides/Chroma1-Radiance-fp8-scaled
|
| 117 |
+
- stabilityai/sdxl-turbo
|
| 118 |
+
- stabilityai/stable-diffusion-3.5-controlnets
|
| 119 |
+
- stabilityai/stable-diffusion-xl-base-1.0
|
| 120 |
+
- stable-diffusion-v1-5/stable-diffusion-v1-5
|
| 121 |
+
- tsukiyomi/krea2_raw-nvfp4
|
| 122 |
+
- Wenaka/NoobAI_XL_Inpainting_ControlNet_Full
|
| 123 |
+
- xinsir/anime-painter
|
| 124 |
+
- xinsir/controlnet-canny-sdxl-1.0
|
| 125 |
+
- xinsir/controlnet-depth-sdxl-1.0
|
| 126 |
+
- xinsir/controlnet-openpose-sdxl-1.0
|
| 127 |
+
- xinsir/controlnet-scribble-sdxl-1.0
|
| 128 |
+
- xinsir/controlnet-tile-sdxl-1.0
|
| 129 |
+
- xinsir/controlnet-union-sdxl-1.0
|
| 130 |
+
- XLabs-AI/flux-controlnet-collections
|
| 131 |
+
- zhenshipo/waiIllustriousSDXL_v170
|
| 132 |
+
# Upstream Base Models
|
| 133 |
+
- AIDC-AI/Ovis-Image-7B
|
| 134 |
+
- Alpha-VLLM/Lumina-Image-2.0
|
| 135 |
+
- baidu/ERNIE-Image
|
| 136 |
+
- baidu/ERNIE-Image-Turbo
|
| 137 |
+
- black-forest-labs/FLUX.1-dev
|
| 138 |
+
- black-forest-labs/FLUX.1-Krea-dev
|
| 139 |
+
- black-forest-labs/FLUX.1-schnell
|
| 140 |
+
- Boogu/Boogu-Image-0.1-Turbo
|
| 141 |
+
- Boogu/Boogu-Image-0.1-Base
|
| 142 |
+
- Boogu/Boogu-Image-0.1-Edit
|
| 143 |
+
- Boogu/Boogu-Image-0.1-Edit-Turbo
|
| 144 |
+
- HiDream-ai/HiDream-I1-Dev
|
| 145 |
+
- HiDream-ai/HiDream-I1-Fast
|
| 146 |
+
- HiDream-ai/HiDream-I1-Full
|
| 147 |
+
- HiDream-ai/HiDream-O1-Image
|
| 148 |
+
- HiDream-ai/HiDream-O1-Image-Dev
|
| 149 |
+
- ideogram-ai/ideogram-4-fp8
|
| 150 |
+
- kohya-ss/Anima-LLLite
|
| 151 |
+
- krea/Krea-2-Raw
|
| 152 |
+
- krea/Krea-2-Turbo
|
| 153 |
+
- lodestones/Chroma1-HD
|
| 154 |
+
- lodestones/Chroma1-Radiance
|
| 155 |
+
- mage-flow-community/Mage-Flow
|
| 156 |
+
- mage-flow-community/Mage-Flow-Base
|
| 157 |
+
- mage-flow-community/Mage-Flow-Edit
|
| 158 |
+
- mage-flow-community/Mage-Flow-Edit-Base
|
| 159 |
+
- mage-flow-community/Mage-Flow-Edit-Turbo
|
| 160 |
+
- mage-flow-community/Mage-Flow-Turbo
|
| 161 |
+
- meituan-longcat/LongCat-Image
|
| 162 |
+
- microsoft/Lens
|
| 163 |
+
- microsoft/Lens-Turbo
|
| 164 |
+
- NewBie-AI/NewBie-image-Exp0.1
|
| 165 |
+
- nvidia/PiD
|
| 166 |
+
- nvidia/PixelDiT-1300M-1024px
|
| 167 |
+
- OmniGen2/OmniGen2
|
| 168 |
+
- Qwen/Qwen-Image
|
| 169 |
+
- Qwen/Qwen-Image-2512
|
| 170 |
+
- Qwen/Qwen-Image-Edit
|
| 171 |
+
- Qwen/Qwen-Image-Edit-2509
|
| 172 |
+
- Qwen/Qwen-Image-Edit-2511
|
| 173 |
+
- stabilityai/stable-diffusion-3.5-large
|
| 174 |
+
- stabilityai/stable-diffusion-3.5-medium
|
| 175 |
+
- tencent/HunyuanImage-2.1
|
| 176 |
+
- Tongyi-MAI/Z-Image
|
| 177 |
+
- Tongyi-MAI/Z-Image-Turbo
|
| 178 |
---
|
| 179 |
|
| 180 |
+
# ImageGen Studio 中文版
|
| 181 |
+
|
| 182 |
+
这是 [RioShiina/ImageGen](https://huggingface.co/spaces/RioShiina/ImageGen) 与 [Dekonstruktio/Fluxus](https://huggingface.co/spaces/Dekonstruktio/Fluxus) 的整合重构版,保留 YAML 配方、动态工作流和 92 个模型目录,重做任务切换、并发调度、中文指导与移动端体验。
|
| 183 |
+
|
| 184 |
+
Fluxus 与 ImageGen 共享同一 Git 历史,Fluxus 当前版本只调整了品牌文案和 MCP 开关,没有第二套推理核心。因此本项目使用一个 ImageGen 引擎,并兼容两边的 API 契约,避免双后端、双状态和重复下载。
|
| 185 |
+
|
| 186 |
+
## 主要改进
|
| 187 |
+
|
| 188 |
+
| 项目 | 原版 | 本整合版 |
|
| 189 |
+
|---|---|---|
|
| 190 |
+
| 任务界面 | 5 个完整 Tab,重复创建全部高级控件 | 1 个共享工作台,动态切换 5 类任务 |
|
| 191 |
+
| 任务切换 | 模型、Prompt 和素材分散在各 Tab | 保留模型、Prompt、参数与上传素材 |
|
| 192 |
+
| 模型切换 | 会覆盖正负 Prompt 和推荐参数 | 保留用户 Prompt;推荐采样参数可自动跟随、关闭或一键恢复 |
|
| 193 |
+
| 复杂度 | 约 4,033 组件 / 506 事件 | 烟测为 881 组件 / 120 事件 |
|
| 194 |
+
| GPU 并发 | UI 与 MCP 可绕过彼此并发执行 | 各入口有界,最终汇合到公平的单 GPU 闸门 |
|
| 195 |
+
| 异步 MCP | 每次请求创建无上限 daemon 线程 | 有界线程池、队列满错误、任务表上限与锁 |
|
| 196 |
+
| 临时文件 | 4 位随机后缀,可能碰撞 | UUID 文件名 |
|
| 197 |
+
| 启动依赖 | 运行时拉取最新版并覆盖项目根 | 固定 commit,隔离在 `_vendor/ComfyUI` |
|
| 198 |
+
| 中文体验 | 英文界面,无模型语言提示 | 中文任务指导、模型用途说明、可操作错误信息 |
|
| 199 |
+
| MCP 兼容 | ImageGen 与 Fluxus 接口名不同 | 同时保留新版接口与两个 Fluxus 旧别名 |
|
| 200 |
+
|
| 201 |
+
## 支持能力
|
| 202 |
+
|
| 203 |
+
- 任务:文生图、图生图、局部重绘、扩图、高清修复。
|
| 204 |
+
- 模型:由 `yaml/model_list.yaml` 驱动,当前包含 30 类架构、92 个显示模型。
|
| 205 |
+
- 扩展:LoRA、ControlNet、IP-Adapter、Embedding、区域提示、多图编辑、VAE、PiD 等。
|
| 206 |
+
- 输出:PNG 内写入生成参数和完整 ComfyUI 工作流元数据。
|
| 207 |
+
- 中文 Prompt:默认原样传递,不做隐式翻译;模型说明会区分中文自然语言和英文标签型模型。
|
| 208 |
+
|
| 209 |
+
## 批量、多图与模型 PK
|
| 210 |
+
|
| 211 |
+
这些能力只增加一个有上限的顺序编排层,不创建第二套推理引擎,也不会让多个大模型同时占用显存:
|
| 212 |
+
|
| 213 |
+
| 运行方式 | 输入语义 | 输出语义 |
|
| 214 |
+
|---|---|---|
|
| 215 |
+
| 普通生成 | 当前任务的一组输入 | 1–4 张同组变体 |
|
| 216 |
+
| 模型 PK | 同一 Prompt、尺寸、源图与已解析 Seed | 每个模型分别生成;默认最多 2 个模型 |
|
| 217 |
+
| 多图独立 | A、B、C 是互不相关的源图 | A→A′、B→B′、C→C′ |
|
| 218 |
+
| 多图 × 多模型 | 多张独立源图和两个模型 | 按模型分组顺序执行图片×模型组合 |
|
| 219 |
+
| 多图融合 | 多张图共同作为一组参考 | 由兼容的编辑模型融合为 1–4 张结果 |
|
| 220 |
+
|
| 221 |
+
- 多图独立目前支持图生图、扩图和高清修复;局部重绘需要逐张图片配对蒙版,暂不做批量。
|
| 222 |
+
- 多图融合内部固定走“文生图 + 模型专属参考链”,不会与图生图 base latent 混用。Prompt 可按“参考图 1 / 2 / 3”说明各图角色。
|
| 223 |
+
- 多图融合是生成式参考,不保证无损拼接、角色逐像素保留��确定性元素替换。
|
| 224 |
+
- PK 默认采用各模型推荐采样参数;关闭后才严格复用当前步数、CFG、采样器和调度器。同一 Seed 在不同架构之间只是尽量控制变量,不表示初始噪声数学等价。
|
| 225 |
+
- PK V1 会关闭 LoRA、ControlNet、IP-Adapter、参考链、自定义 VAE 和 PiD,只比较所有基础 checkpoint 都具备的 Prompt / 源图能力,避免某个模型偷偷多一层条件。
|
| 226 |
+
- 单进程始终一次只执行一个 GPU 任务。模型文件按需缓存在磁盘;只在 PK 的实际模型边界和 GPU 异常后释放 ComfyUI 模型状态。
|
| 227 |
+
- 默认上限为 2 个 PK 模型、4 张输入图、4 个顺序任务、8 张预计输出。某一组合失败时保留已成功结果;取消会停止尚未开始的后续组合。
|
| 228 |
+
|
| 229 |
+
## 部署到 Hugging Face Space
|
| 230 |
+
|
| 231 |
+
1. 新建 Gradio Space,硬件选择 ZeroGPU;README metadata 已固定 Python 3.12.12,并把冷启动上限设为 1 小时。
|
| 232 |
+
2. 上传本仓库内容;Space 会按 `requirements.txt` 安装 Gradio 5.50 和 MCP 额外依赖。
|
| 233 |
+
3. 按需要设置 Secret:
|
| 234 |
+
- `HF_TOKEN`:访问 gated/private Hugging Face 模型。
|
| 235 |
+
- `CIVITAI_API_KEY`:下载需要授权的 Civitai 资源。
|
| 236 |
+
4. 首次启动会按 `vendor.lock.yaml` 拉取固定版本的 ComfyUI 与 5 个 custom nodes;首次使用某个模型时才下载其权重。
|
| 237 |
+
|
| 238 |
+
部署边界:
|
| 239 |
+
|
| 240 |
+
- 模型目录包含 92 个可选项,但这不等于 92 个模型可同时驻留。ZeroGPU 应使用按需磁盘缓存 + 单模型顺序执行。
|
| 241 |
+
- Space 默认磁盘是临时盘,重启/重建后缓存可能消失。若需要长期保留模型,可把 Hugging Face Storage Bucket 挂载到 `/home/user/app/models`,并设置 `HF_HOME=/home/user/app/models/.hf-cache`,让权重实体和项目符号链接位于同一持久卷。
|
| 242 |
+
- 下载前会读取远端文件大小并保留默认 3 GB 安全余量;空间不足时会在下载前拒绝,而不是写满磁盘。项目不自动删除 Hub cache,避免误删仍被符号链接引用的模型。
|
| 243 |
+
- FLUX、SD3.5、Cosmos 等部分资源可能受访问条款限制。`HF_TOKEN` 所属账号必须先在对应模型页接受条款。
|
| 244 |
+
- 公共 Space 建议精选 4–8 个常用模型,并设置 `IMAGEGEN_MAX_BATCH_SIZE=2`;完整 92 模型目录更适合挂载持久存储的专用部署。
|
| 245 |
+
- ZeroGPU 单次 GPU 申请上限为 120 秒。大模型首次装载、超高分辨率或长采样仍可能超时;PK 会为每个模型分别申请 GPU,而不是占用一个超长租约。
|
| 246 |
+
|
| 247 |
+
完整的适配状态、推荐变量与上线实测清单见 [`docs/HF_SPACE_DEPLOYMENT.md`](docs/HF_SPACE_DEPLOYMENT.md)。
|
| 248 |
+
|
| 249 |
+
默认启动命令由 Space metadata 执行:
|
| 250 |
+
|
| 251 |
+
```bash
|
| 252 |
+
python app.py
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
## 本地运行
|
| 256 |
+
|
| 257 |
+
需要 Python 3.12、Git,以及与目标模型相匹配的 NVIDIA GPU 环境:
|
| 258 |
+
|
| 259 |
+
```bash
|
| 260 |
+
python -m venv .venv
|
| 261 |
+
source .venv/bin/activate
|
| 262 |
+
pip install -r requirements.txt
|
| 263 |
+
python app.py
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
如已有 ComfyUI,可避免再次克隆:
|
| 267 |
+
|
| 268 |
+
```bash
|
| 269 |
+
COMFYUI_PATH=/absolute/path/to/ComfyUI python app.py
|
| 270 |
+
```
|
| 271 |
+
|
| 272 |
+
## 运行参数
|
| 273 |
+
|
| 274 |
+
| 环境变量 | 默认值 | 说明 |
|
| 275 |
+
|---|---:|---|
|
| 276 |
+
| `IMAGEGEN_GPU_CONCURRENCY` | 固定 `1` | 为兼容旧部署保留名称;单进程始终串行,扩容请增加独立副本 |
|
| 277 |
+
| `IMAGEGEN_QUEUE_MAX_SIZE` | `24` | Gradio 等待队列上限 |
|
| 278 |
+
| `IMAGEGEN_MCP_MAX_PENDING` | `16` | MCP 后台任务上限 |
|
| 279 |
+
| `IMAGEGEN_MCP_TASK_RETENTION` | `200` | 内存任务记录上限 |
|
| 280 |
+
| `IMAGEGEN_MAX_BATCH_SIZE` | `4` | 单次最大图片数 |
|
| 281 |
+
| `IMAGEGEN_MAX_PK_MODELS` | `2` | PK 模型总数上限(含当前模型) |
|
| 282 |
+
| `IMAGEGEN_MAX_MULTI_IMAGES` | `4` | 批量输入/参考图的全局上传上限 |
|
| 283 |
+
| `IMAGEGEN_MAX_PLAN_JOBS` | `4` | 一次提交可展开的顺序任务上限 |
|
| 284 |
+
| `IMAGEGEN_MAX_PLAN_OUTPUTS` | `8` | 一次提交的预计输出总数上限 |
|
| 285 |
+
| `IMAGEGEN_MAX_INPUT_MEGAPIXELS` | `4.2` | 输入图片/文生图画布上限 |
|
| 286 |
+
| `IMAGEGEN_MAX_REFERENCE_MEGAPIXELS` | `12` | 一组上传图片的累计像素上限 |
|
| 287 |
+
| `IMAGEGEN_MAX_REFERENCE_IMAGES` | `10` | 一次任务中全部参考图/控制图的合计上限 |
|
| 288 |
+
| `IMAGEGEN_MAX_OUTPUT_MEGAPIXELS` | `16` | 扩图和高清修复预计输出上限 |
|
| 289 |
+
| `IMAGEGEN_MIN_FREE_DISK_GB` | `3` | 模型下载后必须保留的磁盘余量 |
|
| 290 |
+
| `IMAGEGEN_OUTPUT_RETENTION` | `80` | 本地保留的生成 PNG 数量 |
|
| 291 |
+
| `IMAGEGEN_ENABLE_MCP` | `true` | 是否启动 MCP;设为 `false` 即采用 Fluxus 的关闭方式 |
|
| 292 |
+
| `IMAGEGEN_STARTUP_GPU_PROBE` | `false` | 是否在启动时申请一次 GPU |
|
| 293 |
+
| `IMAGEGEN_USE_SAGE_ATTENTION` | `auto` | `auto` / `true` / `false` |
|
| 294 |
+
| `IMAGEGEN_SKIP_CUSTOM_NODES` | `false` | 本地调试时跳过 custom nodes 拉取 |
|
| 295 |
+
| `IMAGEGEN_GIT_TIMEOUT_SECONDS` | `180` | 单次 Git clone/fetch 超时 |
|
| 296 |
+
| `IMAGEGEN_GIT_ATTEMPTS` | `2` | Git 网络操作尝试次数 |
|
| 297 |
+
|
| 298 |
+
## MCP / Gradio API
|
| 299 |
+
|
| 300 |
+
公开 7 个主接口:
|
| 301 |
+
|
| 302 |
+
- `get_task_list`
|
| 303 |
+
- `get_model_architecture_list`
|
| 304 |
+
- `get_model_list`
|
| 305 |
+
- `get_feature_list`
|
| 306 |
+
- `get_model_features`
|
| 307 |
+
- `run`
|
| 308 |
+
- `get_task_status`
|
| 309 |
+
|
| 310 |
+
同时保留 Fluxus 客��端兼容别名:
|
| 311 |
+
|
| 312 |
+
- `run_imagegen(json_params)` → `run(json_params)`
|
| 313 |
+
- `get_chain_schema(chain_type)` → 返回单个扩展能力的完整 schema
|
| 314 |
+
|
| 315 |
+
`get_feature_list()` 空参默认返回 Fluxus 兼容的完整 schema;如需节省 MCP token,传 `compact=true` 获取摘要。也可以传 `feature_name`,或使用 `get_chain_schema(chain_type)` 查询单项完整 schema。
|
| 316 |
+
|
| 317 |
+
所有 UI 原子事件均隐藏,不作为公共 API 暴露。
|
| 318 |
+
|
| 319 |
+
## 验证
|
| 320 |
+
|
| 321 |
+
```bash
|
| 322 |
+
python -m compileall -q .
|
| 323 |
+
python -m unittest discover -s tests -v
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
界面烟测会以 stub ComfyUI 构建完整 Gradio 配置,因此不需要下载模型或占用 GPU。
|
| 327 |
+
|
| 328 |
+
## 目录
|
| 329 |
+
|
| 330 |
+
```text
|
| 331 |
+
app.py # Space 入口与有界 Gradio 队列
|
| 332 |
+
core/ # 生成管线、工作流装配、统一调度
|
| 333 |
+
ui/shared/studio_ui.py # 单一动态工作台
|
| 334 |
+
ui/events/ # 切换、模型、扩展与生成事件
|
| 335 |
+
mcp_tools/ # 高层 API、兼容别名、任务状态
|
| 336 |
+
yaml/ # 模型、能力、默认参数与配方注册表
|
| 337 |
+
vendor.lock.yaml # ComfyUI / custom nodes 固定版本
|
| 338 |
+
tests/ # 并发、注册表、MCP 与 UI 烟测
|
| 339 |
+
```
|
| 340 |
+
|
| 341 |
+
## 许可与来源
|
| 342 |
+
|
| 343 |
+
本项目是 ImageGen 的修改版,整体继续采用 GPL-3.0,并保留上游署名。Fluxus 也是同一 GPL-3.0 代码谱系。模型权重、ComfyUI 与 custom nodes 各自受其上游许可证约束;本仓库不重新分发模型权重。具体版本与修改声明见 `NOTICE.md`。
|
app.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import importlib.util
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import site
|
| 6 |
+
|
| 7 |
+
from core.runtime_config import CONFIG
|
| 8 |
+
|
| 9 |
+
sage_mode = os.getenv("IMAGEGEN_USE_SAGE_ATTENTION", "auto").strip().lower()
|
| 10 |
+
sage_available = importlib.util.find_spec("sageattention") is not None
|
| 11 |
+
use_sage_attention = sage_mode in {"1", "true", "yes", "on"} or (
|
| 12 |
+
sage_mode == "auto" and sage_available
|
| 13 |
+
)
|
| 14 |
+
if use_sage_attention and "--use-sage-attention" not in sys.argv:
|
| 15 |
+
sys.argv.append("--use-sage-attention")
|
| 16 |
+
print("🚀 [SageAttention] Injected '--use-sage-attention' into sys.argv.")
|
| 17 |
+
|
| 18 |
+
APP_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 19 |
+
if APP_DIR not in sys.path:
|
| 20 |
+
sys.path.insert(0, APP_DIR)
|
| 21 |
+
print(f"✅ Added project root '{APP_DIR}' to sys.path.")
|
| 22 |
+
|
| 23 |
+
# Keep ComfyUI code isolated while pointing its model/input/output directories
|
| 24 |
+
# at this Space. These arguments are consumed when ComfyUI is imported.
|
| 25 |
+
if "--base-directory" not in sys.argv:
|
| 26 |
+
sys.argv.extend(["--base-directory", APP_DIR])
|
| 27 |
+
|
| 28 |
+
SAGE_PATCH_APPLIED = False
|
| 29 |
+
|
| 30 |
+
def apply_sage_attention_patch():
|
| 31 |
+
global SAGE_PATCH_APPLIED
|
| 32 |
+
if SAGE_PATCH_APPLIED:
|
| 33 |
+
return "SageAttention patch already applied."
|
| 34 |
+
if not use_sage_attention:
|
| 35 |
+
return "SageAttention disabled or unavailable; using the default attention backend."
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
from comfy import model_management
|
| 39 |
+
import sageattention
|
| 40 |
+
|
| 41 |
+
print("--- [Runtime Patch] sageattention package found. Applying patch... ---")
|
| 42 |
+
model_management.sage_attention_enabled = lambda: True
|
| 43 |
+
model_management.pytorch_attention_enabled = lambda: False
|
| 44 |
+
|
| 45 |
+
SAGE_PATCH_APPLIED = True
|
| 46 |
+
return "✅ Successfully enabled SageAttention."
|
| 47 |
+
except ImportError:
|
| 48 |
+
SAGE_PATCH_APPLIED = False
|
| 49 |
+
msg = "--- [Runtime Patch] ⚠️ sageattention package not found. Continuing with default attention. ---"
|
| 50 |
+
print(msg)
|
| 51 |
+
return msg
|
| 52 |
+
except Exception as e:
|
| 53 |
+
SAGE_PATCH_APPLIED = False
|
| 54 |
+
msg = f"--- [Runtime Patch] ❌ An error occurred while applying SageAttention patch: {e} ---"
|
| 55 |
+
print(msg)
|
| 56 |
+
return msg
|
| 57 |
+
|
| 58 |
+
@spaces.GPU
|
| 59 |
+
def dummy_gpu_for_startup():
|
| 60 |
+
print("--- [GPU Startup] Dummy function for startup check initiated. ---")
|
| 61 |
+
patch_result = apply_sage_attention_patch()
|
| 62 |
+
print(f"--- [GPU Startup] {patch_result} ---")
|
| 63 |
+
print("--- [GPU Startup] Startup check passed. ---")
|
| 64 |
+
return "Startup check passed."
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def main():
|
| 68 |
+
os.chdir(APP_DIR)
|
| 69 |
+
from comfy_integration import setup as setup_comfyui
|
| 70 |
+
from imagegen_utils.app_utils import load_ipadapter_presets
|
| 71 |
+
|
| 72 |
+
print("--- [Setup] Starting ComfyUI initialization ---")
|
| 73 |
+
setup_comfyui.initialize_comfyui()
|
| 74 |
+
|
| 75 |
+
print("--- [Setup] Applying SageAttention Runtime Patch ---")
|
| 76 |
+
patch_result = apply_sage_attention_patch()
|
| 77 |
+
print(f"--- [Setup] {patch_result} ---")
|
| 78 |
+
|
| 79 |
+
print("--- [Setup] Reloading site-packages to detect newly installed packages... ---")
|
| 80 |
+
try:
|
| 81 |
+
site.main()
|
| 82 |
+
print("--- [Setup] ✅ Site-packages reloaded. ---")
|
| 83 |
+
except Exception as e:
|
| 84 |
+
print(f"--- [Setup] ⚠️ Warning: Could not fully reload site-packages: {e} ---")
|
| 85 |
+
|
| 86 |
+
if CONFIG.enable_startup_gpu_probe:
|
| 87 |
+
print("--- Initiating optional GPU startup check ---")
|
| 88 |
+
try:
|
| 89 |
+
dummy_gpu_for_startup()
|
| 90 |
+
except BaseException as e:
|
| 91 |
+
err_msg = f"{type(e).__name__}: {str(e)}"
|
| 92 |
+
print(f"--- [GPU Startup] ⚠️ Warning: Startup check failed: {err_msg} ---")
|
| 93 |
+
|
| 94 |
+
print("--- Starting Application Setup ---")
|
| 95 |
+
|
| 96 |
+
print("--- Loading IPAdapter presets ---")
|
| 97 |
+
load_ipadapter_presets()
|
| 98 |
+
print("--- ✅ IPAdapter setup complete. ---")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
print("--- Environment configured. Proceeding with module imports. ---")
|
| 102 |
+
from ui.layout import build_ui
|
| 103 |
+
from ui.events import attach_event_handlers
|
| 104 |
+
if CONFIG.enable_mcp:
|
| 105 |
+
import mcp_tools as mcp
|
| 106 |
+
print(f"✅ Loaded MCP module with tools: {[fn.__name__ for fn in mcp.MCP_FUNCTIONS]}")
|
| 107 |
+
else:
|
| 108 |
+
print("ℹ️ MCP is disabled by IMAGEGEN_ENABLE_MCP.")
|
| 109 |
+
|
| 110 |
+
print(f"✅ Working directory is stable: {os.getcwd()}")
|
| 111 |
+
|
| 112 |
+
demo = build_ui(attach_event_handlers)
|
| 113 |
+
|
| 114 |
+
print(
|
| 115 |
+
"--- Launching Gradio Interface "
|
| 116 |
+
f"(GPU concurrency={CONFIG.gpu_concurrency}, queue={CONFIG.queue_max_size}, "
|
| 117 |
+
f"MCP={CONFIG.enable_mcp}) ---"
|
| 118 |
+
)
|
| 119 |
+
demo.queue(
|
| 120 |
+
default_concurrency_limit=1,
|
| 121 |
+
max_size=CONFIG.queue_max_size,
|
| 122 |
+
status_update_rate="auto",
|
| 123 |
+
).launch(mcp_server=CONFIG.enable_mcp)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
chain_injectors/__init__.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import importlib
|
| 3 |
+
import pkgutil
|
| 4 |
+
|
| 5 |
+
def discover_injectors():
|
| 6 |
+
injectors = {}
|
| 7 |
+
package_dir = os.path.dirname(__file__)
|
| 8 |
+
|
| 9 |
+
for _, module_name, is_pkg in pkgutil.iter_modules([package_dir]):
|
| 10 |
+
if is_pkg or module_name.startswith('_'):
|
| 11 |
+
continue
|
| 12 |
+
|
| 13 |
+
full_module_name = f"chain_injectors.{module_name}"
|
| 14 |
+
try:
|
| 15 |
+
module = importlib.import_module(full_module_name)
|
| 16 |
+
if hasattr(module, 'inject') and callable(module.inject):
|
| 17 |
+
feature_name = getattr(module, 'FEATURE_NAME', None)
|
| 18 |
+
if not feature_name:
|
| 19 |
+
feature_name = module_name[:-9] if module_name.endswith('_injector') else module_name
|
| 20 |
+
|
| 21 |
+
chain_type = getattr(module, 'CHAIN_TYPE', None)
|
| 22 |
+
if not chain_type:
|
| 23 |
+
chain_type = f"dynamic_{feature_name}_chains"
|
| 24 |
+
|
| 25 |
+
injectors[chain_type] = module.inject
|
| 26 |
+
else:
|
| 27 |
+
print(f"Warning: Module '{full_module_name}' does not have a callable 'inject' function.")
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error importing injector module '{full_module_name}': {e}")
|
| 30 |
+
|
| 31 |
+
return injectors
|
| 32 |
+
|
| 33 |
+
def get_registered_features():
|
| 34 |
+
features = {}
|
| 35 |
+
package_dir = os.path.dirname(__file__)
|
| 36 |
+
|
| 37 |
+
for _, module_name, is_pkg in pkgutil.iter_modules([package_dir]):
|
| 38 |
+
if is_pkg or module_name.startswith('_'):
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
feature_name = module_name[:-9] if module_name.endswith('_injector') else module_name
|
| 42 |
+
full_module_name = f"chain_injectors.{module_name}"
|
| 43 |
+
chain_type = f"dynamic_{feature_name}_chains"
|
| 44 |
+
|
| 45 |
+
features[feature_name] = {
|
| 46 |
+
'module': full_module_name,
|
| 47 |
+
'chain_type': chain_type
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
return features
|
chain_injectors/anima_controlnet_lllite_injector.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
if ksampler_name not in assembler.node_map:
|
| 7 |
+
print(f"Warning: KSampler node '{ksampler_name}' not found for Anima LLLite chain. Skipping.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 11 |
+
|
| 12 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 13 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping.")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 17 |
+
|
| 18 |
+
for item_data in chain_items:
|
| 19 |
+
image_loader_id = assembler._get_unique_id()
|
| 20 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 21 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 22 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 23 |
+
|
| 24 |
+
image_scaler_id = assembler._get_unique_id()
|
| 25 |
+
image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 26 |
+
image_scaler_node['inputs']['image'] = [image_loader_id, 0]
|
| 27 |
+
image_scaler_node['inputs']['upscale_method'] = 'nearest-exact'
|
| 28 |
+
image_scaler_node['inputs']['megapixels'] = 1.0
|
| 29 |
+
assembler.workflow[image_scaler_id] = image_scaler_node
|
| 30 |
+
|
| 31 |
+
patch_loader_id = assembler._get_unique_id()
|
| 32 |
+
patch_loader_node = assembler._get_node_template("ModelPatchLoader")
|
| 33 |
+
patch_loader_node['inputs']['name'] = item_data['control_net_name']
|
| 34 |
+
assembler.workflow[patch_loader_id] = patch_loader_node
|
| 35 |
+
|
| 36 |
+
apply_cn_id = assembler._get_unique_id()
|
| 37 |
+
apply_cn_node = assembler._get_node_template("AnimaLLLiteApply")
|
| 38 |
+
|
| 39 |
+
apply_cn_node['inputs']['strength'] = item_data['strength']
|
| 40 |
+
apply_cn_node['inputs']['start_percent'] = item_data.get('start_percent', 0.0)
|
| 41 |
+
apply_cn_node['inputs']['end_percent'] = item_data.get('end_percent', 1.0)
|
| 42 |
+
|
| 43 |
+
apply_cn_node['inputs']['model'] = current_model_connection
|
| 44 |
+
apply_cn_node['inputs']['model_patch'] = [patch_loader_id, 0]
|
| 45 |
+
apply_cn_node['inputs']['image'] = [image_scaler_id, 0]
|
| 46 |
+
|
| 47 |
+
assembler.workflow[apply_cn_id] = apply_cn_node
|
| 48 |
+
|
| 49 |
+
current_model_connection = [apply_cn_id, 0]
|
| 50 |
+
|
| 51 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection
|
| 52 |
+
|
| 53 |
+
print(f"Anima LLLite injector applied. KSampler model input re-routed through {len(chain_items)} LLLite(s).")
|
chain_injectors/boogu_image_edit_injector.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def create_node(assembler, class_type, title):
|
| 2 |
+
try:
|
| 3 |
+
node = assembler._get_node_template(class_type)
|
| 4 |
+
except Exception:
|
| 5 |
+
node = {
|
| 6 |
+
"inputs": {},
|
| 7 |
+
"class_type": class_type,
|
| 8 |
+
"_meta": {"title": title}
|
| 9 |
+
}
|
| 10 |
+
node['_meta']['title'] = title
|
| 11 |
+
return node
|
| 12 |
+
|
| 13 |
+
def inject(assembler, chain_definition, chain_items):
|
| 14 |
+
if not chain_items:
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
valid_images = []
|
| 18 |
+
for item in chain_items:
|
| 19 |
+
if not item:
|
| 20 |
+
continue
|
| 21 |
+
img_path = item
|
| 22 |
+
if isinstance(item, dict):
|
| 23 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 24 |
+
if img_path:
|
| 25 |
+
valid_images.append(img_path)
|
| 26 |
+
|
| 27 |
+
if not valid_images:
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
valid_images = valid_images[:10]
|
| 31 |
+
|
| 32 |
+
boogu_prompt_name = chain_definition.get('boogu_prompt_node', 'boogu_prompt')
|
| 33 |
+
vae_loader_name = chain_definition.get('vae_loader_node', 'vae_loader')
|
| 34 |
+
|
| 35 |
+
boogu_prompt_id = assembler.node_map.get(boogu_prompt_name)
|
| 36 |
+
if not boogu_prompt_id or boogu_prompt_id not in assembler.workflow:
|
| 37 |
+
for node_id, node in assembler.workflow.items():
|
| 38 |
+
if isinstance(node, dict) and node.get('class_type') == 'TextEncodeBooguEdit':
|
| 39 |
+
boogu_prompt_id = node_id
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
if not boogu_prompt_id:
|
| 43 |
+
print(f"Warning: Target node '{boogu_prompt_name}' (TextEncodeBooguEdit) for Boogu Edit chain not found. Skipping.")
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
vae_id = assembler.node_map.get(vae_loader_name)
|
| 47 |
+
if not vae_id:
|
| 48 |
+
for node_id, node in assembler.workflow.items():
|
| 49 |
+
if isinstance(node, dict) and node.get('class_type') == 'VAELoader':
|
| 50 |
+
vae_id = node_id
|
| 51 |
+
break
|
| 52 |
+
|
| 53 |
+
if vae_id:
|
| 54 |
+
assembler.workflow[boogu_prompt_id]['inputs']['vae'] = [vae_id, 0]
|
| 55 |
+
|
| 56 |
+
for i, img_filename in enumerate(valid_images):
|
| 57 |
+
load_id = assembler._get_unique_id()
|
| 58 |
+
load_node = create_node(assembler, "LoadImage", f"Load Reference Image {i+1}")
|
| 59 |
+
load_node['inputs']['image'] = img_filename
|
| 60 |
+
assembler.workflow[load_id] = load_node
|
| 61 |
+
|
| 62 |
+
scale_id = assembler._get_unique_id()
|
| 63 |
+
scale_node = create_node(assembler, "ImageScaleToTotalPixels", f"Scale Reference {i+1}")
|
| 64 |
+
scale_node['inputs']['upscale_method'] = "nearest-exact"
|
| 65 |
+
scale_node['inputs']['megapixels'] = 1
|
| 66 |
+
scale_node['inputs']['resolution_steps'] = 1
|
| 67 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 68 |
+
assembler.workflow[scale_id] = scale_node
|
| 69 |
+
|
| 70 |
+
image_key = f"images.image_{i+1}"
|
| 71 |
+
assembler.workflow[boogu_prompt_id]['inputs'][image_key] = [scale_id, 0]
|
| 72 |
+
|
| 73 |
+
print(f"Boogu Edit injector applied with {len(valid_images)} reference image(s). Connected VAE dynamically.")
|
chain_injectors/conditioning_injector.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
|
| 7 |
+
target_node_id = None
|
| 8 |
+
target_input_name = None
|
| 9 |
+
|
| 10 |
+
if ksampler_name in assembler.node_map:
|
| 11 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 12 |
+
if 'positive' in assembler.workflow[ksampler_id]['inputs']:
|
| 13 |
+
target_node_id = ksampler_id
|
| 14 |
+
target_input_name = 'positive'
|
| 15 |
+
print(f"Conditioning injector targeting KSampler node '{ksampler_name}'.")
|
| 16 |
+
else:
|
| 17 |
+
print(f"Warning: KSampler node '{ksampler_name}' for Conditioning chain not found. Skipping.")
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
if not target_node_id:
|
| 21 |
+
print("Warning: Conditioning chain could not find a valid injection point (KSampler may be missing 'positive' input). Skipping.")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
clip_source_str = chain_definition.get('clip_source')
|
| 25 |
+
if not clip_source_str:
|
| 26 |
+
print("Warning: 'clip_source' definition missing in the recipe for the Conditioning chain. Skipping.")
|
| 27 |
+
return
|
| 28 |
+
clip_node_name, clip_idx_str = clip_source_str.split(':')
|
| 29 |
+
if clip_node_name not in assembler.node_map:
|
| 30 |
+
print(f"Warning: CLIP source node '{clip_node_name}' for Conditioning chain not found. Skipping.")
|
| 31 |
+
return
|
| 32 |
+
clip_connection = [assembler.node_map[clip_node_name], int(clip_idx_str)]
|
| 33 |
+
|
| 34 |
+
original_positive_connection = assembler.workflow[target_node_id]['inputs'][target_input_name]
|
| 35 |
+
|
| 36 |
+
area_conditioning_outputs = []
|
| 37 |
+
|
| 38 |
+
for item_data in chain_items:
|
| 39 |
+
prompt = item_data.get('prompt', '')
|
| 40 |
+
if not prompt or not prompt.strip():
|
| 41 |
+
continue
|
| 42 |
+
|
| 43 |
+
text_encode_id = assembler._get_unique_id()
|
| 44 |
+
text_encode_node = assembler._get_node_template("CLIPTextEncode")
|
| 45 |
+
text_encode_node['inputs']['text'] = prompt
|
| 46 |
+
text_encode_node['inputs']['clip'] = clip_connection
|
| 47 |
+
assembler.workflow[text_encode_id] = text_encode_node
|
| 48 |
+
|
| 49 |
+
set_area_id = assembler._get_unique_id()
|
| 50 |
+
set_area_node = assembler._get_node_template("ConditioningSetArea")
|
| 51 |
+
set_area_node['inputs']['width'] = item_data.get('width', 1024)
|
| 52 |
+
set_area_node['inputs']['height'] = item_data.get('height', 1024)
|
| 53 |
+
set_area_node['inputs']['x'] = item_data.get('x', 0)
|
| 54 |
+
set_area_node['inputs']['y'] = item_data.get('y', 0)
|
| 55 |
+
set_area_node['inputs']['strength'] = item_data.get('strength', 1.0)
|
| 56 |
+
set_area_node['inputs']['conditioning'] = [text_encode_id, 0]
|
| 57 |
+
assembler.workflow[set_area_id] = set_area_node
|
| 58 |
+
|
| 59 |
+
area_conditioning_outputs.append([set_area_id, 0])
|
| 60 |
+
|
| 61 |
+
if not area_conditioning_outputs:
|
| 62 |
+
return
|
| 63 |
+
|
| 64 |
+
current_combined_conditioning = area_conditioning_outputs[0]
|
| 65 |
+
if len(area_conditioning_outputs) > 1:
|
| 66 |
+
for i in range(1, len(area_conditioning_outputs)):
|
| 67 |
+
combine_id = assembler._get_unique_id()
|
| 68 |
+
combine_node = assembler._get_node_template("ConditioningCombine")
|
| 69 |
+
combine_node['inputs']['conditioning_1'] = current_combined_conditioning
|
| 70 |
+
combine_node['inputs']['conditioning_2'] = area_conditioning_outputs[i]
|
| 71 |
+
assembler.workflow[combine_id] = combine_node
|
| 72 |
+
current_combined_conditioning = [combine_id, 0]
|
| 73 |
+
|
| 74 |
+
final_combine_id = assembler._get_unique_id()
|
| 75 |
+
final_combine_node = assembler._get_node_template("ConditioningCombine")
|
| 76 |
+
final_combine_node['inputs']['conditioning_1'] = original_positive_connection
|
| 77 |
+
final_combine_node['inputs']['conditioning_2'] = current_combined_conditioning
|
| 78 |
+
assembler.workflow[final_combine_id] = final_combine_node
|
| 79 |
+
|
| 80 |
+
assembler.workflow[target_node_id]['inputs'][target_input_name] = [final_combine_id, 0]
|
| 81 |
+
print(f"Conditioning injector applied. Redirected '{target_input_name}' input with {len(area_conditioning_outputs)} regional prompts.")
|
chain_injectors/controlnet_injector.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
if ksampler_name not in assembler.node_map:
|
| 7 |
+
print(f"Warning: Target node '{ksampler_name}' for ControlNet chain not found. Skipping chain injection.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 11 |
+
|
| 12 |
+
if 'positive' not in assembler.workflow[ksampler_id]['inputs'] or \
|
| 13 |
+
'negative' not in assembler.workflow[ksampler_id]['inputs']:
|
| 14 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'positive' or 'negative' inputs. Skipping ControlNet chain.")
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
vae_source_str = chain_definition.get('vae_source')
|
| 18 |
+
if not vae_source_str:
|
| 19 |
+
print("Warning: 'vae_source' definition missing in the recipe for the ControlNet chain. Skipping.")
|
| 20 |
+
return
|
| 21 |
+
vae_node_name, vae_idx_str = vae_source_str.split(':')
|
| 22 |
+
if vae_node_name not in assembler.node_map:
|
| 23 |
+
print(f"Warning: VAE source node '{vae_node_name}' for ControlNet chain not found. Skipping.")
|
| 24 |
+
return
|
| 25 |
+
vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)]
|
| 26 |
+
|
| 27 |
+
current_positive_connection = assembler.workflow[ksampler_id]['inputs']['positive']
|
| 28 |
+
current_negative_connection = assembler.workflow[ksampler_id]['inputs']['negative']
|
| 29 |
+
|
| 30 |
+
for item_data in chain_items:
|
| 31 |
+
cn_loader_id = assembler._get_unique_id()
|
| 32 |
+
cn_loader_node = assembler._get_node_template("ControlNetLoader")
|
| 33 |
+
cn_loader_node['inputs']['control_net_name'] = item_data['control_net_name']
|
| 34 |
+
assembler.workflow[cn_loader_id] = cn_loader_node
|
| 35 |
+
|
| 36 |
+
image_loader_id = assembler._get_unique_id()
|
| 37 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 38 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 39 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 40 |
+
|
| 41 |
+
apply_cn_id = assembler._get_unique_id()
|
| 42 |
+
apply_cn_node = assembler._get_node_template(chain_definition['template'])
|
| 43 |
+
|
| 44 |
+
apply_cn_node['inputs']['strength'] = item_data['strength']
|
| 45 |
+
|
| 46 |
+
apply_cn_node['inputs']['positive'] = current_positive_connection
|
| 47 |
+
apply_cn_node['inputs']['negative'] = current_negative_connection
|
| 48 |
+
apply_cn_node['inputs']['control_net'] = [cn_loader_id, 0]
|
| 49 |
+
apply_cn_node['inputs']['image'] = [image_loader_id, 0]
|
| 50 |
+
apply_cn_node['inputs']['vae'] = vae_connection
|
| 51 |
+
|
| 52 |
+
assembler.workflow[apply_cn_id] = apply_cn_node
|
| 53 |
+
|
| 54 |
+
current_positive_connection = [apply_cn_id, 0]
|
| 55 |
+
current_negative_connection = [apply_cn_id, 1]
|
| 56 |
+
|
| 57 |
+
assembler.workflow[ksampler_id]['inputs']['positive'] = current_positive_connection
|
| 58 |
+
assembler.workflow[ksampler_id]['inputs']['negative'] = current_negative_connection
|
| 59 |
+
|
| 60 |
+
print(f"ControlNet injector applied. KSampler inputs redirected through {len(chain_items)} ControlNet nodes.")
|
chain_injectors/diffsynth_controlnet_injector.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
model_sampler_name = chain_definition.get('model_sampler_node')
|
| 6 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 7 |
+
|
| 8 |
+
target_node_id = None
|
| 9 |
+
target_input_name = 'model'
|
| 10 |
+
|
| 11 |
+
if model_sampler_name and model_sampler_name in assembler.node_map:
|
| 12 |
+
model_sampler_id = assembler.node_map[model_sampler_name]
|
| 13 |
+
if target_input_name in assembler.workflow[model_sampler_id]['inputs']:
|
| 14 |
+
target_node_id = model_sampler_id
|
| 15 |
+
print(f"ControlNet Model Patch injector targeting ModelSamplingAuraFlow node '{model_sampler_name}'.")
|
| 16 |
+
|
| 17 |
+
if not target_node_id:
|
| 18 |
+
if ksampler_name in assembler.node_map:
|
| 19 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 20 |
+
if target_input_name in assembler.workflow[ksampler_id]['inputs']:
|
| 21 |
+
target_node_id = ksampler_id
|
| 22 |
+
print(f"ControlNet Model Patch injector targeting KSampler node '{ksampler_name}'.")
|
| 23 |
+
else:
|
| 24 |
+
print(f"Warning: Neither ModelSamplingAuraFlow node '{model_sampler_name}' nor KSampler node '{ksampler_name}' found for ControlNet patch chain. Skipping.")
|
| 25 |
+
return
|
| 26 |
+
|
| 27 |
+
if not target_node_id:
|
| 28 |
+
print(f"Warning: Could not find a valid 'model' input on target nodes. Skipping ControlNet patch chain.")
|
| 29 |
+
return
|
| 30 |
+
|
| 31 |
+
current_model_connection = assembler.workflow[target_node_id]['inputs'][target_input_name]
|
| 32 |
+
|
| 33 |
+
vae_source_str = chain_definition.get('vae_source')
|
| 34 |
+
vae_connection = None
|
| 35 |
+
if vae_source_str:
|
| 36 |
+
try:
|
| 37 |
+
vae_node_name, vae_idx_str = vae_source_str.split(':')
|
| 38 |
+
if vae_node_name in assembler.node_map:
|
| 39 |
+
vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)]
|
| 40 |
+
else:
|
| 41 |
+
print(f"Warning: VAE source node '{vae_node_name}' not found for ControlNet patch chain. VAE will not be connected.")
|
| 42 |
+
except ValueError:
|
| 43 |
+
print(f"Warning: Invalid 'vae_source' format '{vae_source_str}' for ControlNet patch chain. Expected 'node_name:index'. VAE will not be connected.")
|
| 44 |
+
else:
|
| 45 |
+
print(f"Warning: 'vae_source' not defined for ControlNet patch chain definition. VAE may not be connected.")
|
| 46 |
+
|
| 47 |
+
for item_data in chain_items:
|
| 48 |
+
patch_loader_id = assembler._get_unique_id()
|
| 49 |
+
patch_loader_node = assembler._get_node_template("ModelPatchLoader")
|
| 50 |
+
patch_loader_node['inputs']['name'] = item_data['control_net_name']
|
| 51 |
+
assembler.workflow[patch_loader_id] = patch_loader_node
|
| 52 |
+
|
| 53 |
+
image_loader_id = assembler._get_unique_id()
|
| 54 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 55 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 56 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 57 |
+
|
| 58 |
+
apply_cn_id = assembler._get_unique_id()
|
| 59 |
+
apply_cn_node = assembler._get_node_template(chain_definition['template'])
|
| 60 |
+
|
| 61 |
+
apply_cn_node['inputs']['strength'] = item_data.get('strength', 1.0)
|
| 62 |
+
apply_cn_node['inputs']['model'] = current_model_connection
|
| 63 |
+
apply_cn_node['inputs']['model_patch'] = [patch_loader_id, 0]
|
| 64 |
+
apply_cn_node['inputs']['image'] = [image_loader_id, 0]
|
| 65 |
+
|
| 66 |
+
if 'vae' in apply_cn_node['inputs'] and vae_connection:
|
| 67 |
+
apply_cn_node['inputs']['vae'] = vae_connection
|
| 68 |
+
|
| 69 |
+
assembler.workflow[apply_cn_id] = apply_cn_node
|
| 70 |
+
|
| 71 |
+
current_model_connection = [apply_cn_id, 0]
|
| 72 |
+
|
| 73 |
+
assembler.workflow[target_node_id]['inputs'][target_input_name] = current_model_connection
|
| 74 |
+
|
| 75 |
+
print(f"ControlNet Model Patch injector applied. Target 'model' input re-routed through {len(chain_items)} patch(es).")
|
chain_injectors/flux1_ipadapter_injector.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
if ksampler_name not in assembler.node_map:
|
| 7 |
+
print(f"Warning: KSampler node '{ksampler_name}' not found for Flux1 IPAdapter chain. Skipping.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 11 |
+
|
| 12 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 13 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping Flux1 IPAdapter chain.")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 17 |
+
|
| 18 |
+
for item_data in chain_items:
|
| 19 |
+
image_loader_id = assembler._get_unique_id()
|
| 20 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 21 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 22 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 23 |
+
|
| 24 |
+
ipadapter_loader_id = assembler._get_unique_id()
|
| 25 |
+
ipadapter_loader_node = assembler._get_node_template("IPAdapterFluxLoader")
|
| 26 |
+
ipadapter_loader_node['inputs']['ipadapter'] = "ip-adapter.bin"
|
| 27 |
+
ipadapter_loader_node['inputs']['clip_vision'] = "google/siglip-so400m-patch14-384"
|
| 28 |
+
ipadapter_loader_node['inputs']['provider'] = "cuda"
|
| 29 |
+
assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node
|
| 30 |
+
|
| 31 |
+
apply_ipa_id = assembler._get_unique_id()
|
| 32 |
+
apply_ipa_node = assembler._get_node_template("ApplyIPAdapterFlux")
|
| 33 |
+
|
| 34 |
+
apply_ipa_node['inputs']['weight'] = item_data['weight']
|
| 35 |
+
apply_ipa_node['inputs']['start_percent'] = item_data.get('start_percent', 0.0)
|
| 36 |
+
apply_ipa_node['inputs']['end_percent'] = item_data.get('end_percent', 0.6)
|
| 37 |
+
|
| 38 |
+
apply_ipa_node['inputs']['model'] = current_model_connection
|
| 39 |
+
apply_ipa_node['inputs']['ipadapter_flux'] = [ipadapter_loader_id, 0]
|
| 40 |
+
apply_ipa_node['inputs']['image'] = [image_loader_id, 0]
|
| 41 |
+
|
| 42 |
+
assembler.workflow[apply_ipa_id] = apply_ipa_node
|
| 43 |
+
current_model_connection = [apply_ipa_id, 0]
|
| 44 |
+
|
| 45 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection
|
| 46 |
+
print(f"Flux1 IPAdapter injector applied. KSampler model input re-routed through {len(chain_items)} IPAdapter(s).")
|
chain_injectors/hidream_o1_reference_injector.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
|
| 7 |
+
if ksampler_name not in assembler.node_map:
|
| 8 |
+
print(f"Warning: KSampler node '{ksampler_name}' not found for HiDream-O1 Reference chain. Skipping.")
|
| 9 |
+
return
|
| 10 |
+
|
| 11 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 12 |
+
|
| 13 |
+
if 'positive' not in assembler.workflow[ksampler_id]['inputs'] or 'negative' not in assembler.workflow[ksampler_id]['inputs']:
|
| 14 |
+
print(f"Warning: KSampler node '{ksampler_name}' missing positive/negative inputs. Skipping.")
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
current_pos_conditioning = assembler.workflow[ksampler_id]['inputs']['positive']
|
| 18 |
+
current_neg_conditioning = assembler.workflow[ksampler_id]['inputs']['negative']
|
| 19 |
+
|
| 20 |
+
ref_images_id = assembler._get_unique_id()
|
| 21 |
+
ref_images_node = assembler._get_node_template("HiDreamO1ReferenceImages")
|
| 22 |
+
|
| 23 |
+
if 'images' in ref_images_node['inputs']:
|
| 24 |
+
del ref_images_node['inputs']['images']
|
| 25 |
+
|
| 26 |
+
ref_images_node['inputs']['positive'] = current_pos_conditioning
|
| 27 |
+
ref_images_node['inputs']['negative'] = current_neg_conditioning
|
| 28 |
+
|
| 29 |
+
for i, img_filename in enumerate(chain_items):
|
| 30 |
+
if i >= 10:
|
| 31 |
+
break
|
| 32 |
+
|
| 33 |
+
load_id = assembler._get_unique_id()
|
| 34 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 35 |
+
load_node['inputs']['image'] = img_filename
|
| 36 |
+
load_node['_meta']['title'] = f"Load Reference Image {i+1}"
|
| 37 |
+
assembler.workflow[load_id] = load_node
|
| 38 |
+
|
| 39 |
+
scale_id = assembler._get_unique_id()
|
| 40 |
+
scale_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 41 |
+
scale_node['inputs']['megapixels'] = 1.0
|
| 42 |
+
scale_node['inputs']['upscale_method'] = "lanczos"
|
| 43 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 44 |
+
scale_node['_meta']['title'] = f"Scale Reference {i+1}"
|
| 45 |
+
assembler.workflow[scale_id] = scale_node
|
| 46 |
+
|
| 47 |
+
ref_images_node['inputs'][f'images.image_{i+1}'] = [scale_id, 0]
|
| 48 |
+
|
| 49 |
+
assembler.workflow[ref_images_id] = ref_images_node
|
| 50 |
+
|
| 51 |
+
assembler.workflow[ksampler_id]['inputs']['positive'] = [ref_images_id, 0]
|
| 52 |
+
assembler.workflow[ksampler_id]['inputs']['negative'] = [ref_images_id, 1]
|
| 53 |
+
|
| 54 |
+
print(f"HiDream-O1 Reference injector applied. Re-routed inputs through {min(len(chain_items), 10)} reference images.")
|
chain_injectors/hidream_o1_smoothing_injector.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from copy import deepcopy
|
| 2 |
+
|
| 3 |
+
def inject(assembler, chain_definition, chain_items):
|
| 4 |
+
if not chain_items:
|
| 5 |
+
return
|
| 6 |
+
|
| 7 |
+
target_node_name = chain_definition.get('target_node')
|
| 8 |
+
if not target_node_name or target_node_name not in assembler.node_map:
|
| 9 |
+
print(f"Warning: Target node '{target_node_name}' not found for HiDream-O1 Smoothing. Skipping.")
|
| 10 |
+
return
|
| 11 |
+
|
| 12 |
+
target_node_id = assembler.node_map[target_node_name]
|
| 13 |
+
|
| 14 |
+
if 'model' not in assembler.workflow[target_node_id]['inputs']:
|
| 15 |
+
print(f"Warning: Target node '{target_node_name}' has no 'model' input. Skipping.")
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
+
current_model_connection = assembler.workflow[target_node_id]['inputs']['model']
|
| 19 |
+
|
| 20 |
+
for _ in chain_items:
|
| 21 |
+
template = assembler._get_node_template("HiDreamO1PatchSeamSmoothing")
|
| 22 |
+
node_data = deepcopy(template)
|
| 23 |
+
|
| 24 |
+
node_data['inputs']['start_percent'] = 0.8
|
| 25 |
+
node_data['inputs']['end_percent'] = 1.0
|
| 26 |
+
node_data['inputs']['pattern'] = "single_shift"
|
| 27 |
+
node_data['inputs']['passes'] = "ramp_2_4"
|
| 28 |
+
node_data['inputs']['blend'] = "median"
|
| 29 |
+
node_data['inputs']['strength'] = 1.0
|
| 30 |
+
|
| 31 |
+
node_data['inputs']['model'] = current_model_connection
|
| 32 |
+
|
| 33 |
+
new_node_id = assembler._get_unique_id()
|
| 34 |
+
assembler.workflow[new_node_id] = node_data
|
| 35 |
+
|
| 36 |
+
current_model_connection = [new_node_id, 0]
|
| 37 |
+
|
| 38 |
+
assembler.workflow[target_node_id]['inputs']['model'] = current_model_connection
|
| 39 |
+
print("HiDream-O1 Patch Seam Smoothing injector applied.")
|
chain_injectors/ipadapter_injector.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
final_settings = {}
|
| 6 |
+
if chain_items and isinstance(chain_items[-1], dict) and chain_items[-1].get('is_final_settings'):
|
| 7 |
+
final_settings = chain_items.pop()
|
| 8 |
+
|
| 9 |
+
if not chain_items:
|
| 10 |
+
return
|
| 11 |
+
|
| 12 |
+
end_node_name = chain_definition.get('end')
|
| 13 |
+
if not end_node_name or end_node_name not in assembler.node_map:
|
| 14 |
+
print(f"Warning: Target node '{end_node_name}' for IPAdapter chain not found. Skipping chain injection.")
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
end_node_id = assembler.node_map[end_node_name]
|
| 18 |
+
|
| 19 |
+
if 'model' not in assembler.workflow[end_node_id]['inputs']:
|
| 20 |
+
print(f"Warning: Target node '{end_node_name}' is missing 'model' input. Skipping IPAdapter chain.")
|
| 21 |
+
return
|
| 22 |
+
|
| 23 |
+
current_model_connection = assembler.workflow[end_node_id]['inputs']['model']
|
| 24 |
+
|
| 25 |
+
model_type = final_settings.get('model_type', 'sdxl')
|
| 26 |
+
megapixels = 1.05 if model_type == 'sdxl' else 0.39
|
| 27 |
+
|
| 28 |
+
first_preset = chain_items[0].get('preset', '')
|
| 29 |
+
is_faceid_chain = 'FACEID' in first_preset.upper()
|
| 30 |
+
|
| 31 |
+
if is_faceid_chain:
|
| 32 |
+
for i, item_data in enumerate(chain_items):
|
| 33 |
+
image_loader_id = assembler._get_unique_id()
|
| 34 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 35 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 36 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 37 |
+
|
| 38 |
+
image_scaler_id = assembler._get_unique_id()
|
| 39 |
+
image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 40 |
+
image_scaler_node['inputs']['image'] = [image_loader_id, 0]
|
| 41 |
+
image_scaler_node['inputs']['megapixels'] = megapixels
|
| 42 |
+
image_scaler_node['inputs']['upscale_method'] = "lanczos"
|
| 43 |
+
assembler.workflow[image_scaler_id] = image_scaler_node
|
| 44 |
+
|
| 45 |
+
ipadapter_loader_id = assembler._get_unique_id()
|
| 46 |
+
ipadapter_loader_node = assembler._get_node_template("IPAdapterUnifiedLoaderFaceID")
|
| 47 |
+
ipadapter_loader_node['inputs']['model'] = current_model_connection
|
| 48 |
+
ipadapter_loader_node['inputs']['preset'] = item_data['preset']
|
| 49 |
+
ipadapter_loader_node['inputs']['lora_strength'] = item_data.get('lora_strength', 0.6)
|
| 50 |
+
ipadapter_loader_node['inputs']['provider'] = "CUDA"
|
| 51 |
+
assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node
|
| 52 |
+
|
| 53 |
+
apply_id = assembler._get_unique_id()
|
| 54 |
+
apply_node = assembler._get_node_template("IPAdapterFaceID")
|
| 55 |
+
apply_node['inputs']['model'] = [ipadapter_loader_id, 0]
|
| 56 |
+
apply_node['inputs']['ipadapter'] = [ipadapter_loader_id, 1]
|
| 57 |
+
apply_node['inputs']['image'] = [image_scaler_id, 0]
|
| 58 |
+
apply_node['inputs']['weight'] = item_data['weight']
|
| 59 |
+
apply_node['inputs']['weight_faceidv2'] = final_settings.get('final_lora_strength', 0.6)
|
| 60 |
+
apply_node['inputs']['weight_type'] = "linear"
|
| 61 |
+
apply_node['inputs']['combine_embeds'] = final_settings.get('final_combine_method', 'concat')
|
| 62 |
+
apply_node['inputs']['start_at'] = item_data.get('start_percent', 0.0)
|
| 63 |
+
apply_node['inputs']['end_at'] = item_data.get('end_percent', 1.0)
|
| 64 |
+
apply_node['inputs']['embeds_scaling'] = final_settings.get('final_embeds_scaling', 'V only')
|
| 65 |
+
|
| 66 |
+
assembler.workflow[apply_id] = apply_node
|
| 67 |
+
current_model_connection = [apply_id, 0]
|
| 68 |
+
|
| 69 |
+
assembler.workflow[end_node_id]['inputs']['model'] = current_model_connection
|
| 70 |
+
print(f"IPAdapter FaceID injector applied (Direct Apply). Redirected '{end_node_name}' model input through {len(chain_items)} FaceID node(s).")
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
else:
|
| 74 |
+
pos_embed_outputs = []
|
| 75 |
+
neg_embed_outputs = []
|
| 76 |
+
|
| 77 |
+
for i, item_data in enumerate(chain_items):
|
| 78 |
+
loader_type = 'FaceID' if 'FACEID' in item_data.get('preset', '') else 'Unified'
|
| 79 |
+
loader_template_name = "IPAdapterUnifiedLoader"
|
| 80 |
+
if loader_type == 'FaceID':
|
| 81 |
+
loader_template_name = "IPAdapterUnifiedLoaderFaceID"
|
| 82 |
+
|
| 83 |
+
image_loader_id = assembler._get_unique_id()
|
| 84 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 85 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 86 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 87 |
+
|
| 88 |
+
image_scaler_id = assembler._get_unique_id()
|
| 89 |
+
image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 90 |
+
image_scaler_node['inputs']['image'] = [image_loader_id, 0]
|
| 91 |
+
image_scaler_node['inputs']['megapixels'] = megapixels
|
| 92 |
+
image_scaler_node['inputs']['upscale_method'] = "lanczos"
|
| 93 |
+
assembler.workflow[image_scaler_id] = image_scaler_node
|
| 94 |
+
|
| 95 |
+
ipadapter_loader_id = assembler._get_unique_id()
|
| 96 |
+
ipadapter_loader_node = assembler._get_node_template(loader_template_name)
|
| 97 |
+
ipadapter_loader_node['inputs']['model'] = current_model_connection
|
| 98 |
+
ipadapter_loader_node['inputs']['preset'] = item_data['preset']
|
| 99 |
+
if loader_type == 'FaceID':
|
| 100 |
+
ipadapter_loader_node['inputs']['lora_strength'] = item_data.get('lora_strength', 0.6)
|
| 101 |
+
assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node
|
| 102 |
+
|
| 103 |
+
encoder_id = assembler._get_unique_id()
|
| 104 |
+
encoder_node = assembler._get_node_template("IPAdapterEncoder")
|
| 105 |
+
encoder_node['inputs']['weight'] = item_data['weight']
|
| 106 |
+
encoder_node['inputs']['ipadapter'] = [ipadapter_loader_id, 1]
|
| 107 |
+
encoder_node['inputs']['image'] = [image_scaler_id, 0]
|
| 108 |
+
assembler.workflow[encoder_id] = encoder_node
|
| 109 |
+
|
| 110 |
+
pos_embed_outputs.append([encoder_id, 0])
|
| 111 |
+
neg_embed_outputs.append([encoder_id, 1])
|
| 112 |
+
|
| 113 |
+
pos_combiner_id = assembler._get_unique_id()
|
| 114 |
+
pos_combiner_node = assembler._get_node_template("IPAdapterCombineEmbeds")
|
| 115 |
+
pos_combiner_node['inputs']['method'] = final_settings.get('final_combine_method', 'concat')
|
| 116 |
+
for i, conn in enumerate(pos_embed_outputs):
|
| 117 |
+
pos_combiner_node['inputs'][f'embed{i+1}'] = conn
|
| 118 |
+
assembler.workflow[pos_combiner_id] = pos_combiner_node
|
| 119 |
+
|
| 120 |
+
neg_combiner_id = assembler._get_unique_id()
|
| 121 |
+
neg_combiner_node = assembler._get_node_template("IPAdapterCombineEmbeds")
|
| 122 |
+
neg_combiner_node['inputs']['method'] = final_settings.get('final_combine_method', 'concat')
|
| 123 |
+
for i, conn in enumerate(neg_embed_outputs):
|
| 124 |
+
neg_combiner_node['inputs'][f'embed{i+1}'] = conn
|
| 125 |
+
assembler.workflow[neg_combiner_id] = neg_combiner_node
|
| 126 |
+
|
| 127 |
+
final_loader_type = 'FaceID' if 'FACEID' in final_settings.get('final_preset', '') else 'Unified'
|
| 128 |
+
final_loader_template_name = "IPAdapterUnifiedLoader"
|
| 129 |
+
if final_loader_type == 'FaceID':
|
| 130 |
+
final_loader_template_name = "IPAdapterUnifiedLoaderFaceID"
|
| 131 |
+
|
| 132 |
+
final_loader_id = assembler._get_unique_id()
|
| 133 |
+
final_loader_node = assembler._get_node_template(final_loader_template_name)
|
| 134 |
+
final_loader_node['inputs']['model'] = current_model_connection
|
| 135 |
+
final_loader_node['inputs']['preset'] = final_settings.get('final_preset', 'STANDARD (medium strength)')
|
| 136 |
+
if final_loader_type == 'FaceID':
|
| 137 |
+
final_loader_node['inputs']['lora_strength'] = final_settings.get('final_lora_strength', 0.6)
|
| 138 |
+
assembler.workflow[final_loader_id] = final_loader_node
|
| 139 |
+
|
| 140 |
+
apply_embeds_id = assembler._get_unique_id()
|
| 141 |
+
apply_embeds_node = assembler._get_node_template("IPAdapterEmbeds")
|
| 142 |
+
apply_embeds_node['inputs']['weight'] = final_settings.get('final_weight', 1.0)
|
| 143 |
+
apply_embeds_node['inputs']['embeds_scaling'] = final_settings.get('final_embeds_scaling', 'V only')
|
| 144 |
+
apply_embeds_node['inputs']['model'] = [final_loader_id, 0]
|
| 145 |
+
apply_embeds_node['inputs']['ipadapter'] = [final_loader_id, 1]
|
| 146 |
+
apply_embeds_node['inputs']['pos_embed'] = [pos_combiner_id, 0]
|
| 147 |
+
apply_embeds_node['inputs']['neg_embed'] = [neg_combiner_id, 0]
|
| 148 |
+
assembler.workflow[apply_embeds_id] = apply_embeds_node
|
| 149 |
+
|
| 150 |
+
assembler.workflow[end_node_id]['inputs']['model'] = [apply_embeds_id, 0]
|
| 151 |
+
print(f"IPAdapter Unified injector applied. Redirected '{end_node_name}' model input through {len(chain_items)} reference image(s).")
|
chain_injectors/joyai_image_injector.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
def inject(assembler, chain_definition, chain_items):
|
| 4 |
+
if not chain_items:
|
| 5 |
+
return
|
| 6 |
+
|
| 7 |
+
valid_images = []
|
| 8 |
+
for item in chain_items:
|
| 9 |
+
if not item:
|
| 10 |
+
continue
|
| 11 |
+
img_path = item
|
| 12 |
+
if isinstance(item, dict):
|
| 13 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 14 |
+
if img_path:
|
| 15 |
+
valid_images.append(img_path)
|
| 16 |
+
|
| 17 |
+
if not valid_images:
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
valid_images = valid_images[:2]
|
| 21 |
+
|
| 22 |
+
pos_prompt_name = chain_definition.get('pos_prompt_node', 'pos_prompt')
|
| 23 |
+
neg_prompt_name = chain_definition.get('neg_prompt_node', 'neg_prompt')
|
| 24 |
+
vae_node_name = chain_definition.get('vae_node', 'vae_loader')
|
| 25 |
+
|
| 26 |
+
if pos_prompt_name not in assembler.node_map:
|
| 27 |
+
print(f"Warning: Positive prompt node '{pos_prompt_name}' not found for JoyAI Reference chain. Skipping.")
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
if vae_node_name not in assembler.node_map:
|
| 31 |
+
print(f"Warning: VAE loader node '{vae_node_name}' not found for JoyAI Reference chain. Skipping.")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
pos_prompt_id = assembler.node_map[pos_prompt_name]
|
| 35 |
+
neg_prompt_id = assembler.node_map.get(neg_prompt_name)
|
| 36 |
+
vae_node_id = assembler.node_map[vae_node_name]
|
| 37 |
+
|
| 38 |
+
assembler.workflow[pos_prompt_id]['inputs']['vae'] = [vae_node_id, 0]
|
| 39 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 40 |
+
assembler.workflow[neg_prompt_id]['inputs']['vae'] = [vae_node_id, 0]
|
| 41 |
+
|
| 42 |
+
for i, img_filename in enumerate(valid_images):
|
| 43 |
+
load_id = assembler._get_unique_id()
|
| 44 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 45 |
+
load_node['inputs']['image'] = img_filename
|
| 46 |
+
load_node['_meta']['title'] = f"Load Reference Image {i+1}"
|
| 47 |
+
assembler.workflow[load_id] = load_node
|
| 48 |
+
|
| 49 |
+
scale_id = assembler._get_unique_id()
|
| 50 |
+
scale_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 51 |
+
scale_node['inputs']['megapixels'] = 1.0
|
| 52 |
+
scale_node['inputs']['upscale_method'] = "nearest-exact"
|
| 53 |
+
scale_node['inputs']['resolution_steps'] = 1
|
| 54 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 55 |
+
scale_node['_meta']['title'] = f"Scale Reference {i+1}"
|
| 56 |
+
assembler.workflow[scale_id] = scale_node
|
| 57 |
+
|
| 58 |
+
input_key = f"images.image{i}"
|
| 59 |
+
assembler.workflow[pos_prompt_id]['inputs'][input_key] = [scale_id, 0]
|
| 60 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 61 |
+
assembler.workflow[neg_prompt_id]['inputs'][input_key] = [scale_id, 0]
|
| 62 |
+
|
| 63 |
+
print(f"JoyAI Reference injector applied. Injected {len(valid_images)} reference images to JoyAI text encoding nodes.")
|
chain_injectors/krea2_controlnet_injector.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
if ksampler_name not in assembler.node_map:
|
| 7 |
+
print(f"Warning: Target node '{ksampler_name}' for Krea2 ControlNet chain not found. Skipping.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 11 |
+
|
| 12 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 13 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping.")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
vae_source_str = chain_definition.get('vae_source')
|
| 17 |
+
vae_connection = None
|
| 18 |
+
if vae_source_str:
|
| 19 |
+
vae_node_name, vae_idx_str = vae_source_str.split(':')
|
| 20 |
+
if vae_node_name in assembler.node_map:
|
| 21 |
+
vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)]
|
| 22 |
+
|
| 23 |
+
latent_connection = assembler.workflow[ksampler_id]['inputs'].get('latent_image')
|
| 24 |
+
if not latent_connection:
|
| 25 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'latent_image' input. Krea2 ControlNet requires it. Skipping.")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 29 |
+
|
| 30 |
+
for item_data in chain_items:
|
| 31 |
+
image_loader_id = assembler._get_unique_id()
|
| 32 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 33 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 34 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 35 |
+
|
| 36 |
+
image_scaler_id = assembler._get_unique_id()
|
| 37 |
+
image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 38 |
+
image_scaler_node['inputs']['image'] = [image_loader_id, 0]
|
| 39 |
+
image_scaler_node['inputs']['upscale_method'] = 'nearest-exact'
|
| 40 |
+
image_scaler_node['inputs']['megapixels'] = 1.0
|
| 41 |
+
image_scaler_node['inputs']['resolution_steps'] = 1
|
| 42 |
+
assembler.workflow[image_scaler_id] = image_scaler_node
|
| 43 |
+
|
| 44 |
+
lora_loader_id = assembler._get_unique_id()
|
| 45 |
+
lora_loader_node = assembler._get_node_template("Krea2ControlLoRALoader")
|
| 46 |
+
lora_loader_node['inputs']['lora_name'] = item_data['control_net_name']
|
| 47 |
+
lora_loader_node['inputs']['strength'] = item_data.get('strength', 1.0)
|
| 48 |
+
lora_loader_node['inputs']['model'] = current_model_connection
|
| 49 |
+
assembler.workflow[lora_loader_id] = lora_loader_node
|
| 50 |
+
|
| 51 |
+
img_encode_id = assembler._get_unique_id()
|
| 52 |
+
img_encode_node = assembler._get_node_template("Krea2ControlImageEncode")
|
| 53 |
+
img_encode_node['inputs']['resize'] = "match_latent_size"
|
| 54 |
+
img_encode_node['inputs']['upscale_method'] = "lanczos"
|
| 55 |
+
img_encode_node['inputs']['crop'] = "center"
|
| 56 |
+
img_encode_node['inputs']['channel_mode'] = "rgb"
|
| 57 |
+
img_encode_node['inputs']['normalize'] = "none"
|
| 58 |
+
img_encode_node['inputs']['invert'] = False
|
| 59 |
+
img_encode_node['inputs']['batch_mode'] = "independent_images"
|
| 60 |
+
img_encode_node['inputs']['control_image'] = [image_scaler_id, 0]
|
| 61 |
+
if vae_connection:
|
| 62 |
+
img_encode_node['inputs']['vae'] = vae_connection
|
| 63 |
+
if latent_connection:
|
| 64 |
+
img_encode_node['inputs']['latent'] = latent_connection
|
| 65 |
+
assembler.workflow[img_encode_id] = img_encode_node
|
| 66 |
+
|
| 67 |
+
apply_cn_id = assembler._get_unique_id()
|
| 68 |
+
apply_cn_node = assembler._get_node_template("Krea2ControlApply")
|
| 69 |
+
apply_cn_node['inputs']['model'] = [lora_loader_id, 0]
|
| 70 |
+
apply_cn_node['inputs']['control_latent'] = [img_encode_id, 0]
|
| 71 |
+
|
| 72 |
+
assembler.workflow[apply_cn_id] = apply_cn_node
|
| 73 |
+
|
| 74 |
+
current_model_connection = [apply_cn_id, 0]
|
| 75 |
+
|
| 76 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection
|
| 77 |
+
|
| 78 |
+
print(f"Krea2 ControlNet injector applied. KSampler model input redirected through {len(chain_items)} Krea2 ControlNet nodes.")
|
chain_injectors/krea2_identity_edit_injector.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from imagegen_utils.app_utils import ensure_file_downloaded
|
| 3 |
+
|
| 4 |
+
def inject(assembler, chain_definition, chain_items):
|
| 5 |
+
if not chain_items:
|
| 6 |
+
return
|
| 7 |
+
|
| 8 |
+
valid_images = []
|
| 9 |
+
for item in chain_items:
|
| 10 |
+
if not item:
|
| 11 |
+
continue
|
| 12 |
+
img_path = item
|
| 13 |
+
if isinstance(item, dict):
|
| 14 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 15 |
+
if img_path:
|
| 16 |
+
valid_images.append(img_path)
|
| 17 |
+
|
| 18 |
+
if not valid_images:
|
| 19 |
+
return
|
| 20 |
+
|
| 21 |
+
valid_images = valid_images[:2]
|
| 22 |
+
|
| 23 |
+
lora_filename = "krea2_identity_edit_v1_2.safetensors"
|
| 24 |
+
try:
|
| 25 |
+
ensure_file_downloaded(lora_filename)
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Warning: Failed to ensure '{lora_filename}' downloaded: {e}")
|
| 28 |
+
|
| 29 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 30 |
+
pos_prompt_name = chain_definition.get('pos_prompt_node', 'pos_prompt')
|
| 31 |
+
neg_prompt_name = chain_definition.get('neg_prompt_node', 'neg_prompt')
|
| 32 |
+
clip_loader_name = chain_definition.get('clip_loader_node', 'clip_loader')
|
| 33 |
+
vae_loader_name = chain_definition.get('vae_loader_node', 'vae_loader')
|
| 34 |
+
|
| 35 |
+
if ksampler_name not in assembler.node_map:
|
| 36 |
+
print(f"Warning: Target node '{ksampler_name}' for Krea2 Identity Edit chain not found. Skipping.")
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 40 |
+
|
| 41 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 42 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping.")
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
latent_connection = assembler.workflow[ksampler_id]['inputs'].get('latent_image')
|
| 46 |
+
if not latent_connection:
|
| 47 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'latent_image' input. Skipping.")
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 51 |
+
|
| 52 |
+
vae_connection = None
|
| 53 |
+
if vae_loader_name in assembler.node_map:
|
| 54 |
+
vae_connection = [assembler.node_map[vae_loader_name], 0]
|
| 55 |
+
|
| 56 |
+
clip_connection = None
|
| 57 |
+
if clip_loader_name in assembler.node_map:
|
| 58 |
+
clip_connection = [assembler.node_map[clip_loader_name], 0]
|
| 59 |
+
elif pos_prompt_name in assembler.node_map:
|
| 60 |
+
pos_id = assembler.node_map[pos_prompt_name]
|
| 61 |
+
clip_connection = assembler.workflow[pos_id]['inputs'].get('clip')
|
| 62 |
+
|
| 63 |
+
lora_loader_id = assembler._get_unique_id()
|
| 64 |
+
lora_loader_node = assembler._get_node_template("LoraLoaderModelOnly")
|
| 65 |
+
lora_loader_node['inputs']['lora_name'] = lora_filename
|
| 66 |
+
lora_loader_node['inputs']['strength_model'] = 1.0
|
| 67 |
+
lora_loader_node['inputs']['model'] = current_model_connection
|
| 68 |
+
lora_loader_node['_meta']['title'] = "Load LoRA (Krea2 Identity Edit)"
|
| 69 |
+
assembler.workflow[lora_loader_id] = lora_loader_node
|
| 70 |
+
|
| 71 |
+
image_ids = []
|
| 72 |
+
vae_encode_ids = []
|
| 73 |
+
|
| 74 |
+
for i, img_filename in enumerate(valid_images):
|
| 75 |
+
load_id = assembler._get_unique_id()
|
| 76 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 77 |
+
load_node['inputs']['image'] = img_filename
|
| 78 |
+
load_node['_meta']['title'] = f"Load Image (Ref {i+1})"
|
| 79 |
+
assembler.workflow[load_id] = load_node
|
| 80 |
+
image_ids.append(load_id)
|
| 81 |
+
|
| 82 |
+
vae_enc_id = assembler._get_unique_id()
|
| 83 |
+
vae_enc_node = assembler._get_node_template("VAEEncode")
|
| 84 |
+
vae_enc_node['inputs']['pixels'] = [load_id, 0]
|
| 85 |
+
if vae_connection:
|
| 86 |
+
vae_enc_node['inputs']['vae'] = vae_connection
|
| 87 |
+
vae_enc_node['_meta']['title'] = f"VAE Encode (Ref {i+1})"
|
| 88 |
+
assembler.workflow[vae_enc_id] = vae_enc_node
|
| 89 |
+
vae_encode_ids.append(vae_enc_id)
|
| 90 |
+
|
| 91 |
+
patch_id = assembler._get_unique_id()
|
| 92 |
+
patch_node = assembler._get_node_template("Krea2EditModelPatch")
|
| 93 |
+
patch_node['inputs']['ref_boost'] = 4
|
| 94 |
+
patch_node['inputs']['ref_boost_a'] = 1
|
| 95 |
+
patch_node['inputs']['fit_mode'] = "fit"
|
| 96 |
+
patch_node['inputs']['model'] = [lora_loader_id, 0]
|
| 97 |
+
patch_node['inputs']['source_latent'] = [vae_encode_ids[0], 0]
|
| 98 |
+
if vae_connection:
|
| 99 |
+
patch_node['inputs']['vae'] = vae_connection
|
| 100 |
+
patch_node['inputs']['source_image'] = [image_ids[0], 0]
|
| 101 |
+
patch_node['inputs']['target_latent'] = latent_connection
|
| 102 |
+
|
| 103 |
+
if len(valid_images) > 1:
|
| 104 |
+
patch_node['inputs']['source_latent_b'] = [vae_encode_ids[1], 0]
|
| 105 |
+
patch_node['inputs']['source_image_b'] = [image_ids[1], 0]
|
| 106 |
+
|
| 107 |
+
patch_node['_meta']['title'] = "Krea2 Edit (source patch)"
|
| 108 |
+
assembler.workflow[patch_id] = patch_node
|
| 109 |
+
|
| 110 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = [patch_id, 0]
|
| 111 |
+
|
| 112 |
+
pos_prompt_id = assembler.node_map.get(pos_prompt_name)
|
| 113 |
+
neg_prompt_id = assembler.node_map.get(neg_prompt_name)
|
| 114 |
+
|
| 115 |
+
pos_text = ""
|
| 116 |
+
if pos_prompt_id and pos_prompt_id in assembler.workflow:
|
| 117 |
+
pos_text = assembler.workflow[pos_prompt_id]['inputs'].get('text', '')
|
| 118 |
+
elif hasattr(assembler, 'ui_values') and isinstance(assembler.ui_values, dict):
|
| 119 |
+
pos_text = assembler.ui_values.get('positive_prompt') or assembler.ui_values.get('prompt') or ''
|
| 120 |
+
|
| 121 |
+
if not pos_text:
|
| 122 |
+
for node_id, node in assembler.workflow.items():
|
| 123 |
+
if isinstance(node, dict):
|
| 124 |
+
cls = node.get('class_type', '')
|
| 125 |
+
if cls in ['Krea2EditGroundedEncode', 'TextEncodeQwenImageEditPlus', 'CLIPTextEncode']:
|
| 126 |
+
t = node.get('inputs', {}).get('prompt') or node.get('inputs', {}).get('text')
|
| 127 |
+
if t:
|
| 128 |
+
pos_text = t
|
| 129 |
+
break
|
| 130 |
+
|
| 131 |
+
neg_text = ""
|
| 132 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 133 |
+
neg_text = assembler.workflow[neg_prompt_id]['inputs'].get('text', '')
|
| 134 |
+
elif hasattr(assembler, 'ui_values') and isinstance(assembler.ui_values, dict):
|
| 135 |
+
neg_text = assembler.ui_values.get('negative_prompt') or assembler.ui_values.get('neg_prompt') or ''
|
| 136 |
+
|
| 137 |
+
pos_grounded_id = assembler._get_unique_id()
|
| 138 |
+
pos_grounded_node = assembler._get_node_template("Krea2EditGroundedEncode")
|
| 139 |
+
pos_grounded_node['inputs']['prompt'] = pos_text
|
| 140 |
+
pos_grounded_node['inputs']['grounding_px'] = 768
|
| 141 |
+
pos_grounded_node['inputs']['system_prompt'] = ""
|
| 142 |
+
if clip_connection:
|
| 143 |
+
pos_grounded_node['inputs']['clip'] = clip_connection
|
| 144 |
+
pos_grounded_node['inputs']['image'] = [image_ids[0], 0]
|
| 145 |
+
if len(valid_images) > 1:
|
| 146 |
+
pos_grounded_node['inputs']['image_b'] = [image_ids[1], 0]
|
| 147 |
+
pos_grounded_node['_meta']['title'] = "Krea2 Edit (grounded encode positive)"
|
| 148 |
+
assembler.workflow[pos_grounded_id] = pos_grounded_node
|
| 149 |
+
|
| 150 |
+
assembler.workflow[ksampler_id]['inputs']['positive'] = [pos_grounded_id, 0]
|
| 151 |
+
|
| 152 |
+
neg_grounded_id = assembler._get_unique_id()
|
| 153 |
+
neg_grounded_node = assembler._get_node_template("Krea2EditGroundedEncode")
|
| 154 |
+
neg_grounded_node['inputs']['prompt'] = neg_text
|
| 155 |
+
neg_grounded_node['inputs']['grounding_px'] = 768
|
| 156 |
+
neg_grounded_node['inputs']['system_prompt'] = ""
|
| 157 |
+
if clip_connection:
|
| 158 |
+
neg_grounded_node['inputs']['clip'] = clip_connection
|
| 159 |
+
neg_grounded_node['inputs']['image'] = [image_ids[0], 0]
|
| 160 |
+
if len(valid_images) > 1:
|
| 161 |
+
neg_grounded_node['inputs']['image_b'] = [image_ids[1], 0]
|
| 162 |
+
neg_grounded_node['_meta']['title'] = "Krea2 Edit (grounded encode negative)"
|
| 163 |
+
assembler.workflow[neg_grounded_id] = neg_grounded_node
|
| 164 |
+
|
| 165 |
+
assembler.workflow[ksampler_id]['inputs']['negative'] = [neg_grounded_id, 0]
|
| 166 |
+
|
| 167 |
+
if pos_prompt_id and pos_prompt_id in assembler.workflow:
|
| 168 |
+
del assembler.workflow[pos_prompt_id]
|
| 169 |
+
|
| 170 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 171 |
+
del assembler.workflow[neg_prompt_id]
|
| 172 |
+
|
| 173 |
+
print(f"Krea2 Identity Edit injector applied with {len(valid_images)} reference image(s). Original CLIPTextEncode nodes removed.")
|
chain_injectors/krea2_style_reference_injector.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from imagegen_utils.app_utils import ensure_file_downloaded
|
| 3 |
+
|
| 4 |
+
def create_node(assembler, class_type, title):
|
| 5 |
+
try:
|
| 6 |
+
node = assembler._get_node_template(class_type)
|
| 7 |
+
except Exception:
|
| 8 |
+
node = {
|
| 9 |
+
"inputs": {},
|
| 10 |
+
"class_type": class_type,
|
| 11 |
+
"_meta": {"title": title}
|
| 12 |
+
}
|
| 13 |
+
node['_meta']['title'] = title
|
| 14 |
+
return node
|
| 15 |
+
|
| 16 |
+
def inject(assembler, chain_definition, chain_items):
|
| 17 |
+
if not chain_items:
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
valid_images = []
|
| 21 |
+
for item in chain_items:
|
| 22 |
+
if not item:
|
| 23 |
+
continue
|
| 24 |
+
img_path = item
|
| 25 |
+
if isinstance(item, dict):
|
| 26 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 27 |
+
if img_path:
|
| 28 |
+
valid_images.append(img_path)
|
| 29 |
+
|
| 30 |
+
if not valid_images:
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
valid_images = valid_images[:3]
|
| 34 |
+
|
| 35 |
+
lora_filename = "krea2_style_reference.safetensors"
|
| 36 |
+
try:
|
| 37 |
+
ensure_file_downloaded(lora_filename)
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"Warning: Failed to ensure '{lora_filename}' downloaded: {e}")
|
| 40 |
+
|
| 41 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 42 |
+
pos_prompt_name = chain_definition.get('pos_prompt_node', 'pos_prompt')
|
| 43 |
+
neg_prompt_name = chain_definition.get('neg_prompt_node', 'neg_prompt')
|
| 44 |
+
clip_loader_name = chain_definition.get('clip_loader_node', 'clip_loader')
|
| 45 |
+
vae_loader_name = chain_definition.get('vae_loader_node', 'vae_loader')
|
| 46 |
+
|
| 47 |
+
if ksampler_name not in assembler.node_map:
|
| 48 |
+
print(f"Warning: Target node '{ksampler_name}' for Krea2 Style Reference Edit chain not found. Skipping.")
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 52 |
+
|
| 53 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 54 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping.")
|
| 55 |
+
return
|
| 56 |
+
|
| 57 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 58 |
+
|
| 59 |
+
vae_connection = None
|
| 60 |
+
if vae_loader_name in assembler.node_map:
|
| 61 |
+
vae_connection = [assembler.node_map[vae_loader_name], 0]
|
| 62 |
+
else:
|
| 63 |
+
for node_id, node in assembler.workflow.items():
|
| 64 |
+
if isinstance(node, dict) and node.get('class_type') == 'VAELoader':
|
| 65 |
+
vae_connection = [node_id, 0]
|
| 66 |
+
break
|
| 67 |
+
|
| 68 |
+
clip_connection = None
|
| 69 |
+
if clip_loader_name in assembler.node_map:
|
| 70 |
+
clip_connection = [assembler.node_map[clip_loader_name], 0]
|
| 71 |
+
elif pos_prompt_name in assembler.node_map:
|
| 72 |
+
pos_id = assembler.node_map[pos_prompt_name]
|
| 73 |
+
clip_connection = assembler.workflow[pos_id]['inputs'].get('clip')
|
| 74 |
+
|
| 75 |
+
scaled_image_ids = []
|
| 76 |
+
for i, img_filename in enumerate(valid_images):
|
| 77 |
+
load_id = assembler._get_unique_id()
|
| 78 |
+
load_node = create_node(assembler, "LoadImage", f"Load Reference Image {i+1}")
|
| 79 |
+
load_node['inputs']['image'] = img_filename
|
| 80 |
+
assembler.workflow[load_id] = load_node
|
| 81 |
+
|
| 82 |
+
scale_id = assembler._get_unique_id()
|
| 83 |
+
scale_node = create_node(assembler, "ImageScaleToTotalPixels", f"Scale Reference {i+1}")
|
| 84 |
+
scale_node['inputs']['upscale_method'] = "nearest-exact"
|
| 85 |
+
scale_node['inputs']['megapixels'] = 1
|
| 86 |
+
scale_node['inputs']['resolution_steps'] = 1
|
| 87 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 88 |
+
assembler.workflow[scale_id] = scale_node
|
| 89 |
+
scaled_image_ids.append(scale_id)
|
| 90 |
+
|
| 91 |
+
lora_loader_id = assembler._get_unique_id()
|
| 92 |
+
lora_loader_node = create_node(assembler, "LoraLoaderModelOnly", "Load LoRA (Krea2 Style Reference)")
|
| 93 |
+
lora_loader_node['inputs']['lora_name'] = lora_filename
|
| 94 |
+
lora_loader_node['inputs']['strength_model'] = 1.0
|
| 95 |
+
lora_loader_node['inputs']['model'] = current_model_connection
|
| 96 |
+
assembler.workflow[lora_loader_id] = lora_loader_node
|
| 97 |
+
|
| 98 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = [lora_loader_id, 0]
|
| 99 |
+
|
| 100 |
+
pos_prompt_id = assembler.node_map.get(pos_prompt_name)
|
| 101 |
+
neg_prompt_id = assembler.node_map.get(neg_prompt_name)
|
| 102 |
+
|
| 103 |
+
pos_text = ""
|
| 104 |
+
if pos_prompt_id and pos_prompt_id in assembler.workflow:
|
| 105 |
+
pos_text = assembler.workflow[pos_prompt_id]['inputs'].get('text', '')
|
| 106 |
+
elif hasattr(assembler, 'ui_values') and isinstance(assembler.ui_values, dict):
|
| 107 |
+
pos_text = assembler.ui_values.get('positive_prompt') or assembler.ui_values.get('prompt') or ''
|
| 108 |
+
|
| 109 |
+
if not pos_text:
|
| 110 |
+
for node_id, node in assembler.workflow.items():
|
| 111 |
+
if isinstance(node, dict):
|
| 112 |
+
cls = node.get('class_type', '')
|
| 113 |
+
if cls in ['Krea2EditGroundedEncode', 'TextEncodeQwenImageEditPlus', 'CLIPTextEncode']:
|
| 114 |
+
t = node.get('inputs', {}).get('prompt') or node.get('inputs', {}).get('text')
|
| 115 |
+
if t:
|
| 116 |
+
pos_text = t
|
| 117 |
+
break
|
| 118 |
+
|
| 119 |
+
neg_text = ""
|
| 120 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 121 |
+
neg_text = assembler.workflow[neg_prompt_id]['inputs'].get('text', '')
|
| 122 |
+
elif hasattr(assembler, 'ui_values') and isinstance(assembler.ui_values, dict):
|
| 123 |
+
neg_text = assembler.ui_values.get('negative_prompt') or assembler.ui_values.get('neg_prompt') or ''
|
| 124 |
+
|
| 125 |
+
pos_encode_id = assembler._get_unique_id()
|
| 126 |
+
pos_encode_node = create_node(assembler, "TextEncodeQwenImageEditPlus", "TextEncodeQwenImageEditPlus (Positive)")
|
| 127 |
+
pos_encode_node['inputs']['prompt'] = pos_text
|
| 128 |
+
if clip_connection:
|
| 129 |
+
pos_encode_node['inputs']['clip'] = clip_connection
|
| 130 |
+
if vae_connection:
|
| 131 |
+
pos_encode_node['inputs']['vae'] = vae_connection
|
| 132 |
+
for idx, s_id in enumerate(scaled_image_ids):
|
| 133 |
+
pos_encode_node['inputs'][f"image{idx+1}"] = [s_id, 0]
|
| 134 |
+
assembler.workflow[pos_encode_id] = pos_encode_node
|
| 135 |
+
|
| 136 |
+
neg_encode_id = assembler._get_unique_id()
|
| 137 |
+
neg_encode_node = create_node(assembler, "TextEncodeQwenImageEditPlus", "TextEncodeQwenImageEditPlus (Negative)")
|
| 138 |
+
neg_encode_node['inputs']['prompt'] = neg_text
|
| 139 |
+
if clip_connection:
|
| 140 |
+
neg_encode_node['inputs']['clip'] = clip_connection
|
| 141 |
+
if vae_connection:
|
| 142 |
+
neg_encode_node['inputs']['vae'] = vae_connection
|
| 143 |
+
for idx, s_id in enumerate(scaled_image_ids):
|
| 144 |
+
neg_encode_node['inputs'][f"image{idx+1}"] = [s_id, 0]
|
| 145 |
+
assembler.workflow[neg_encode_id] = neg_encode_node
|
| 146 |
+
|
| 147 |
+
pos_ref_id = assembler._get_unique_id()
|
| 148 |
+
pos_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method")
|
| 149 |
+
pos_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero"
|
| 150 |
+
pos_ref_node['inputs']['conditioning'] = [pos_encode_id, 0]
|
| 151 |
+
assembler.workflow[pos_ref_id] = pos_ref_node
|
| 152 |
+
|
| 153 |
+
neg_ref_id = assembler._get_unique_id()
|
| 154 |
+
neg_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method")
|
| 155 |
+
neg_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero"
|
| 156 |
+
neg_ref_node['inputs']['conditioning'] = [neg_encode_id, 0]
|
| 157 |
+
assembler.workflow[neg_ref_id] = neg_ref_node
|
| 158 |
+
|
| 159 |
+
assembler.workflow[ksampler_id]['inputs']['positive'] = [pos_ref_id, 0]
|
| 160 |
+
assembler.workflow[ksampler_id]['inputs']['negative'] = [neg_ref_id, 0]
|
| 161 |
+
|
| 162 |
+
if pos_prompt_id and pos_prompt_id in assembler.workflow:
|
| 163 |
+
del assembler.workflow[pos_prompt_id]
|
| 164 |
+
|
| 165 |
+
if neg_prompt_id and neg_prompt_id in assembler.workflow:
|
| 166 |
+
del assembler.workflow[neg_prompt_id]
|
| 167 |
+
|
| 168 |
+
print(f"Krea2 Style Reference Edit injector applied with {len(valid_images)} reference image(s). Original CLIPTextEncode nodes replaced.")
|
chain_injectors/lora_injector.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from copy import deepcopy
|
| 2 |
+
|
| 3 |
+
def inject(assembler, chain_definition, chain_items):
|
| 4 |
+
if not chain_items:
|
| 5 |
+
return
|
| 6 |
+
|
| 7 |
+
start_node_name = chain_definition.get('start')
|
| 8 |
+
start_node_id = None
|
| 9 |
+
if start_node_name:
|
| 10 |
+
if start_node_name not in assembler.node_map:
|
| 11 |
+
print(f"Warning: Start node '{start_node_name}' for dynamic LoRA chain not found. Skipping chain.")
|
| 12 |
+
return
|
| 13 |
+
start_node_id = assembler.node_map[start_node_name]
|
| 14 |
+
|
| 15 |
+
output_map = chain_definition.get('output_map', {})
|
| 16 |
+
current_connections = {}
|
| 17 |
+
for key, type_name in output_map.items():
|
| 18 |
+
if ':' in str(key):
|
| 19 |
+
node_name, idx_str = key.split(':')
|
| 20 |
+
if node_name not in assembler.node_map:
|
| 21 |
+
print(f"Warning: Node '{node_name}' in chain's output_map not found. Skipping.")
|
| 22 |
+
continue
|
| 23 |
+
node_id = assembler.node_map[node_name]
|
| 24 |
+
start_output_idx = int(idx_str)
|
| 25 |
+
current_connections[type_name] = [node_id, start_output_idx]
|
| 26 |
+
elif start_node_id:
|
| 27 |
+
start_output_idx = int(key)
|
| 28 |
+
current_connections[type_name] = [start_node_id, start_output_idx]
|
| 29 |
+
else:
|
| 30 |
+
print(f"Warning: LoRA chain has no 'start' node defined, and an output_map key '{key}' is not in 'node:index' format. Skipping this connection.")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
input_map = chain_definition.get('input_map', {})
|
| 34 |
+
chain_output_map = chain_definition.get('template_output_map', { "0": "model", "1": "clip" })
|
| 35 |
+
|
| 36 |
+
for item_data in chain_items:
|
| 37 |
+
template_name = chain_definition['template']
|
| 38 |
+
template = assembler._get_node_template(template_name)
|
| 39 |
+
node_data = deepcopy(template)
|
| 40 |
+
|
| 41 |
+
for param_name, value in item_data.items():
|
| 42 |
+
if param_name in node_data['inputs']:
|
| 43 |
+
node_data['inputs'][param_name] = value
|
| 44 |
+
|
| 45 |
+
for type_name, input_name in input_map.items():
|
| 46 |
+
if type_name in current_connections:
|
| 47 |
+
node_data['inputs'][input_name] = current_connections[type_name]
|
| 48 |
+
|
| 49 |
+
new_node_id = assembler._get_unique_id()
|
| 50 |
+
assembler.workflow[new_node_id] = node_data
|
| 51 |
+
|
| 52 |
+
for idx_str, type_name in chain_output_map.items():
|
| 53 |
+
current_connections[type_name] = [new_node_id, int(idx_str)]
|
| 54 |
+
|
| 55 |
+
end_input_map = chain_definition.get('end_input_map', {})
|
| 56 |
+
for type_name, targets in end_input_map.items():
|
| 57 |
+
if type_name in current_connections:
|
| 58 |
+
if not isinstance(targets, list):
|
| 59 |
+
targets = [targets]
|
| 60 |
+
|
| 61 |
+
for target_str in targets:
|
| 62 |
+
end_node_name, end_input_name = target_str.split(':')
|
| 63 |
+
if end_node_name in assembler.node_map:
|
| 64 |
+
end_node_id = assembler.node_map[end_node_name]
|
| 65 |
+
assembler.workflow[end_node_id]['inputs'][end_input_name] = current_connections[type_name]
|
| 66 |
+
else:
|
| 67 |
+
print(f"Warning: End node '{end_node_name}' for dynamic chain not found. Skipping connection.")
|
chain_injectors/pid_injector.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import yaml
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
def load_pid_config():
|
| 6 |
+
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 7 |
+
pid_path = os.path.join(project_root, 'yaml', 'pid.yaml')
|
| 8 |
+
with open(pid_path, 'r', encoding='utf-8') as f:
|
| 9 |
+
return yaml.safe_load(f) or {}
|
| 10 |
+
|
| 11 |
+
def load_model_config():
|
| 12 |
+
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 13 |
+
model_list_path = os.path.join(project_root, 'yaml', 'model_list.yaml')
|
| 14 |
+
with open(model_list_path, 'r', encoding='utf-8') as f:
|
| 15 |
+
return yaml.safe_load(f) or {}
|
| 16 |
+
|
| 17 |
+
def inject(assembler, chain_definition, chain_items):
|
| 18 |
+
if not chain_items:
|
| 19 |
+
return
|
| 20 |
+
|
| 21 |
+
pid_config = {}
|
| 22 |
+
try:
|
| 23 |
+
pid_config = load_pid_config() or {}
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"Error loading PiD config: {e}")
|
| 26 |
+
|
| 27 |
+
pid_items = pid_config.get("PiD", [])
|
| 28 |
+
architectures_settings = {}
|
| 29 |
+
default_settings = {"unet_name": "pid_flux1_1024_to_4096_4step_mxfp8.safetensors", "latent_format": "flux"}
|
| 30 |
+
|
| 31 |
+
for item in pid_items:
|
| 32 |
+
unet_name = item.get("filepath")
|
| 33 |
+
latent_format = item.get("latent_format")
|
| 34 |
+
archs = item.get("architectures", [])
|
| 35 |
+
for arch in archs:
|
| 36 |
+
architectures_settings[arch] = {
|
| 37 |
+
"unet_name": unet_name,
|
| 38 |
+
"latent_format": latent_format
|
| 39 |
+
}
|
| 40 |
+
if arch == "flux1":
|
| 41 |
+
default_settings = {
|
| 42 |
+
"unet_name": unet_name,
|
| 43 |
+
"latent_format": latent_format
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 47 |
+
if ksampler_name not in assembler.node_map:
|
| 48 |
+
print(f"Warning: [PiD Injector] KSampler node '{ksampler_name}' not found. Skipping.")
|
| 49 |
+
return
|
| 50 |
+
|
| 51 |
+
original_ksampler_id = assembler.node_map[ksampler_name]
|
| 52 |
+
|
| 53 |
+
original_vae_loader_id = assembler.node_map.get('vae_loader')
|
| 54 |
+
original_vae_decode_id = assembler.node_map.get('vae_decode')
|
| 55 |
+
original_pos_prompt_id = assembler.node_map.get('pos_prompt')
|
| 56 |
+
original_neg_prompt_id = assembler.node_map.get('neg_prompt')
|
| 57 |
+
|
| 58 |
+
if not original_vae_loader_id:
|
| 59 |
+
for node_id, node_data in assembler.workflow.items():
|
| 60 |
+
if node_data.get('class_type') == 'VAELoader':
|
| 61 |
+
original_vae_loader_id = node_id
|
| 62 |
+
break
|
| 63 |
+
|
| 64 |
+
if not original_vae_decode_id:
|
| 65 |
+
for node_id, node_data in assembler.workflow.items():
|
| 66 |
+
if node_data.get('class_type') == 'VAEDecode':
|
| 67 |
+
original_vae_decode_id = node_id
|
| 68 |
+
break
|
| 69 |
+
|
| 70 |
+
if not original_pos_prompt_id or not original_neg_prompt_id:
|
| 71 |
+
for node_id, node_data in assembler.workflow.items():
|
| 72 |
+
if node_data.get('class_type') == 'CLIPTextEncode':
|
| 73 |
+
title = node_data.get('_meta', {}).get('title', '')
|
| 74 |
+
if 'Positive' in title:
|
| 75 |
+
if not original_pos_prompt_id:
|
| 76 |
+
original_pos_prompt_id = node_id
|
| 77 |
+
elif 'Negative' in title:
|
| 78 |
+
if not original_neg_prompt_id:
|
| 79 |
+
original_neg_prompt_id = node_id
|
| 80 |
+
|
| 81 |
+
pos_text = ""
|
| 82 |
+
if original_pos_prompt_id and original_pos_prompt_id in assembler.workflow:
|
| 83 |
+
pos_text = assembler.workflow[original_pos_prompt_id]['inputs'].get('text', '')
|
| 84 |
+
|
| 85 |
+
neg_text = ""
|
| 86 |
+
if original_neg_prompt_id and original_neg_prompt_id in assembler.workflow:
|
| 87 |
+
neg_text = assembler.workflow[original_neg_prompt_id]['inputs'].get('text', '')
|
| 88 |
+
|
| 89 |
+
clip_loader_id = assembler._get_unique_id()
|
| 90 |
+
clip_loader_node = assembler._get_node_template("CLIPLoader")
|
| 91 |
+
clip_loader_node['inputs']['clip_name'] = "gemma_2_2b_it_elm_fp8_scaled.safetensors"
|
| 92 |
+
clip_loader_node['inputs']['type'] = "pixeldit"
|
| 93 |
+
clip_loader_node['inputs']['device'] = "default"
|
| 94 |
+
assembler.workflow[clip_loader_id] = clip_loader_node
|
| 95 |
+
|
| 96 |
+
pos_text_encode_id = assembler._get_unique_id()
|
| 97 |
+
pos_text_encode_node = assembler._get_node_template("CLIPTextEncode")
|
| 98 |
+
pos_text_encode_node['inputs']['text'] = pos_text
|
| 99 |
+
pos_text_encode_node['inputs']['clip'] = [clip_loader_id, 0]
|
| 100 |
+
assembler.workflow[pos_text_encode_id] = pos_text_encode_node
|
| 101 |
+
|
| 102 |
+
neg_text_encode_id = assembler._get_unique_id()
|
| 103 |
+
neg_text_encode_node = assembler._get_node_template("CLIPTextEncode")
|
| 104 |
+
neg_text_encode_node['inputs']['text'] = neg_text
|
| 105 |
+
neg_text_encode_node['inputs']['clip'] = [clip_loader_id, 0]
|
| 106 |
+
assembler.workflow[neg_text_encode_id] = neg_text_encode_node
|
| 107 |
+
|
| 108 |
+
active_model_file = None
|
| 109 |
+
for node_id, node_data in assembler.workflow.items():
|
| 110 |
+
class_type = node_data.get('class_type')
|
| 111 |
+
if class_type == 'UNETLoader':
|
| 112 |
+
active_model_file = node_data.get('inputs', {}).get('unet_name')
|
| 113 |
+
if active_model_file:
|
| 114 |
+
break
|
| 115 |
+
elif class_type == 'CheckpointLoaderSimple':
|
| 116 |
+
active_model_file = node_data.get('inputs', {}).get('ckpt_name')
|
| 117 |
+
if active_model_file:
|
| 118 |
+
break
|
| 119 |
+
|
| 120 |
+
architecture = None
|
| 121 |
+
if active_model_file:
|
| 122 |
+
try:
|
| 123 |
+
model_config = load_model_config()
|
| 124 |
+
checkpoints = model_config.get("Checkpoints", {})
|
| 125 |
+
for arch_name, arch_data in checkpoints.items():
|
| 126 |
+
models_list = arch_data.get("models", [])
|
| 127 |
+
for model_entry in models_list:
|
| 128 |
+
if model_entry.get('path') == active_model_file:
|
| 129 |
+
architecture = arch_name
|
| 130 |
+
break
|
| 131 |
+
components_dict = model_entry.get('components', {})
|
| 132 |
+
if active_model_file in components_dict.values():
|
| 133 |
+
architecture = arch_name
|
| 134 |
+
break
|
| 135 |
+
if architecture:
|
| 136 |
+
break
|
| 137 |
+
except Exception as e:
|
| 138 |
+
print(f"Error looking up model architecture in PiD injector: {e}")
|
| 139 |
+
|
| 140 |
+
if architecture:
|
| 141 |
+
architecture = architecture.lower().replace(" ", "-").replace(".", "")
|
| 142 |
+
else:
|
| 143 |
+
file_lower = active_model_file.lower().replace("-", "").replace("_", "").replace(".", "")
|
| 144 |
+
for arch in sorted(architectures_settings.keys(), key=len, reverse=True):
|
| 145 |
+
candidates = [arch]
|
| 146 |
+
if "-image" in arch:
|
| 147 |
+
candidates.append(arch.replace("-image", ""))
|
| 148 |
+
if "-i1" in arch:
|
| 149 |
+
candidates.append(arch.replace("-i1", ""))
|
| 150 |
+
if "-kv" in arch:
|
| 151 |
+
candidates.append(arch.replace("-kv", ""))
|
| 152 |
+
|
| 153 |
+
matched = False
|
| 154 |
+
for cand in candidates:
|
| 155 |
+
if cand.replace("-", "").replace(".", "") in file_lower:
|
| 156 |
+
architecture = arch
|
| 157 |
+
matched = True
|
| 158 |
+
break
|
| 159 |
+
if matched:
|
| 160 |
+
break
|
| 161 |
+
|
| 162 |
+
unet_name = default_settings.get("unet_name")
|
| 163 |
+
latent_format = default_settings.get("latent_format")
|
| 164 |
+
|
| 165 |
+
if architecture in architectures_settings:
|
| 166 |
+
arch_config = architectures_settings[architecture]
|
| 167 |
+
unet_name = arch_config.get("unet_name", unet_name)
|
| 168 |
+
latent_format = arch_config.get("latent_format", latent_format)
|
| 169 |
+
else:
|
| 170 |
+
print(f"[PiD Injector] Warning: Model architecture '{architecture}' (file: '{active_model_file}') not explicitly mapped. Using default settings.")
|
| 171 |
+
|
| 172 |
+
pid_pos_id = assembler._get_unique_id()
|
| 173 |
+
pid_pos_node = assembler._get_node_template("PiDConditioning")
|
| 174 |
+
pid_pos_node['inputs']['latent_format'] = latent_format
|
| 175 |
+
pid_pos_node['inputs']['degrade_sigma'] = 0
|
| 176 |
+
pid_pos_node['inputs']['positive'] = [pos_text_encode_id, 0]
|
| 177 |
+
pid_pos_node['inputs']['latent'] = [original_ksampler_id, 0]
|
| 178 |
+
assembler.workflow[pid_pos_id] = pid_pos_node
|
| 179 |
+
|
| 180 |
+
pid_neg_id = assembler._get_unique_id()
|
| 181 |
+
pid_neg_node = assembler._get_node_template("PiDConditioning")
|
| 182 |
+
pid_neg_node['inputs']['latent_format'] = latent_format
|
| 183 |
+
pid_neg_node['inputs']['degrade_sigma'] = 0
|
| 184 |
+
pid_neg_node['inputs']['positive'] = [neg_text_encode_id, 0]
|
| 185 |
+
pid_neg_node['inputs']['latent'] = [original_ksampler_id, 0]
|
| 186 |
+
assembler.workflow[pid_neg_id] = pid_neg_node
|
| 187 |
+
|
| 188 |
+
pid_unet_loader_id = assembler._get_unique_id()
|
| 189 |
+
pid_unet_loader_node = assembler._get_node_template("UNETLoader")
|
| 190 |
+
pid_unet_loader_node['inputs']['unet_name'] = unet_name
|
| 191 |
+
pid_unet_loader_node['inputs']['weight_dtype'] = "default"
|
| 192 |
+
assembler.workflow[pid_unet_loader_id] = pid_unet_loader_node
|
| 193 |
+
|
| 194 |
+
orig_width = 1024
|
| 195 |
+
orig_height = 1024
|
| 196 |
+
original_latent_source_id = assembler.node_map.get('latent_source')
|
| 197 |
+
if original_latent_source_id in assembler.workflow:
|
| 198 |
+
node_inputs = assembler.workflow[original_latent_source_id].get('inputs', {})
|
| 199 |
+
if 'width' in node_inputs and 'height' in node_inputs:
|
| 200 |
+
orig_width = node_inputs['width']
|
| 201 |
+
orig_height = node_inputs['height']
|
| 202 |
+
else:
|
| 203 |
+
for node_data in assembler.workflow.values():
|
| 204 |
+
inputs = node_data.get('inputs', {})
|
| 205 |
+
if 'width' in inputs and 'height' in inputs and isinstance(inputs['width'], (int, float)) and isinstance(inputs['height'], (int, float)):
|
| 206 |
+
if 256 <= inputs['width'] <= 4096 and 256 <= inputs['height'] <= 4096:
|
| 207 |
+
orig_width = inputs['width']
|
| 208 |
+
orig_height = inputs['height']
|
| 209 |
+
break
|
| 210 |
+
else:
|
| 211 |
+
for node_data in assembler.workflow.values():
|
| 212 |
+
inputs = node_data.get('inputs', {})
|
| 213 |
+
if 'width' in inputs and 'height' in inputs and isinstance(inputs['width'], (int, float)) and isinstance(inputs['height'], (int, float)):
|
| 214 |
+
if 256 <= inputs['width'] <= 4096 and 256 <= inputs['height'] <= 4096:
|
| 215 |
+
orig_width = inputs['width']
|
| 216 |
+
orig_height = inputs['height']
|
| 217 |
+
break
|
| 218 |
+
|
| 219 |
+
empty_latent_id = assembler._get_unique_id()
|
| 220 |
+
empty_latent_node = assembler._get_node_template("EmptyChromaRadianceLatentImage")
|
| 221 |
+
empty_latent_node['inputs']['width'] = int(orig_width) * 4
|
| 222 |
+
empty_latent_node['inputs']['height'] = int(orig_height) * 4
|
| 223 |
+
empty_latent_node['inputs']['batch_size'] = 1
|
| 224 |
+
|
| 225 |
+
if original_latent_source_id in assembler.workflow:
|
| 226 |
+
orig_batch_size = assembler.workflow[original_latent_source_id]['inputs'].get('batch_size') or assembler.workflow[original_latent_source_id]['inputs'].get('amount')
|
| 227 |
+
if orig_batch_size:
|
| 228 |
+
empty_latent_node['inputs']['batch_size'] = orig_batch_size
|
| 229 |
+
|
| 230 |
+
assembler.workflow[empty_latent_id] = empty_latent_node
|
| 231 |
+
|
| 232 |
+
orig_seed = 0
|
| 233 |
+
if original_ksampler_id in assembler.workflow:
|
| 234 |
+
orig_seed = assembler.workflow[original_ksampler_id]['inputs'].get('seed', 0)
|
| 235 |
+
if orig_seed == -1:
|
| 236 |
+
orig_seed = random.randint(0, 2**32 - 1)
|
| 237 |
+
else:
|
| 238 |
+
orig_seed = (orig_seed + 1) % (2**32)
|
| 239 |
+
|
| 240 |
+
new_ksampler_id = assembler._get_unique_id()
|
| 241 |
+
new_ksampler_node = assembler._get_node_template("KSampler")
|
| 242 |
+
new_ksampler_node['inputs']['seed'] = orig_seed
|
| 243 |
+
new_ksampler_node['inputs']['steps'] = 4
|
| 244 |
+
new_ksampler_node['inputs']['cfg'] = 1
|
| 245 |
+
new_ksampler_node['inputs']['sampler_name'] = "lcm"
|
| 246 |
+
new_ksampler_node['inputs']['scheduler'] = "simple"
|
| 247 |
+
new_ksampler_node['inputs']['denoise'] = 1.0
|
| 248 |
+
new_ksampler_node['inputs']['model'] = [pid_unet_loader_id, 0]
|
| 249 |
+
new_ksampler_node['inputs']['positive'] = [pid_pos_id, 0]
|
| 250 |
+
new_ksampler_node['inputs']['negative'] = [pid_neg_id, 0]
|
| 251 |
+
new_ksampler_node['inputs']['latent_image'] = [empty_latent_id, 0]
|
| 252 |
+
assembler.workflow[new_ksampler_id] = new_ksampler_node
|
| 253 |
+
|
| 254 |
+
pid_vae_loader_id = assembler._get_unique_id()
|
| 255 |
+
pid_vae_loader_node = assembler._get_node_template("VAELoader")
|
| 256 |
+
pid_vae_loader_node['inputs']['vae_name'] = "pixel_space"
|
| 257 |
+
assembler.workflow[pid_vae_loader_id] = pid_vae_loader_node
|
| 258 |
+
|
| 259 |
+
pid_vae_decode_id = assembler._get_unique_id()
|
| 260 |
+
pid_vae_decode_node = assembler._get_node_template("VAEDecode")
|
| 261 |
+
pid_vae_decode_node['inputs']['samples'] = [new_ksampler_id, 0]
|
| 262 |
+
pid_vae_decode_node['inputs']['vae'] = [pid_vae_loader_id, 0]
|
| 263 |
+
assembler.workflow[pid_vae_decode_id] = pid_vae_decode_node
|
| 264 |
+
|
| 265 |
+
if original_vae_decode_id:
|
| 266 |
+
for node_id, node_data in assembler.workflow.items():
|
| 267 |
+
if 'inputs' in node_data:
|
| 268 |
+
for input_name, input_val in list(node_data['inputs'].items()):
|
| 269 |
+
if isinstance(input_val, list) and len(input_val) == 2:
|
| 270 |
+
if input_val[0] == original_vae_decode_id:
|
| 271 |
+
node_data['inputs'][input_name] = [pid_vae_decode_id, 0]
|
| 272 |
+
|
| 273 |
+
is_vae_loader_referenced = False
|
| 274 |
+
if original_vae_loader_id:
|
| 275 |
+
for node_id, node_data in assembler.workflow.items():
|
| 276 |
+
if node_id == original_vae_loader_id:
|
| 277 |
+
continue
|
| 278 |
+
for input_val in node_data.get('inputs', {}).values():
|
| 279 |
+
if isinstance(input_val, list) and len(input_val) == 2:
|
| 280 |
+
if input_val[0] == original_vae_loader_id:
|
| 281 |
+
is_vae_loader_referenced = True
|
| 282 |
+
break
|
| 283 |
+
if is_vae_loader_referenced:
|
| 284 |
+
break
|
| 285 |
+
|
| 286 |
+
if original_vae_loader_id in assembler.workflow and not is_vae_loader_referenced:
|
| 287 |
+
del assembler.workflow[original_vae_loader_id]
|
| 288 |
+
|
| 289 |
+
if original_vae_decode_id in assembler.workflow:
|
| 290 |
+
del assembler.workflow[original_vae_decode_id]
|
| 291 |
+
|
| 292 |
+
print("[PiD Injector] Successfully injected PiD pipeline and replaced VAE decode/loader.")
|
chain_injectors/qwen_image_edit_injector.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def create_node(assembler, class_type, title):
|
| 2 |
+
try:
|
| 3 |
+
node = assembler._get_node_template(class_type)
|
| 4 |
+
except Exception:
|
| 5 |
+
node = {
|
| 6 |
+
"inputs": {},
|
| 7 |
+
"class_type": class_type,
|
| 8 |
+
"_meta": {"title": title}
|
| 9 |
+
}
|
| 10 |
+
node['_meta']['title'] = title
|
| 11 |
+
return node
|
| 12 |
+
|
| 13 |
+
def inject(assembler, chain_definition, chain_items):
|
| 14 |
+
if not chain_items:
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
valid_images = []
|
| 18 |
+
for item in chain_items:
|
| 19 |
+
if not item:
|
| 20 |
+
continue
|
| 21 |
+
img_path = item
|
| 22 |
+
if isinstance(item, dict):
|
| 23 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 24 |
+
if img_path:
|
| 25 |
+
valid_images.append(img_path)
|
| 26 |
+
|
| 27 |
+
if not valid_images:
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
valid_images = valid_images[:3]
|
| 31 |
+
|
| 32 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 33 |
+
pos_prompt_name = chain_definition.get('pos_prompt_node', 'pos_prompt')
|
| 34 |
+
neg_prompt_name = chain_definition.get('neg_prompt_node', 'neg_prompt')
|
| 35 |
+
vae_loader_name = chain_definition.get('vae_loader_node', 'vae_loader')
|
| 36 |
+
model_sampler_name = chain_definition.get('model_sampler_node', 'model_sampler')
|
| 37 |
+
|
| 38 |
+
if ksampler_name not in assembler.node_map:
|
| 39 |
+
print(f"Warning: Target node '{ksampler_name}' for Qwen-Image Edit chain not found. Skipping.")
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 43 |
+
pos_prompt_id = assembler.node_map.get(pos_prompt_name)
|
| 44 |
+
neg_prompt_id = assembler.node_map.get(neg_prompt_name)
|
| 45 |
+
|
| 46 |
+
if not pos_prompt_id or not neg_prompt_id:
|
| 47 |
+
print("Warning: Positive or negative prompt node not found for Qwen-Image Edit chain. Skipping.")
|
| 48 |
+
return
|
| 49 |
+
|
| 50 |
+
vae_id = assembler.node_map.get(vae_loader_name)
|
| 51 |
+
if not vae_id:
|
| 52 |
+
for node_id, node in assembler.workflow.items():
|
| 53 |
+
if isinstance(node, dict) and node.get('class_type') == 'VAELoader':
|
| 54 |
+
vae_id = node_id
|
| 55 |
+
break
|
| 56 |
+
|
| 57 |
+
if vae_id:
|
| 58 |
+
assembler.workflow[pos_prompt_id]['inputs']['vae'] = [vae_id, 0]
|
| 59 |
+
assembler.workflow[neg_prompt_id]['inputs']['vae'] = [vae_id, 0]
|
| 60 |
+
|
| 61 |
+
for i, img_filename in enumerate(valid_images):
|
| 62 |
+
load_id = assembler._get_unique_id()
|
| 63 |
+
load_node = create_node(assembler, "LoadImage", f"Load Reference Image {i+1}")
|
| 64 |
+
load_node['inputs']['image'] = img_filename
|
| 65 |
+
assembler.workflow[load_id] = load_node
|
| 66 |
+
|
| 67 |
+
scale_id = assembler._get_unique_id()
|
| 68 |
+
scale_node = create_node(assembler, "ImageScaleToTotalPixels", f"Scale Reference {i+1}")
|
| 69 |
+
scale_node['inputs']['upscale_method'] = "lanczos"
|
| 70 |
+
scale_node['inputs']['megapixels'] = 1
|
| 71 |
+
scale_node['inputs']['resolution_steps'] = 1
|
| 72 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 73 |
+
assembler.workflow[scale_id] = scale_node
|
| 74 |
+
|
| 75 |
+
image_key = f"image{i+1}"
|
| 76 |
+
assembler.workflow[pos_prompt_id]['inputs'][image_key] = [scale_id, 0]
|
| 77 |
+
assembler.workflow[neg_prompt_id]['inputs'][image_key] = [scale_id, 0]
|
| 78 |
+
|
| 79 |
+
pos_ref_id = assembler._get_unique_id()
|
| 80 |
+
pos_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method")
|
| 81 |
+
pos_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero"
|
| 82 |
+
pos_ref_node['inputs']['conditioning'] = [pos_prompt_id, 0]
|
| 83 |
+
assembler.workflow[pos_ref_id] = pos_ref_node
|
| 84 |
+
|
| 85 |
+
neg_ref_id = assembler._get_unique_id()
|
| 86 |
+
neg_ref_node = create_node(assembler, "FluxKontextMultiReferenceLatentMethod", "Edit Model Reference Method")
|
| 87 |
+
neg_ref_node['inputs']['reference_latents_method'] = "index_timestep_zero"
|
| 88 |
+
neg_ref_node['inputs']['conditioning'] = [neg_prompt_id, 0]
|
| 89 |
+
assembler.workflow[neg_ref_id] = neg_ref_node
|
| 90 |
+
|
| 91 |
+
assembler.workflow[ksampler_id]['inputs']['positive'] = [pos_ref_id, 0]
|
| 92 |
+
assembler.workflow[ksampler_id]['inputs']['negative'] = [neg_ref_id, 0]
|
| 93 |
+
|
| 94 |
+
model_sampler_id = assembler.node_map.get(model_sampler_name)
|
| 95 |
+
if not model_sampler_id:
|
| 96 |
+
for node_id, node in assembler.workflow.items():
|
| 97 |
+
if isinstance(node, dict) and node.get('class_type') == 'ModelSamplingAuraFlow':
|
| 98 |
+
model_sampler_id = node_id
|
| 99 |
+
break
|
| 100 |
+
|
| 101 |
+
if model_sampler_id and model_sampler_id in assembler.workflow:
|
| 102 |
+
assembler.workflow[model_sampler_id]['inputs']['shift'] = 3
|
| 103 |
+
|
| 104 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 105 |
+
cfg_norm_id = assembler._get_unique_id()
|
| 106 |
+
cfg_norm_node = create_node(assembler, "CFGNorm", "CFGNorm")
|
| 107 |
+
cfg_norm_node['inputs']['strength'] = 1
|
| 108 |
+
cfg_norm_node['inputs']['pre_cfg'] = False
|
| 109 |
+
cfg_norm_node['inputs']['model'] = current_model_connection
|
| 110 |
+
assembler.workflow[cfg_norm_id] = cfg_norm_node
|
| 111 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = [cfg_norm_id, 0]
|
| 112 |
+
|
| 113 |
+
print(f"Qwen-Image Edit injector applied with {len(valid_images)} reference image(s). Connected VAE dynamically.")
|
chain_injectors/reference_image_injector.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
def inject(assembler, chain_definition, chain_items):
|
| 4 |
+
if not chain_items:
|
| 5 |
+
return
|
| 6 |
+
|
| 7 |
+
valid_images = []
|
| 8 |
+
for item in chain_items:
|
| 9 |
+
if not item:
|
| 10 |
+
continue
|
| 11 |
+
img_path = item
|
| 12 |
+
if isinstance(item, dict):
|
| 13 |
+
img_path = item.get('image') or item.get('filename') or item.get('path')
|
| 14 |
+
if img_path:
|
| 15 |
+
valid_images.append(img_path)
|
| 16 |
+
|
| 17 |
+
if not valid_images:
|
| 18 |
+
return
|
| 19 |
+
|
| 20 |
+
text_encode_name = chain_definition.get('text_encode_node')
|
| 21 |
+
text_encode_id = None
|
| 22 |
+
if text_encode_name and text_encode_name in assembler.node_map:
|
| 23 |
+
text_encode_id = assembler.node_map[text_encode_name]
|
| 24 |
+
else:
|
| 25 |
+
for node_id, node in assembler.workflow.items():
|
| 26 |
+
if isinstance(node, dict) and node.get('class_type') == 'TextEncodeMageFlowEdit':
|
| 27 |
+
text_encode_id = node_id
|
| 28 |
+
break
|
| 29 |
+
|
| 30 |
+
if not text_encode_id or text_encode_id not in assembler.workflow:
|
| 31 |
+
print("Warning: TextEncodeMageFlowEdit node not found for Reference Image chain. Skipping.")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
vae_node_name = chain_definition.get('vae_node', 'vae_loader')
|
| 35 |
+
vae_node_id = assembler.node_map.get(vae_node_name)
|
| 36 |
+
if not vae_node_id:
|
| 37 |
+
for node_id, node in assembler.workflow.items():
|
| 38 |
+
if isinstance(node, dict) and node.get('class_type') == 'VAELoader':
|
| 39 |
+
vae_node_id = node_id
|
| 40 |
+
break
|
| 41 |
+
|
| 42 |
+
if vae_node_id:
|
| 43 |
+
assembler.workflow[text_encode_id]['inputs']['vae'] = [vae_node_id, 0]
|
| 44 |
+
|
| 45 |
+
for i, img_filename in enumerate(valid_images):
|
| 46 |
+
load_id = assembler._get_unique_id()
|
| 47 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 48 |
+
load_node['inputs']['image'] = img_filename
|
| 49 |
+
load_node['_meta']['title'] = f"Load Reference Image {i+1}"
|
| 50 |
+
assembler.workflow[load_id] = load_node
|
| 51 |
+
|
| 52 |
+
scale_id = assembler._get_unique_id()
|
| 53 |
+
scale_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 54 |
+
scale_node['inputs']['megapixels'] = 1.0
|
| 55 |
+
scale_node['inputs']['upscale_method'] = "nearest-exact"
|
| 56 |
+
scale_node['inputs']['resolution_steps'] = 1
|
| 57 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 58 |
+
scale_node['_meta']['title'] = f"Scale Reference {i+1}"
|
| 59 |
+
assembler.workflow[scale_id] = scale_node
|
| 60 |
+
|
| 61 |
+
input_key = f"images.image_{i+1}"
|
| 62 |
+
assembler.workflow[text_encode_id]['inputs'][input_key] = [scale_id, 0]
|
| 63 |
+
|
| 64 |
+
print(f"Reference Image injector applied. Injected {len(valid_images)} reference images to TextEncodeMageFlowEdit node '{text_encode_id}'.")
|
chain_injectors/reference_latent_injector.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
guider_node_name = chain_definition.get('guider_node')
|
| 6 |
+
guider_target_inputs = chain_definition.get('guider_target_inputs', [])
|
| 7 |
+
start_connections_map = chain_definition.get('start_connections', {})
|
| 8 |
+
vae_node_name = chain_definition.get('vae_node', 'vae_loader')
|
| 9 |
+
|
| 10 |
+
if guider_node_name and guider_node_name in assembler.node_map and guider_target_inputs:
|
| 11 |
+
guider_id = assembler.node_map[guider_node_name]
|
| 12 |
+
if vae_node_name not in assembler.node_map:
|
| 13 |
+
print(f"Warning: VAE node '{vae_node_name}' not found for Guider chain. Skipping.")
|
| 14 |
+
return
|
| 15 |
+
vae_node_id = assembler.node_map[vae_node_name]
|
| 16 |
+
|
| 17 |
+
print(f"ReferenceLatent injector targeting DualCFGGuider node '{guider_node_name}'.")
|
| 18 |
+
|
| 19 |
+
current_connections = {}
|
| 20 |
+
for target_input in guider_target_inputs:
|
| 21 |
+
conn_str = start_connections_map.get(target_input)
|
| 22 |
+
if not conn_str:
|
| 23 |
+
print(f"Warning: No start connection defined for '{target_input}' in Guider chain. Skipping this input.")
|
| 24 |
+
continue
|
| 25 |
+
try:
|
| 26 |
+
node_name, idx_str = conn_str.split(':')
|
| 27 |
+
node_id = assembler.node_map[node_name]
|
| 28 |
+
current_connections[target_input] = [node_id, int(idx_str)]
|
| 29 |
+
except (ValueError, KeyError):
|
| 30 |
+
print(f"Warning: Invalid start connection '{conn_str}' for '{target_input}'. Skipping.")
|
| 31 |
+
|
| 32 |
+
encoded_latents = []
|
| 33 |
+
for i, img_filename in enumerate(chain_items):
|
| 34 |
+
load_id = assembler._get_unique_id()
|
| 35 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 36 |
+
load_node['inputs']['image'] = img_filename
|
| 37 |
+
assembler.workflow[load_id] = load_node
|
| 38 |
+
|
| 39 |
+
scale_id = assembler._get_unique_id()
|
| 40 |
+
scale_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 41 |
+
scale_node['inputs']['megapixels'] = 1.0
|
| 42 |
+
scale_node['inputs']['upscale_method'] = "lanczos"
|
| 43 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 44 |
+
assembler.workflow[scale_id] = scale_node
|
| 45 |
+
|
| 46 |
+
vae_encode_id = assembler._get_unique_id()
|
| 47 |
+
vae_encode_node = assembler._get_node_template("VAEEncode")
|
| 48 |
+
vae_encode_node['inputs']['pixels'] = [scale_id, 0]
|
| 49 |
+
vae_encode_node['inputs']['vae'] = [vae_node_id, 0]
|
| 50 |
+
assembler.workflow[vae_encode_id] = vae_encode_node
|
| 51 |
+
encoded_latents.append([vae_encode_id, 0])
|
| 52 |
+
|
| 53 |
+
for target_input_name, start_connection in current_connections.items():
|
| 54 |
+
current_chain_head = start_connection
|
| 55 |
+
for i, latent_conn in enumerate(encoded_latents):
|
| 56 |
+
ref_latent_id = assembler._get_unique_id()
|
| 57 |
+
ref_latent_node = assembler._get_node_template("ReferenceLatent")
|
| 58 |
+
ref_latent_node['inputs']['conditioning'] = current_chain_head
|
| 59 |
+
ref_latent_node['inputs']['latent'] = latent_conn
|
| 60 |
+
ref_latent_node['_meta']['title'] = f"{target_input_name} RefLatent {i+1}"
|
| 61 |
+
assembler.workflow[ref_latent_id] = ref_latent_node
|
| 62 |
+
current_chain_head = [ref_latent_id, 0]
|
| 63 |
+
|
| 64 |
+
assembler.workflow[guider_id]['inputs'][target_input_name] = current_chain_head
|
| 65 |
+
print(f" - Input '{target_input_name}' of node '{guider_node_name}' re-routed through {len(chain_items)} reference images.")
|
| 66 |
+
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
flux_guidance_name = chain_definition.get('flux_guidance_node')
|
| 70 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 71 |
+
|
| 72 |
+
if ksampler_name not in assembler.node_map:
|
| 73 |
+
print(f"Warning: KSampler node '{ksampler_name}' not found for ReferenceLatent chain. Skipping.")
|
| 74 |
+
return
|
| 75 |
+
if vae_node_name not in assembler.node_map:
|
| 76 |
+
print(f"Warning: VAE loader node '{vae_node_name}' not found for ReferenceLatent chain. Skipping.")
|
| 77 |
+
return
|
| 78 |
+
|
| 79 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 80 |
+
vae_node_id = assembler.node_map[vae_node_name]
|
| 81 |
+
|
| 82 |
+
pos_target_node_id = None
|
| 83 |
+
pos_target_input_name = None
|
| 84 |
+
if flux_guidance_name and flux_guidance_name in assembler.node_map:
|
| 85 |
+
flux_guidance_id = assembler.node_map[flux_guidance_name]
|
| 86 |
+
if 'conditioning' in assembler.workflow[flux_guidance_id]['inputs']:
|
| 87 |
+
pos_target_node_id = flux_guidance_id
|
| 88 |
+
pos_target_input_name = 'conditioning'
|
| 89 |
+
print(f"ReferenceLatent injector targeting FluxGuidance node '{flux_guidance_name}' for positive chain.")
|
| 90 |
+
|
| 91 |
+
if not pos_target_node_id:
|
| 92 |
+
if 'positive' in assembler.workflow[ksampler_id]['inputs']:
|
| 93 |
+
pos_target_node_id = ksampler_id
|
| 94 |
+
pos_target_input_name = 'positive'
|
| 95 |
+
print(f"ReferenceLatent injector targeting KSampler node '{ksampler_name}' for positive chain.")
|
| 96 |
+
else:
|
| 97 |
+
print(f"Warning: Could not find a valid positive injection point for ReferenceLatent chain. Skipping.")
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
current_pos_conditioning = assembler.workflow[pos_target_node_id]['inputs'][pos_target_input_name]
|
| 101 |
+
|
| 102 |
+
neg_target_node_id = ksampler_id
|
| 103 |
+
neg_target_input_name = 'negative'
|
| 104 |
+
if 'negative' not in assembler.workflow[neg_target_node_id]['inputs']:
|
| 105 |
+
print(f"Warning: KSampler node '{ksampler_name}' has no 'negative' input. Skipping negative ReferenceLatent chain.")
|
| 106 |
+
neg_target_node_id = None
|
| 107 |
+
|
| 108 |
+
current_neg_conditioning = None
|
| 109 |
+
if neg_target_node_id:
|
| 110 |
+
current_neg_conditioning = assembler.workflow[neg_target_node_id]['inputs'][neg_target_input_name]
|
| 111 |
+
|
| 112 |
+
for i, img_filename in enumerate(chain_items):
|
| 113 |
+
load_id = assembler._get_unique_id()
|
| 114 |
+
load_node = assembler._get_node_template("LoadImage")
|
| 115 |
+
load_node['inputs']['image'] = img_filename
|
| 116 |
+
load_node['_meta']['title'] = f"Load Reference Image {i+1}"
|
| 117 |
+
assembler.workflow[load_id] = load_node
|
| 118 |
+
|
| 119 |
+
scale_id = assembler._get_unique_id()
|
| 120 |
+
scale_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 121 |
+
scale_node['inputs']['megapixels'] = 1.0
|
| 122 |
+
scale_node['inputs']['upscale_method'] = "lanczos"
|
| 123 |
+
scale_node['inputs']['image'] = [load_id, 0]
|
| 124 |
+
scale_node['_meta']['title'] = f"Scale Reference {i+1}"
|
| 125 |
+
assembler.workflow[scale_id] = scale_node
|
| 126 |
+
|
| 127 |
+
vae_encode_id = assembler._get_unique_id()
|
| 128 |
+
vae_encode_node = assembler._get_node_template("VAEEncode")
|
| 129 |
+
vae_encode_node['inputs']['pixels'] = [scale_id, 0]
|
| 130 |
+
vae_encode_node['inputs']['vae'] = [vae_node_id, 0]
|
| 131 |
+
vae_encode_node['_meta']['title'] = f"VAE Encode Reference {i+1}"
|
| 132 |
+
assembler.workflow[vae_encode_id] = vae_encode_node
|
| 133 |
+
|
| 134 |
+
latent_conn = [vae_encode_id, 0]
|
| 135 |
+
|
| 136 |
+
pos_ref_latent_id = assembler._get_unique_id()
|
| 137 |
+
pos_ref_latent_node = assembler._get_node_template("ReferenceLatent")
|
| 138 |
+
pos_ref_latent_node['inputs']['conditioning'] = current_pos_conditioning
|
| 139 |
+
pos_ref_latent_node['inputs']['latent'] = latent_conn
|
| 140 |
+
pos_ref_latent_node['_meta']['title'] = f"Positive ReferenceLatent {i+1}"
|
| 141 |
+
assembler.workflow[pos_ref_latent_id] = pos_ref_latent_node
|
| 142 |
+
current_pos_conditioning = [pos_ref_latent_id, 0]
|
| 143 |
+
|
| 144 |
+
if neg_target_node_id:
|
| 145 |
+
neg_ref_latent_id = assembler._get_unique_id()
|
| 146 |
+
neg_ref_latent_node = assembler._get_node_template("ReferenceLatent")
|
| 147 |
+
neg_ref_latent_node['inputs']['conditioning'] = current_neg_conditioning
|
| 148 |
+
neg_ref_latent_node['inputs']['latent'] = latent_conn
|
| 149 |
+
neg_ref_latent_node['_meta']['title'] = f"Negative ReferenceLatent {i+1}"
|
| 150 |
+
assembler.workflow[neg_ref_latent_id] = neg_ref_latent_node
|
| 151 |
+
current_neg_conditioning = [neg_ref_latent_id, 0]
|
| 152 |
+
|
| 153 |
+
assembler.workflow[pos_target_node_id]['inputs'][pos_target_input_name] = current_pos_conditioning
|
| 154 |
+
if neg_target_node_id:
|
| 155 |
+
assembler.workflow[neg_target_node_id]['inputs'][neg_target_input_name] = current_neg_conditioning
|
| 156 |
+
|
| 157 |
+
print(f"ReferenceLatent injector applied. Re-routed inputs through {len(chain_items)} reference images.")
|
chain_injectors/sd3_ipadapter_injector.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 6 |
+
if ksampler_name not in assembler.node_map:
|
| 7 |
+
print(f"Warning: KSampler node '{ksampler_name}' not found for SD3 IPAdapter chain. Skipping.")
|
| 8 |
+
return
|
| 9 |
+
|
| 10 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 11 |
+
|
| 12 |
+
if 'model' not in assembler.workflow[ksampler_id]['inputs']:
|
| 13 |
+
print(f"Warning: KSampler node '{ksampler_name}' is missing 'model' input. Skipping SD3 IPAdapter chain.")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
current_model_connection = assembler.workflow[ksampler_id]['inputs']['model']
|
| 17 |
+
|
| 18 |
+
clip_vision_loader_id = assembler._get_unique_id()
|
| 19 |
+
clip_vision_loader_node = assembler._get_node_template("CLIPVisionLoader")
|
| 20 |
+
clip_vision_loader_node['inputs']['clip_name'] = "sigclip_vision_patch14_384.safetensors"
|
| 21 |
+
assembler.workflow[clip_vision_loader_id] = clip_vision_loader_node
|
| 22 |
+
|
| 23 |
+
ipadapter_loader_id = assembler._get_unique_id()
|
| 24 |
+
ipadapter_loader_node = assembler._get_node_template("IPAdapterSD3Loader")
|
| 25 |
+
ipadapter_loader_node['inputs']['ipadapter'] = "ip-adapter_sd35l_instantx.bin"
|
| 26 |
+
ipadapter_loader_node['inputs']['provider'] = "cuda"
|
| 27 |
+
assembler.workflow[ipadapter_loader_id] = ipadapter_loader_node
|
| 28 |
+
|
| 29 |
+
for item_data in chain_items:
|
| 30 |
+
image_loader_id = assembler._get_unique_id()
|
| 31 |
+
image_loader_node = assembler._get_node_template("LoadImage")
|
| 32 |
+
image_loader_node['inputs']['image'] = item_data['image']
|
| 33 |
+
assembler.workflow[image_loader_id] = image_loader_node
|
| 34 |
+
|
| 35 |
+
image_scaler_id = assembler._get_unique_id()
|
| 36 |
+
image_scaler_node = assembler._get_node_template("ImageScaleToTotalPixels")
|
| 37 |
+
image_scaler_node['inputs']['image'] = [image_loader_id, 0]
|
| 38 |
+
image_scaler_node['inputs']['upscale_method'] = 'nearest-exact'
|
| 39 |
+
image_scaler_node['inputs']['megapixels'] = 1.0
|
| 40 |
+
assembler.workflow[image_scaler_id] = image_scaler_node
|
| 41 |
+
|
| 42 |
+
clip_vision_encode_id = assembler._get_unique_id()
|
| 43 |
+
clip_vision_encode_node = assembler._get_node_template("CLIPVisionEncode")
|
| 44 |
+
clip_vision_encode_node['inputs']['crop'] = "center"
|
| 45 |
+
clip_vision_encode_node['inputs']['clip_vision'] = [clip_vision_loader_id, 0]
|
| 46 |
+
clip_vision_encode_node['inputs']['image'] = [image_scaler_id, 0]
|
| 47 |
+
assembler.workflow[clip_vision_encode_id] = clip_vision_encode_node
|
| 48 |
+
|
| 49 |
+
apply_ipa_id = assembler._get_unique_id()
|
| 50 |
+
apply_ipa_node = assembler._get_node_template("ApplyIPAdapterSD3")
|
| 51 |
+
|
| 52 |
+
apply_ipa_node['inputs']['weight'] = item_data.get('weight', 1.0)
|
| 53 |
+
apply_ipa_node['inputs']['start_percent'] = item_data.get('start_percent', 0.0)
|
| 54 |
+
apply_ipa_node['inputs']['end_percent'] = item_data.get('end_percent', 1.0)
|
| 55 |
+
|
| 56 |
+
apply_ipa_node['inputs']['model'] = current_model_connection
|
| 57 |
+
apply_ipa_node['inputs']['ipadapter'] = [ipadapter_loader_id, 0]
|
| 58 |
+
apply_ipa_node['inputs']['image_embed'] = [clip_vision_encode_id, 0]
|
| 59 |
+
|
| 60 |
+
assembler.workflow[apply_ipa_id] = apply_ipa_node
|
| 61 |
+
|
| 62 |
+
current_model_connection = [apply_ipa_id, 0]
|
| 63 |
+
|
| 64 |
+
assembler.workflow[ksampler_id]['inputs']['model'] = current_model_connection
|
| 65 |
+
|
| 66 |
+
print(f"SD3 IPAdapter injector applied. KSampler model input re-routed through {len(chain_items)} IPAdapter(s).")
|
chain_injectors/style_injector.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
flux_guidance_name = chain_definition.get('flux_guidance_node')
|
| 6 |
+
ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
|
| 7 |
+
|
| 8 |
+
target_node_id = None
|
| 9 |
+
target_input_name = None
|
| 10 |
+
|
| 11 |
+
if flux_guidance_name and flux_guidance_name in assembler.node_map:
|
| 12 |
+
flux_guidance_id = assembler.node_map[flux_guidance_name]
|
| 13 |
+
if 'conditioning' in assembler.workflow[flux_guidance_id]['inputs']:
|
| 14 |
+
target_node_id = flux_guidance_id
|
| 15 |
+
target_input_name = 'conditioning'
|
| 16 |
+
|
| 17 |
+
if not target_node_id:
|
| 18 |
+
if ksampler_name in assembler.node_map:
|
| 19 |
+
ksampler_id = assembler.node_map[ksampler_name]
|
| 20 |
+
if 'positive' in assembler.workflow[ksampler_id]['inputs']:
|
| 21 |
+
target_node_id = ksampler_id
|
| 22 |
+
target_input_name = 'positive'
|
| 23 |
+
else:
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
if not target_node_id:
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
current_conditioning = assembler.workflow[target_node_id]['inputs'][target_input_name]
|
| 30 |
+
|
| 31 |
+
style_model_loader_id = assembler._get_unique_id()
|
| 32 |
+
style_model_loader_node = assembler._get_node_template("StyleModelLoader")
|
| 33 |
+
style_model_loader_node['inputs']['style_model_name'] = "flux1-redux-dev.safetensors"
|
| 34 |
+
assembler.workflow[style_model_loader_id] = style_model_loader_node
|
| 35 |
+
|
| 36 |
+
clip_vision_loader_id = assembler._get_unique_id()
|
| 37 |
+
clip_vision_loader_node = assembler._get_node_template("CLIPVisionLoader")
|
| 38 |
+
clip_vision_loader_node['inputs']['clip_name'] = "sigclip_vision_patch14_384.safetensors"
|
| 39 |
+
assembler.workflow[clip_vision_loader_id] = clip_vision_loader_node
|
| 40 |
+
|
| 41 |
+
for item_data in chain_items:
|
| 42 |
+
image = item_data.get('image')
|
| 43 |
+
strength = item_data.get('strength', 1.0)
|
| 44 |
+
if not image or strength is None:
|
| 45 |
+
continue
|
| 46 |
+
|
| 47 |
+
load_image_id = assembler._get_unique_id()
|
| 48 |
+
clip_vision_encode_id = assembler._get_unique_id()
|
| 49 |
+
style_apply_id = assembler._get_unique_id()
|
| 50 |
+
|
| 51 |
+
load_image_node = assembler._get_node_template("LoadImage")
|
| 52 |
+
clip_vision_encode_node = assembler._get_node_template("CLIPVisionEncode")
|
| 53 |
+
style_apply_node = assembler._get_node_template("StyleModelApply")
|
| 54 |
+
|
| 55 |
+
load_image_node['inputs']['image'] = image
|
| 56 |
+
clip_vision_encode_node['inputs']['crop'] = "center"
|
| 57 |
+
clip_vision_encode_node['inputs']['clip_vision'] = [clip_vision_loader_id, 0]
|
| 58 |
+
clip_vision_encode_node['inputs']['image'] = [load_image_id, 0]
|
| 59 |
+
|
| 60 |
+
style_apply_node['inputs']['strength'] = strength
|
| 61 |
+
style_apply_node['inputs']['strength_type'] = "multiply"
|
| 62 |
+
style_apply_node['inputs']['conditioning'] = current_conditioning
|
| 63 |
+
style_apply_node['inputs']['style_model'] = [style_model_loader_id, 0]
|
| 64 |
+
style_apply_node['inputs']['clip_vision_output'] = [clip_vision_encode_id, 0]
|
| 65 |
+
|
| 66 |
+
assembler.workflow[load_image_id] = load_image_node
|
| 67 |
+
assembler.workflow[clip_vision_encode_id] = clip_vision_encode_node
|
| 68 |
+
assembler.workflow[style_apply_id] = style_apply_node
|
| 69 |
+
current_conditioning = [style_apply_id, 0]
|
| 70 |
+
|
| 71 |
+
assembler.workflow[target_node_id]['inputs'][target_input_name] = current_conditioning
|
chain_injectors/vae_injector.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def inject(assembler, chain_definition, chain_items):
|
| 2 |
+
if not chain_items:
|
| 3 |
+
return
|
| 4 |
+
|
| 5 |
+
vae_name = chain_items[0] if isinstance(chain_items, list) else chain_items
|
| 6 |
+
if not vae_name or vae_name == "None":
|
| 7 |
+
return
|
| 8 |
+
|
| 9 |
+
targets = chain_definition.get('targets', [])
|
| 10 |
+
if not targets:
|
| 11 |
+
return
|
| 12 |
+
|
| 13 |
+
vae_loader_id = assembler._get_unique_id()
|
| 14 |
+
vae_loader_node = assembler._get_node_template("VAELoader")
|
| 15 |
+
vae_loader_node['inputs']['vae_name'] = vae_name
|
| 16 |
+
assembler.workflow[vae_loader_id] = vae_loader_node
|
| 17 |
+
|
| 18 |
+
injected_count = 0
|
| 19 |
+
for target_str in targets:
|
| 20 |
+
try:
|
| 21 |
+
node_name, input_name = target_str.split(':')
|
| 22 |
+
if node_name in assembler.node_map:
|
| 23 |
+
node_id = assembler.node_map[node_name]
|
| 24 |
+
assembler.workflow[node_id]['inputs'][input_name] = [vae_loader_id, 0]
|
| 25 |
+
injected_count += 1
|
| 26 |
+
except ValueError:
|
| 27 |
+
print(f"Warning: Invalid VAE injector target format '{target_str}'. Expected 'node_name:input_name'.")
|
| 28 |
+
|
| 29 |
+
if injected_count > 0:
|
| 30 |
+
print(f"VAE injector applied. Rerouted {injected_count} connection(s) to new VAELoader ({vae_name}).")
|
comfy_integration/__init__.py
ADDED
|
File without changes
|
comfy_integration/nodes.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import execution
|
| 3 |
+
import server
|
| 4 |
+
from nodes import (
|
| 5 |
+
init_extra_nodes, CheckpointLoaderSimple, EmptyLatentImage, KSampler,
|
| 6 |
+
VAEDecode, SaveImage, NODE_CLASS_MAPPINGS, LoadImage, VAEEncode,
|
| 7 |
+
VAEEncodeForInpaint, ImagePadForOutpaint, LatentUpscaleBy, RepeatLatentBatch
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def import_custom_nodes() -> None:
|
| 12 |
+
loop = asyncio.new_event_loop()
|
| 13 |
+
asyncio.set_event_loop(loop)
|
| 14 |
+
server_instance = server.PromptServer(loop)
|
| 15 |
+
execution.PromptQueue(server_instance)
|
| 16 |
+
|
| 17 |
+
loop.run_until_complete(init_extra_nodes())
|
| 18 |
+
|
| 19 |
+
import_custom_nodes()
|
| 20 |
+
|
| 21 |
+
CLIPTextEncode = NODE_CLASS_MAPPINGS['CLIPTextEncode']
|
| 22 |
+
CLIPTextEncodeSDXL = NODE_CLASS_MAPPINGS['CLIPTextEncodeSDXL']
|
| 23 |
+
LoraLoader = NODE_CLASS_MAPPINGS['LoraLoader']
|
| 24 |
+
CLIPSetLastLayer = NODE_CLASS_MAPPINGS['CLIPSetLastLayer']
|
| 25 |
+
|
| 26 |
+
if 'EmptyHunyuanImageLatent' in NODE_CLASS_MAPPINGS:
|
| 27 |
+
EmptyHunyuanImageLatent = NODE_CLASS_MAPPINGS['EmptyHunyuanImageLatent']
|
| 28 |
+
else:
|
| 29 |
+
print("⚠️ Warning: 'EmptyHunyuanImageLatent' not found in NODE_CLASS_MAPPINGS. HunyuanImage txt2img may fail if this node is required.")
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
KSamplerNode = NODE_CLASS_MAPPINGS['KSampler']
|
| 33 |
+
SAMPLER_CHOICES = KSamplerNode.INPUT_TYPES()["required"]["sampler_name"][0]
|
| 34 |
+
SCHEDULER_CHOICES = KSamplerNode.INPUT_TYPES()["required"]["scheduler"][0]
|
| 35 |
+
except Exception:
|
| 36 |
+
print("⚠️ Could not dynamically get sampler/scheduler choices, using fallback list.")
|
| 37 |
+
SAMPLER_CHOICES = ['euler', 'dpmpp_2m_sde_gpu']
|
| 38 |
+
SCHEDULER_CHOICES = ['normal', 'karras']
|
| 39 |
+
|
| 40 |
+
checkpointloadersimple = CheckpointLoaderSimple()
|
| 41 |
+
loraloader = LoraLoader()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
print("✅ ComfyUI custom nodes and class mappings are ready.")
|
comfy_integration/setup.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Install the pinned ComfyUI runtime without overwriting application code."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import yaml
|
| 12 |
+
|
| 13 |
+
from core.settings import CATEGORY_TO_DIR_MAP, INPUT_DIR, OUTPUT_DIR
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
APP_DIR = Path(__file__).resolve().parents[1]
|
| 17 |
+
LOCK_FILE = APP_DIR / "vendor.lock.yaml"
|
| 18 |
+
VENDOR_DIR = APP_DIR / "_vendor"
|
| 19 |
+
CUSTOM_NODES_DIR = APP_DIR / "custom_nodes"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _bounded_env_int(name: str, default: int, minimum: int, maximum: int) -> int:
|
| 23 |
+
try:
|
| 24 |
+
value = int(os.getenv(name, str(default)))
|
| 25 |
+
except ValueError:
|
| 26 |
+
value = default
|
| 27 |
+
return max(minimum, min(maximum, value))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
GIT_TIMEOUT_SECONDS = _bounded_env_int(
|
| 31 |
+
"IMAGEGEN_GIT_TIMEOUT_SECONDS", 180, 30, 900
|
| 32 |
+
)
|
| 33 |
+
GIT_NETWORK_ATTEMPTS = _bounded_env_int("IMAGEGEN_GIT_ATTEMPTS", 2, 1, 5)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _run_git(*args: str, cwd: Path | None = None) -> str:
|
| 37 |
+
attempts = GIT_NETWORK_ATTEMPTS if args and args[0] == "fetch" else 1
|
| 38 |
+
for attempt in range(1, attempts + 1):
|
| 39 |
+
try:
|
| 40 |
+
completed = subprocess.run(
|
| 41 |
+
["git", *args],
|
| 42 |
+
cwd=str(cwd) if cwd else None,
|
| 43 |
+
check=True,
|
| 44 |
+
stdout=subprocess.PIPE,
|
| 45 |
+
stderr=subprocess.STDOUT,
|
| 46 |
+
text=True,
|
| 47 |
+
timeout=GIT_TIMEOUT_SECONDS,
|
| 48 |
+
)
|
| 49 |
+
return completed.stdout.strip()
|
| 50 |
+
except subprocess.TimeoutExpired as exc:
|
| 51 |
+
if attempt == attempts:
|
| 52 |
+
raise RuntimeError(
|
| 53 |
+
f"Git 操作超过 {GIT_TIMEOUT_SECONDS} 秒:git {args[0]}。"
|
| 54 |
+
"可稍后重启,或设置 COMFYUI_PATH 使用本地 checkout。"
|
| 55 |
+
) from exc
|
| 56 |
+
print(f"⚠️ Git {args[0]} 超时,正在重试({attempt}/{attempts})…")
|
| 57 |
+
except subprocess.CalledProcessError:
|
| 58 |
+
if attempt == attempts:
|
| 59 |
+
raise
|
| 60 |
+
print(f"⚠️ Git {args[0]} 失败,正在重试({attempt}/{attempts})…")
|
| 61 |
+
raise RuntimeError("Unreachable git retry state")
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _ensure_pinned_repo(name: str, url: str, revision: str, destination: Path) -> None:
|
| 65 |
+
if destination.exists() and not (destination / ".git").is_dir():
|
| 66 |
+
raise RuntimeError(
|
| 67 |
+
f"{name} 目录已存在但不是 Git 仓库:{destination}。"
|
| 68 |
+
"请移走该目录后重新启动。"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if not destination.exists():
|
| 72 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 73 |
+
print(f"--- [Vendor] Cloning pinned {name} ---")
|
| 74 |
+
partial = destination.with_name(f"{destination.name}.partial")
|
| 75 |
+
last_error = None
|
| 76 |
+
for attempt in range(1, GIT_NETWORK_ATTEMPTS + 1):
|
| 77 |
+
if partial.exists():
|
| 78 |
+
shutil.rmtree(partial)
|
| 79 |
+
try:
|
| 80 |
+
_run_git(
|
| 81 |
+
"clone", "--filter=blob:none", "--no-checkout", url, str(partial)
|
| 82 |
+
)
|
| 83 |
+
partial.replace(destination)
|
| 84 |
+
last_error = None
|
| 85 |
+
break
|
| 86 |
+
except (subprocess.CalledProcessError, RuntimeError) as exc:
|
| 87 |
+
last_error = exc
|
| 88 |
+
if attempt < GIT_NETWORK_ATTEMPTS:
|
| 89 |
+
print(f"⚠️ {name} clone 失败,正在重试({attempt}/{GIT_NETWORK_ATTEMPTS})…")
|
| 90 |
+
if last_error is not None:
|
| 91 |
+
raise RuntimeError(
|
| 92 |
+
f"无法拉取 {name}。可稍后重启;本地离线运行可设置 "
|
| 93 |
+
"COMFYUI_PATH,并按需设置 IMAGEGEN_SKIP_CUSTOM_NODES=1。"
|
| 94 |
+
) from last_error
|
| 95 |
+
|
| 96 |
+
current = ""
|
| 97 |
+
try:
|
| 98 |
+
current = _run_git("rev-parse", "HEAD", cwd=destination)
|
| 99 |
+
except (subprocess.CalledProcessError, RuntimeError):
|
| 100 |
+
pass
|
| 101 |
+
|
| 102 |
+
if current != revision:
|
| 103 |
+
print(f"--- [Vendor] Checking out {name} @ {revision[:12]} ---")
|
| 104 |
+
_run_git("fetch", "--depth", "1", "origin", revision, cwd=destination)
|
| 105 |
+
_run_git("checkout", "--detach", "--force", "FETCH_HEAD", cwd=destination)
|
| 106 |
+
|
| 107 |
+
actual = _run_git("rev-parse", "HEAD", cwd=destination)
|
| 108 |
+
if actual != revision:
|
| 109 |
+
raise RuntimeError(
|
| 110 |
+
f"{name} 版本不匹配:期望 {revision},实际 {actual}。"
|
| 111 |
+
)
|
| 112 |
+
print(f"✅ {name} ready @ {actual[:12]}")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def _load_lock() -> dict:
|
| 116 |
+
with LOCK_FILE.open("r", encoding="utf-8") as handle:
|
| 117 |
+
data = yaml.safe_load(handle) or {}
|
| 118 |
+
if "comfyui" not in data:
|
| 119 |
+
raise RuntimeError(f"Missing comfyui entry in {LOCK_FILE}")
|
| 120 |
+
return data
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def initialize_comfyui() -> Path:
|
| 124 |
+
"""Prepare pinned sources and make ComfyUI importable.
|
| 125 |
+
|
| 126 |
+
Set ``COMFYUI_PATH`` to use an existing local checkout. This is the
|
| 127 |
+
recommended offline/local-development route.
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
lock = _load_lock()
|
| 131 |
+
configured_path = os.getenv("COMFYUI_PATH", "").strip()
|
| 132 |
+
|
| 133 |
+
if configured_path:
|
| 134 |
+
comfyui_path = Path(configured_path).expanduser().resolve()
|
| 135 |
+
if not (comfyui_path / "nodes.py").is_file():
|
| 136 |
+
raise RuntimeError(f"COMFYUI_PATH is not a ComfyUI checkout: {comfyui_path}")
|
| 137 |
+
else:
|
| 138 |
+
comfyui_path = VENDOR_DIR / "ComfyUI"
|
| 139 |
+
comfy = lock["comfyui"]
|
| 140 |
+
_ensure_pinned_repo("ComfyUI", comfy["url"], comfy["revision"], comfyui_path)
|
| 141 |
+
|
| 142 |
+
CUSTOM_NODES_DIR.mkdir(parents=True, exist_ok=True)
|
| 143 |
+
if os.getenv("IMAGEGEN_SKIP_CUSTOM_NODES", "0").lower() not in {"1", "true", "yes"}:
|
| 144 |
+
for name, spec in (lock.get("custom_nodes") or {}).items():
|
| 145 |
+
_ensure_pinned_repo(name, spec["url"], spec["revision"], CUSTOM_NODES_DIR / name)
|
| 146 |
+
|
| 147 |
+
# ComfyUI contains a top-level `utils` package. The application uses the
|
| 148 |
+
# collision-free `imagegen_utils` package, so ComfyUI can safely come first.
|
| 149 |
+
comfyui_str = str(comfyui_path)
|
| 150 |
+
if comfyui_str not in sys.path:
|
| 151 |
+
sys.path.insert(0, comfyui_str)
|
| 152 |
+
|
| 153 |
+
for relative_path in CATEGORY_TO_DIR_MAP.values():
|
| 154 |
+
(APP_DIR / relative_path).mkdir(parents=True, exist_ok=True)
|
| 155 |
+
(APP_DIR / INPUT_DIR).mkdir(parents=True, exist_ok=True)
|
| 156 |
+
(APP_DIR / OUTPUT_DIR).mkdir(parents=True, exist_ok=True)
|
| 157 |
+
|
| 158 |
+
import comfy.model_management # noqa: F401
|
| 159 |
+
|
| 160 |
+
print(f"✅ ComfyUI initialized from isolated path: {comfyui_path}")
|
| 161 |
+
return comfyui_path
|
core/__init__.py
ADDED
|
File without changes
|
core/execution_plan.py
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build small sequential generation plans for PK and multi-image workflows.
|
| 2 |
+
|
| 3 |
+
The in-process ComfyUI runtime is intentionally single-model-at-a-time. This
|
| 4 |
+
module therefore expands comparisons into bounded sequential runs instead of
|
| 5 |
+
trying to keep several checkpoints resident on one ZeroGPU allocation.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import random
|
| 11 |
+
from collections.abc import Callable, Iterable, Sequence
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from itertools import pairwise
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from typing import Any
|
| 16 |
+
|
| 17 |
+
from PIL import Image
|
| 18 |
+
|
| 19 |
+
from core.model_capabilities import supports_chain_for_model
|
| 20 |
+
from core.runtime_config import CONFIG
|
| 21 |
+
from core.settings import (
|
| 22 |
+
ARCHITECTURES_CONFIG,
|
| 23 |
+
FEATURES_CONFIG,
|
| 24 |
+
MODEL_DEFAULTS_CONFIG,
|
| 25 |
+
MODEL_MAP_CHECKPOINT,
|
| 26 |
+
MODEL_TYPE_MAP,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
MODE_SINGLE = "single"
|
| 30 |
+
MODE_MODEL_PK = "model_pk"
|
| 31 |
+
MODE_MULTI_INDEPENDENT = "multi_independent"
|
| 32 |
+
MODE_MULTI_MODEL_GRID = "multi_model_grid"
|
| 33 |
+
MODE_MULTI_REFERENCE = "multi_reference"
|
| 34 |
+
|
| 35 |
+
RUN_MODE_CHOICES = [
|
| 36 |
+
("普通生成", MODE_SINGLE),
|
| 37 |
+
("模型 PK:同一输入对比多个模型", MODE_MODEL_PK),
|
| 38 |
+
("多图独立:每张图分别处理", MODE_MULTI_INDEPENDENT),
|
| 39 |
+
("多图 × 多模型:组合对比", MODE_MULTI_MODEL_GRID),
|
| 40 |
+
("多图融合:多张参考图生成一组结果", MODE_MULTI_REFERENCE),
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
INDEPENDENT_IMAGE_TASK_KEYS = {
|
| 44 |
+
"img2img": "img2img_image",
|
| 45 |
+
"outpaint": "outpaint_image",
|
| 46 |
+
"hires_fix": "hires_image",
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
COMPARISON_CHAIN_INPUT_KEYS = (
|
| 50 |
+
"lora_data",
|
| 51 |
+
"controlnet_data",
|
| 52 |
+
"anima_controlnet_lllite_data",
|
| 53 |
+
"diffsynth_controlnet_data",
|
| 54 |
+
"krea2_controlnet_data",
|
| 55 |
+
"ipadapter_data",
|
| 56 |
+
"sd3_ipadapter_chain",
|
| 57 |
+
"flux1_ipadapter_data",
|
| 58 |
+
"style_data",
|
| 59 |
+
"embedding_data",
|
| 60 |
+
"conditioning_data",
|
| 61 |
+
"reference_latent_data",
|
| 62 |
+
"hidream_o1_reference_data",
|
| 63 |
+
"joyai_reference_data",
|
| 64 |
+
"krea2_identity_edit_data",
|
| 65 |
+
"krea2_reference_edit_data",
|
| 66 |
+
"qwen_image_edit_data",
|
| 67 |
+
"boogu_edit_data",
|
| 68 |
+
"reference_image_data",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# (chain name, pipeline input key, maximum images supported by its injector)
|
| 72 |
+
REFERENCE_CHAIN_SPECS = {
|
| 73 |
+
"qwen_image_edit": ("qwen_image_edit_data", 3),
|
| 74 |
+
"joyai_image": ("joyai_reference_data", 2),
|
| 75 |
+
"boogu_image_edit": ("boogu_edit_data", 10),
|
| 76 |
+
"reference_image": ("reference_image_data", 10),
|
| 77 |
+
"reference_latent": ("reference_latent_data", 10),
|
| 78 |
+
"hidream_o1_reference": ("hidream_o1_reference_data", 10),
|
| 79 |
+
"krea2_identity_edit": ("krea2_identity_edit_data", 2),
|
| 80 |
+
"krea2_style_reference": ("krea2_reference_edit_data", 3),
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class ExecutionPlanError(ValueError):
|
| 85 |
+
pass
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@dataclass(frozen=True)
|
| 89 |
+
class PlannedGeneration:
|
| 90 |
+
inputs: dict[str, Any]
|
| 91 |
+
caption: str
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _unique(values: Iterable[str]) -> list[str]:
|
| 95 |
+
return list(dict.fromkeys(value for value in values if value))
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def _caption(label: str, values: dict[str, Any]) -> str:
|
| 99 |
+
seed = values.get("seed", "-")
|
| 100 |
+
steps = values.get("num_inference_steps", "-")
|
| 101 |
+
cfg = values.get("guidance_scale", "-")
|
| 102 |
+
return f"{label} · Seed {seed} · {steps} 步 · CFG {cfg}"
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def _workflow_type(model_name: str) -> str:
|
| 106 |
+
architecture = MODEL_TYPE_MAP.get(model_name, "SDXL")
|
| 107 |
+
architecture_info = ARCHITECTURES_CONFIG.get("architectures", {}).get(
|
| 108 |
+
architecture, {}
|
| 109 |
+
)
|
| 110 |
+
return architecture_info.get(
|
| 111 |
+
"model_type", architecture.lower().replace(" ", "").replace(".", "")
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def _model_defaults(model_name: str) -> dict[str, Any]:
|
| 116 |
+
workflow_type = _workflow_type(model_name)
|
| 117 |
+
defaults = {
|
| 118 |
+
"steps": 25,
|
| 119 |
+
"cfg": 7.0,
|
| 120 |
+
"sampler_name": "euler",
|
| 121 |
+
"scheduler": "simple",
|
| 122 |
+
}
|
| 123 |
+
defaults.update(MODEL_DEFAULTS_CONFIG.get("Default", {}))
|
| 124 |
+
type_key = next(
|
| 125 |
+
(
|
| 126 |
+
key
|
| 127 |
+
for key in MODEL_DEFAULTS_CONFIG
|
| 128 |
+
if key.lower().replace(" ", "-").replace(".", "")
|
| 129 |
+
== workflow_type.lower()
|
| 130 |
+
),
|
| 131 |
+
None,
|
| 132 |
+
)
|
| 133 |
+
if type_key:
|
| 134 |
+
section = MODEL_DEFAULTS_CONFIG.get(type_key, {})
|
| 135 |
+
defaults.update(section.get("_defaults", {}))
|
| 136 |
+
defaults.update(section.get(model_name, {}))
|
| 137 |
+
return defaults
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def _for_model(
|
| 141 |
+
base_inputs: dict[str, Any], model_name: str, use_model_defaults: bool
|
| 142 |
+
) -> dict[str, Any]:
|
| 143 |
+
# Pipeline processing replaces and occasionally mutates chain containers.
|
| 144 |
+
# Copy those containers while sharing immutable/PIL payloads.
|
| 145 |
+
values = {
|
| 146 |
+
key: list(value)
|
| 147 |
+
if isinstance(value, list)
|
| 148 |
+
else dict(value)
|
| 149 |
+
if isinstance(value, dict)
|
| 150 |
+
else value
|
| 151 |
+
for key, value in base_inputs.items()
|
| 152 |
+
}
|
| 153 |
+
values["model_display_name"] = model_name
|
| 154 |
+
if use_model_defaults:
|
| 155 |
+
defaults = _model_defaults(model_name)
|
| 156 |
+
values.update(
|
| 157 |
+
{
|
| 158 |
+
"num_inference_steps": defaults.get("steps", 20),
|
| 159 |
+
"guidance_scale": defaults.get("cfg", 1.0),
|
| 160 |
+
"sampler": defaults.get("sampler_name", "euler"),
|
| 161 |
+
"scheduler": defaults.get("scheduler", "simple"),
|
| 162 |
+
}
|
| 163 |
+
)
|
| 164 |
+
return values
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def _make_fair_comparison(values: dict[str, Any]) -> None:
|
| 168 |
+
"""Keep V1 comparisons to capabilities shared by every base checkpoint."""
|
| 169 |
+
|
| 170 |
+
for key in COMPARISON_CHAIN_INPUT_KEYS:
|
| 171 |
+
values[key] = []
|
| 172 |
+
values["pid_settings"] = "OFF"
|
| 173 |
+
values["vae_source"] = None
|
| 174 |
+
values["vae_id"] = None
|
| 175 |
+
values["vae_file"] = None
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def load_uploaded_images(uploaded_files: Sequence[Any] | None) -> list[Image.Image]:
|
| 179 |
+
"""Materialize Gradio File values as detached PIL images."""
|
| 180 |
+
|
| 181 |
+
images: list[Image.Image] = []
|
| 182 |
+
total_megapixels = 0.0
|
| 183 |
+
for item in uploaded_files or []:
|
| 184 |
+
raw_path = getattr(item, "name", item)
|
| 185 |
+
if not raw_path:
|
| 186 |
+
continue
|
| 187 |
+
path = Path(str(raw_path))
|
| 188 |
+
if not path.is_file():
|
| 189 |
+
raise ExecutionPlanError(f"找不到上传图片:{path.name}")
|
| 190 |
+
try:
|
| 191 |
+
with Image.open(path) as source:
|
| 192 |
+
source.load()
|
| 193 |
+
megapixels = (source.width * source.height) / 1_000_000
|
| 194 |
+
if megapixels > CONFIG.max_input_megapixels:
|
| 195 |
+
raise ExecutionPlanError(
|
| 196 |
+
f"图片“{path.name}”为 {megapixels:.1f} MP,超过单图上限 "
|
| 197 |
+
f"{CONFIG.max_input_megapixels:g} MP。"
|
| 198 |
+
)
|
| 199 |
+
total_megapixels += megapixels
|
| 200 |
+
if total_megapixels > CONFIG.max_reference_megapixels:
|
| 201 |
+
raise ExecutionPlanError(
|
| 202 |
+
f"上传图片累计为 {total_megapixels:.1f} MP,超过上限 "
|
| 203 |
+
f"{CONFIG.max_reference_megapixels:g} MP;请缩小图片或减少数量。"
|
| 204 |
+
)
|
| 205 |
+
images.append(source.convert("RGB").copy())
|
| 206 |
+
except ExecutionPlanError:
|
| 207 |
+
raise
|
| 208 |
+
except Exception as exc:
|
| 209 |
+
raise ExecutionPlanError(f"无法读取图片“{path.name}”:{exc}") from exc
|
| 210 |
+
|
| 211 |
+
if len(images) > CONFIG.max_multi_images:
|
| 212 |
+
raise ExecutionPlanError(
|
| 213 |
+
f"一次最多上传 {CONFIG.max_multi_images} 张图片;当前为 {len(images)} 张。"
|
| 214 |
+
)
|
| 215 |
+
return images
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def _pick_reference_chain(model_name: str, role: str) -> tuple[str, str, int]:
|
| 219 |
+
workflow_type = _workflow_type(model_name)
|
| 220 |
+
enabled = set(
|
| 221 |
+
FEATURES_CONFIG.get(workflow_type, {}).get("enabled_chains", [])
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
if role == "identity":
|
| 225 |
+
order = ["krea2_identity_edit"]
|
| 226 |
+
elif role == "style":
|
| 227 |
+
# The generic FLUX style injector has a different image/weight schema;
|
| 228 |
+
# keep this high-level path limited to the validated Krea reference chain.
|
| 229 |
+
order = ["krea2_style_reference"]
|
| 230 |
+
else:
|
| 231 |
+
order = [
|
| 232 |
+
"qwen_image_edit",
|
| 233 |
+
"joyai_image",
|
| 234 |
+
"boogu_image_edit",
|
| 235 |
+
"reference_image",
|
| 236 |
+
"reference_latent",
|
| 237 |
+
"hidream_o1_reference",
|
| 238 |
+
"krea2_identity_edit",
|
| 239 |
+
"krea2_style_reference",
|
| 240 |
+
]
|
| 241 |
+
|
| 242 |
+
for chain_name in order:
|
| 243 |
+
if (
|
| 244 |
+
chain_name in enabled
|
| 245 |
+
and chain_name in REFERENCE_CHAIN_SPECS
|
| 246 |
+
and supports_chain_for_model(model_name, chain_name)
|
| 247 |
+
):
|
| 248 |
+
input_key, maximum = REFERENCE_CHAIN_SPECS[chain_name]
|
| 249 |
+
return chain_name, input_key, maximum
|
| 250 |
+
|
| 251 |
+
if role in {"identity", "style"}:
|
| 252 |
+
raise ExecutionPlanError(
|
| 253 |
+
f"模型“{model_name}”不支持所选的{('身份' if role == 'identity' else '风格')}参考方式。"
|
| 254 |
+
)
|
| 255 |
+
raise ExecutionPlanError(
|
| 256 |
+
f"模型“{model_name}”没有可自动使用的多图参考链;请换用编辑/多模态模型。"
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def build_execution_plan(
|
| 261 |
+
base_inputs: dict[str, Any],
|
| 262 |
+
mode: str = MODE_SINGLE,
|
| 263 |
+
extra_models: Sequence[str] | None = None,
|
| 264 |
+
images: Sequence[Image.Image] | None = None,
|
| 265 |
+
reference_role: str = "auto",
|
| 266 |
+
use_model_defaults: bool = True,
|
| 267 |
+
) -> list[PlannedGeneration]:
|
| 268 |
+
"""Expand one UI submission into a bounded list of sequential runs."""
|
| 269 |
+
|
| 270 |
+
if mode not in {choice[1] for choice in RUN_MODE_CHOICES}:
|
| 271 |
+
raise ExecutionPlanError(f"未知运行模式:{mode}")
|
| 272 |
+
|
| 273 |
+
base_model = str(base_inputs.get("model_display_name") or "")
|
| 274 |
+
if base_model not in MODEL_MAP_CHECKPOINT:
|
| 275 |
+
raise ExecutionPlanError("请先选择有效模型。")
|
| 276 |
+
|
| 277 |
+
comparison_mode = mode in {MODE_MODEL_PK, MODE_MULTI_MODEL_GRID}
|
| 278 |
+
models = _unique(
|
| 279 |
+
[base_model, *(extra_models or [])] if comparison_mode else [base_model]
|
| 280 |
+
)
|
| 281 |
+
unknown_models = [name for name in models if name not in MODEL_MAP_CHECKPOINT]
|
| 282 |
+
if unknown_models:
|
| 283 |
+
raise ExecutionPlanError(f"未知模型:{', '.join(unknown_models)}")
|
| 284 |
+
if len(models) > CONFIG.max_pk_models:
|
| 285 |
+
raise ExecutionPlanError(
|
| 286 |
+
f"模型 PK 最多 {CONFIG.max_pk_models} 个模型;当前为 {len(models)} 个。"
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
if mode in {MODE_MODEL_PK, MODE_MULTI_MODEL_GRID} and len(models) < 2:
|
| 290 |
+
raise ExecutionPlanError("模型 PK 至少需要再选择 1 个对比模型。")
|
| 291 |
+
|
| 292 |
+
source_images = list(images or [])
|
| 293 |
+
shared_seed = base_inputs.get("seed", -1)
|
| 294 |
+
try:
|
| 295 |
+
shared_seed = int(shared_seed)
|
| 296 |
+
except (TypeError, ValueError):
|
| 297 |
+
shared_seed = -1
|
| 298 |
+
if shared_seed < 0 and mode != MODE_SINGLE:
|
| 299 |
+
shared_seed = random.randint(0, 2**32 - 1)
|
| 300 |
+
|
| 301 |
+
plan: list[PlannedGeneration] = []
|
| 302 |
+
if mode == MODE_SINGLE:
|
| 303 |
+
plan.append(PlannedGeneration(dict(base_inputs), base_model))
|
| 304 |
+
|
| 305 |
+
elif mode == MODE_MODEL_PK:
|
| 306 |
+
for model_name in models:
|
| 307 |
+
values = _for_model(base_inputs, model_name, use_model_defaults)
|
| 308 |
+
_make_fair_comparison(values)
|
| 309 |
+
values["seed"] = shared_seed
|
| 310 |
+
plan.append(
|
| 311 |
+
PlannedGeneration(values, _caption(f"模型 PK · {model_name}", values))
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
elif mode in {MODE_MULTI_INDEPENDENT, MODE_MULTI_MODEL_GRID}:
|
| 315 |
+
task_type = str(base_inputs.get("task_type") or "")
|
| 316 |
+
task_input_key = INDEPENDENT_IMAGE_TASK_KEYS.get(task_type)
|
| 317 |
+
if not task_input_key:
|
| 318 |
+
raise ExecutionPlanError(
|
| 319 |
+
"多图独立处理仅支持图生图、扩图和高清修复;局部重绘需要逐张绘制蒙版。"
|
| 320 |
+
)
|
| 321 |
+
if not source_images:
|
| 322 |
+
raise ExecutionPlanError("请上传至少 1 张批量输入图片。")
|
| 323 |
+
target_models = models if mode == MODE_MULTI_MODEL_GRID else [base_model]
|
| 324 |
+
# Keep one checkpoint active for all its inputs before switching. This
|
| 325 |
+
# avoids needless reloads while preserving Gallery captions by source.
|
| 326 |
+
for model_name in target_models:
|
| 327 |
+
for image_index, image in enumerate(source_images, start=1):
|
| 328 |
+
values = _for_model(
|
| 329 |
+
base_inputs,
|
| 330 |
+
model_name,
|
| 331 |
+
use_model_defaults if mode == MODE_MULTI_MODEL_GRID else False,
|
| 332 |
+
)
|
| 333 |
+
if mode == MODE_MULTI_MODEL_GRID:
|
| 334 |
+
_make_fair_comparison(values)
|
| 335 |
+
values["seed"] = shared_seed
|
| 336 |
+
values[task_input_key] = image
|
| 337 |
+
caption = _caption(f"输入 {image_index} · {model_name}", values)
|
| 338 |
+
plan.append(PlannedGeneration(values, caption))
|
| 339 |
+
|
| 340 |
+
elif mode == MODE_MULTI_REFERENCE:
|
| 341 |
+
if str(base_inputs.get("task_type")) != "txt2img":
|
| 342 |
+
raise ExecutionPlanError("多图融合请把任务切换为“文生图”;参考图会直接进入编辑模型。")
|
| 343 |
+
if not source_images:
|
| 344 |
+
raise ExecutionPlanError("多图融合需要上传至少 1 张参考图。")
|
| 345 |
+
chain_name, input_key, maximum = _pick_reference_chain(
|
| 346 |
+
base_model, reference_role
|
| 347 |
+
)
|
| 348 |
+
if len(source_images) > maximum:
|
| 349 |
+
raise ExecutionPlanError(
|
| 350 |
+
f"当前模型的 {chain_name} 最多支持 {maximum} 张参考图。"
|
| 351 |
+
)
|
| 352 |
+
values = _for_model(base_inputs, base_model, False)
|
| 353 |
+
existing = [value for value in values.get(input_key, []) if value is not None]
|
| 354 |
+
values[input_key] = [*existing, *source_images][:maximum]
|
| 355 |
+
values["seed"] = shared_seed
|
| 356 |
+
plan.append(
|
| 357 |
+
PlannedGeneration(
|
| 358 |
+
values,
|
| 359 |
+
_caption(
|
| 360 |
+
f"多图融合 · {base_model} · {len(source_images)} 张参考图",
|
| 361 |
+
values,
|
| 362 |
+
),
|
| 363 |
+
)
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
if len(plan) > CONFIG.max_plan_jobs:
|
| 367 |
+
raise ExecutionPlanError(
|
| 368 |
+
f"本次会产生 {len(plan)} 个任务,超过上限 {CONFIG.max_plan_jobs};请减少图片或模型。"
|
| 369 |
+
)
|
| 370 |
+
batch_size = max(1, int(base_inputs.get("batch_size") or 1))
|
| 371 |
+
estimated_outputs = len(plan) * batch_size
|
| 372 |
+
if estimated_outputs > CONFIG.max_plan_outputs:
|
| 373 |
+
raise ExecutionPlanError(
|
| 374 |
+
f"预计输出 {estimated_outputs} 张,超过上限 {CONFIG.max_plan_outputs};"
|
| 375 |
+
"请减少模型、输入图片或单次生成数量。"
|
| 376 |
+
)
|
| 377 |
+
# Release Comfy's global model state only at an actual model boundary. The
|
| 378 |
+
# final model remains warm for a likely follow-up generation.
|
| 379 |
+
for current, following in pairwise(plan):
|
| 380 |
+
if (
|
| 381 |
+
current.inputs.get("model_display_name")
|
| 382 |
+
!= following.inputs.get("model_display_name")
|
| 383 |
+
):
|
| 384 |
+
current.inputs["_release_models_after_run"] = True
|
| 385 |
+
return plan
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
class _PlanProgress:
|
| 389 |
+
def __init__(self, parent: Any, index: int, total: int, caption: str):
|
| 390 |
+
self.parent = parent
|
| 391 |
+
self.index = index
|
| 392 |
+
self.total = total
|
| 393 |
+
self.caption = caption
|
| 394 |
+
|
| 395 |
+
def __call__(self, value: float = 0.0, desc: str | None = None):
|
| 396 |
+
if not self.parent:
|
| 397 |
+
return None
|
| 398 |
+
try:
|
| 399 |
+
fraction = max(0.0, min(1.0, float(value)))
|
| 400 |
+
except (TypeError, ValueError):
|
| 401 |
+
fraction = 0.0
|
| 402 |
+
overall = (self.index + fraction) / self.total
|
| 403 |
+
detail = f"[{self.index + 1}/{self.total}] {self.caption}"
|
| 404 |
+
if desc:
|
| 405 |
+
detail += f" · {desc}"
|
| 406 |
+
return self.parent(overall, desc=detail)
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
def execute_generation_plan(
|
| 410 |
+
plan: Sequence[PlannedGeneration],
|
| 411 |
+
generate: Callable[[dict[str, Any], Any], Any],
|
| 412 |
+
progress: Any = None,
|
| 413 |
+
cancel_event: Any = None,
|
| 414 |
+
) -> tuple[list[Any], str]:
|
| 415 |
+
"""Run the plan sequentially and retain partial successes."""
|
| 416 |
+
|
| 417 |
+
gallery: list[Any] = []
|
| 418 |
+
summary: list[str] = []
|
| 419 |
+
total = max(1, len(plan))
|
| 420 |
+
for index, item in enumerate(plan):
|
| 421 |
+
if cancel_event is not None and cancel_event.is_set():
|
| 422 |
+
if gallery:
|
| 423 |
+
summary.append("- ⏹️ 已取消:后续组合未执行,已保留成功结果。")
|
| 424 |
+
break
|
| 425 |
+
raise ExecutionPlanError("任务已取消,后续组合未执行。")
|
| 426 |
+
try:
|
| 427 |
+
result = generate(
|
| 428 |
+
item.inputs,
|
| 429 |
+
_PlanProgress(progress, index, total, item.caption),
|
| 430 |
+
)
|
| 431 |
+
paths = result if isinstance(result, list) else ([result] if result else [])
|
| 432 |
+
for output_index, path in enumerate(paths, start=1):
|
| 433 |
+
caption = item.caption
|
| 434 |
+
if len(paths) > 1:
|
| 435 |
+
caption += f" · 结果 {output_index}"
|
| 436 |
+
gallery.append((path, caption))
|
| 437 |
+
summary.append(f"- ✅ {item.caption}:{len(paths)} 张")
|
| 438 |
+
except Exception as exc:
|
| 439 |
+
if cancel_event is not None and cancel_event.is_set():
|
| 440 |
+
if gallery:
|
| 441 |
+
summary.append("- ⏹️ 已取消:后续组合未执行,已保留成功结果。")
|
| 442 |
+
break
|
| 443 |
+
raise
|
| 444 |
+
summary.append(f"- ❌ {item.caption}:{exc}")
|
| 445 |
+
|
| 446 |
+
if not gallery:
|
| 447 |
+
raise ExecutionPlanError("本次任务没有成功生成图片。\n" + "\n".join(summary))
|
| 448 |
+
if progress:
|
| 449 |
+
progress(1.0, desc="全部组合执行完成。")
|
| 450 |
+
return gallery, "### 本次执行\n" + "\n".join(summary)
|
core/generation_logic.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Dict
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
from core.pipelines.sd_image_pipeline import SdImagePipeline
|
| 5 |
+
|
| 6 |
+
sd_image_pipeline = SdImagePipeline()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def generate_image_wrapper(ui_inputs: dict, progress=gr.Progress(track_tqdm=True)):
|
| 10 |
+
return sd_image_pipeline.run(ui_inputs=ui_inputs, progress=progress)
|
core/model_capabilities.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Small checkpoint-level capability guards layered over architecture YAML."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
_EDIT_ONLY_CHAINS = {
|
| 6 |
+
"qwen_image_edit",
|
| 7 |
+
"boogu_image_edit",
|
| 8 |
+
"reference_image", # Mage-Flow edit checkpoints
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def supports_chain_for_model(model_name: str, chain_name: str) -> bool:
|
| 13 |
+
"""Return whether a concrete checkpoint is known to support a chain.
|
| 14 |
+
|
| 15 |
+
Most capabilities apply to every checkpoint of an architecture. Qwen,
|
| 16 |
+
Boogu, and Mage-Flow register generation and edit checkpoints together, so
|
| 17 |
+
their reference injectors require the concrete Edit variant.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
if chain_name in _EDIT_ONLY_CHAINS:
|
| 21 |
+
return "edit" in str(model_name).casefold()
|
| 22 |
+
return True
|
core/model_manager.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gc
|
| 2 |
+
from typing import List
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from imagegen_utils.app_utils import _ensure_model_downloaded
|
| 5 |
+
from core.settings import ALL_MODEL_MAP
|
| 6 |
+
|
| 7 |
+
class ModelManager:
|
| 8 |
+
_instance = None
|
| 9 |
+
|
| 10 |
+
def __new__(cls, *args, **kwargs):
|
| 11 |
+
if not cls._instance:
|
| 12 |
+
cls._instance = super(ModelManager, cls).__new__(cls, *args, **kwargs)
|
| 13 |
+
return cls._instance
|
| 14 |
+
|
| 15 |
+
def __init__(self):
|
| 16 |
+
if hasattr(self, 'initialized'):
|
| 17 |
+
return
|
| 18 |
+
self.initialized = True
|
| 19 |
+
print("✅ ModelManager initialized.")
|
| 20 |
+
|
| 21 |
+
def ensure_models_downloaded(self, required_models: List[str], progress):
|
| 22 |
+
print(f"--- [ModelManager] Ensuring models are downloaded: {required_models} ---")
|
| 23 |
+
for i, display_name in enumerate(required_models):
|
| 24 |
+
if progress and hasattr(progress, '__call__'):
|
| 25 |
+
progress(i / max(len(required_models), 1), desc=f"Checking file: {display_name}")
|
| 26 |
+
try:
|
| 27 |
+
_ensure_model_downloaded(display_name, progress)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
raise gr.Error(f"模型“{display_name}”下载失败:{e}")
|
| 30 |
+
print(f"--- [ModelManager] ✅ All required models are present on disk. ---")
|
| 31 |
+
|
| 32 |
+
model_manager = ModelManager()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def release_loaded_models() -> bool:
|
| 36 |
+
"""Best-effort release of ComfyUI model state while GPU access is active."""
|
| 37 |
+
|
| 38 |
+
released = False
|
| 39 |
+
try:
|
| 40 |
+
from comfy import model_management
|
| 41 |
+
|
| 42 |
+
unload = getattr(model_management, "unload_all_models", None)
|
| 43 |
+
if callable(unload):
|
| 44 |
+
unload()
|
| 45 |
+
released = True
|
| 46 |
+
|
| 47 |
+
cleanup = getattr(model_management, "cleanup_models", None)
|
| 48 |
+
if callable(cleanup):
|
| 49 |
+
cleanup()
|
| 50 |
+
|
| 51 |
+
gc.collect()
|
| 52 |
+
empty_cache = getattr(model_management, "soft_empty_cache", None)
|
| 53 |
+
if callable(empty_cache):
|
| 54 |
+
try:
|
| 55 |
+
empty_cache(force=True)
|
| 56 |
+
except TypeError:
|
| 57 |
+
empty_cache()
|
| 58 |
+
print("✅ Released ComfyUI model state after a model switch/error.")
|
| 59 |
+
except Exception as exc:
|
| 60 |
+
# Cleanup must never hide the original generation result or exception.
|
| 61 |
+
gc.collect()
|
| 62 |
+
print(f"Warning: Could not fully release ComfyUI model state: {exc}")
|
| 63 |
+
return released
|
core/pipelines/__init__.py
ADDED
|
File without changes
|
core/pipelines/base_pipeline.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod
|
| 2 |
+
from typing import List, Any, Dict
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import spaces
|
| 5 |
+
import tempfile
|
| 6 |
+
import imageio
|
| 7 |
+
import numpy as np
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
class BasePipeline(ABC):
|
| 12 |
+
def __init__(self):
|
| 13 |
+
from core.model_manager import model_manager
|
| 14 |
+
self.model_manager = model_manager
|
| 15 |
+
|
| 16 |
+
@abstractmethod
|
| 17 |
+
def get_required_models(self, **kwargs) -> List[str]:
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
@abstractmethod
|
| 21 |
+
def run(self, *args, progress: gr.Progress, **kwargs) -> Any:
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
def _ensure_models_downloaded(self, progress: gr.Progress, **kwargs):
|
| 25 |
+
"""Ensures model files are downloaded before requesting GPU."""
|
| 26 |
+
required_models = self.get_required_models(**kwargs)
|
| 27 |
+
self.model_manager.ensure_models_downloaded(required_models, progress=progress)
|
| 28 |
+
|
| 29 |
+
def _execute_gpu_logic(self, gpu_function: callable, duration: int, default_duration: int, task_name: str, *args, **kwargs):
|
| 30 |
+
final_duration = default_duration
|
| 31 |
+
try:
|
| 32 |
+
if duration is not None and int(duration) > 0:
|
| 33 |
+
final_duration = int(duration)
|
| 34 |
+
except (ValueError, TypeError):
|
| 35 |
+
print(f"Invalid ZeroGPU duration input for {task_name}. Using default {default_duration}s.")
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
print(f"Requesting ZeroGPU for {task_name} with duration: {final_duration} seconds.")
|
| 39 |
+
gpu_runner = spaces.GPU(duration=final_duration)(gpu_function)
|
| 40 |
+
|
| 41 |
+
return gpu_runner(*args, **kwargs)
|
| 42 |
+
|
| 43 |
+
def _encode_video_from_frames(self, frames_tensor_cpu: 'torch.Tensor', fps: int, progress: gr.Progress) -> str:
|
| 44 |
+
progress(0.9, desc="Encoding video on CPU...")
|
| 45 |
+
frames_np = (frames_tensor_cpu.numpy() * 255.0).astype(np.uint8)
|
| 46 |
+
|
| 47 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video_file:
|
| 48 |
+
video_path = temp_video_file.name
|
| 49 |
+
writer = imageio.get_writer(video_path, fps=fps, codec='libx264', quality=8)
|
| 50 |
+
for frame in frames_np:
|
| 51 |
+
writer.append_data(frame)
|
| 52 |
+
writer.close()
|
| 53 |
+
|
| 54 |
+
progress(1.0, desc="Done!")
|
| 55 |
+
return video_path
|
core/pipelines/pipeline_input_processor.py
ADDED
|
@@ -0,0 +1,580 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from PIL import Image, ImageChops
|
| 6 |
+
from typing import Dict, Any, List
|
| 7 |
+
|
| 8 |
+
from core.settings import INPUT_DIR, MULTIPLIERS_MAP, LORA_DIR, EMBEDDING_DIR, VAE_DIR
|
| 9 |
+
from core.runtime_config import CONFIG
|
| 10 |
+
from imagegen_utils.app_utils import (
|
| 11 |
+
sanitize_filename,
|
| 12 |
+
get_lora_path,
|
| 13 |
+
get_embedding_path,
|
| 14 |
+
ensure_controlnet_model_downloaded,
|
| 15 |
+
ensure_ipadapter_models_downloaded,
|
| 16 |
+
_ensure_model_downloaded,
|
| 17 |
+
ensure_sd3_ipadapter_models_downloaded,
|
| 18 |
+
get_vae_path,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _temp_png(stem: str) -> str:
|
| 23 |
+
return os.path.join(INPUT_DIR, f"{stem}_{uuid.uuid4().hex}.png")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
REFERENCE_IMAGE_LIMITS = {
|
| 27 |
+
"controlnet_data": 5,
|
| 28 |
+
"anima_controlnet_lllite_data": 5,
|
| 29 |
+
"diffsynth_controlnet_data": 5,
|
| 30 |
+
"krea2_controlnet_data": 5,
|
| 31 |
+
"ipadapter_data": 5,
|
| 32 |
+
"flux1_ipadapter_data": 5,
|
| 33 |
+
"sd3_ipadapter_chain": 5,
|
| 34 |
+
"style_data": 5,
|
| 35 |
+
"reference_latent_data": 10,
|
| 36 |
+
"hidream_o1_reference_data": 10,
|
| 37 |
+
"joyai_reference_data": 2,
|
| 38 |
+
"krea2_identity_edit_data": 2,
|
| 39 |
+
"krea2_reference_edit_data": 3,
|
| 40 |
+
"qwen_image_edit_data": 3,
|
| 41 |
+
"boogu_edit_data": 10,
|
| 42 |
+
"reference_image_data": 10,
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _pil_images(value: Any):
|
| 47 |
+
if isinstance(value, Image.Image):
|
| 48 |
+
yield value
|
| 49 |
+
elif isinstance(value, dict):
|
| 50 |
+
for child in value.values():
|
| 51 |
+
yield from _pil_images(child)
|
| 52 |
+
elif isinstance(value, (list, tuple)):
|
| 53 |
+
for child in value:
|
| 54 |
+
yield from _pil_images(child)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _validate_reference_image_budget(ui_inputs: Dict[str, Any]) -> None:
|
| 58 |
+
"""Bound decoded reference images before saving or entering a workflow."""
|
| 59 |
+
|
| 60 |
+
all_images = []
|
| 61 |
+
for input_key, chain_limit in REFERENCE_IMAGE_LIMITS.items():
|
| 62 |
+
images = list(_pil_images(ui_inputs.get(input_key)))
|
| 63 |
+
if len(images) > chain_limit:
|
| 64 |
+
raise gr.Error(
|
| 65 |
+
f"扩展“{input_key}”最多支持 {chain_limit} 张图片;当前为 {len(images)} 张。"
|
| 66 |
+
)
|
| 67 |
+
all_images.extend(images)
|
| 68 |
+
|
| 69 |
+
if len(all_images) > CONFIG.max_reference_images:
|
| 70 |
+
raise gr.Error(
|
| 71 |
+
f"一次任务最多使用 {CONFIG.max_reference_images} 张参考/控制图;"
|
| 72 |
+
f"当前合计 {len(all_images)} 张。"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
total_megapixels = 0.0
|
| 76 |
+
for index, image in enumerate(all_images, start=1):
|
| 77 |
+
megapixels = (image.width * image.height) / 1_000_000
|
| 78 |
+
if megapixels > CONFIG.max_input_megapixels:
|
| 79 |
+
raise gr.Error(
|
| 80 |
+
f"参考图 {index} 为 {megapixels:.1f}MP,超过单图上限 "
|
| 81 |
+
f"{CONFIG.max_input_megapixels:g}MP。"
|
| 82 |
+
)
|
| 83 |
+
total_megapixels += megapixels
|
| 84 |
+
if total_megapixels > CONFIG.max_reference_megapixels:
|
| 85 |
+
raise gr.Error(
|
| 86 |
+
f"参考/控制图累计为 {total_megapixels:.1f}MP,超过上限 "
|
| 87 |
+
f"{CONFIG.max_reference_megapixels:g}MP;请缩小图片或减少数量。"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def process_pipeline_inputs(ui_inputs: Dict[str, Any], progress: gr.Progress, workflow_model_type: str) -> Dict[str, Any]:
|
| 91 |
+
task_type = ui_inputs['task_type']
|
| 92 |
+
temp_files_to_clean = []
|
| 93 |
+
_validate_reference_image_budget(ui_inputs)
|
| 94 |
+
|
| 95 |
+
multiplier = MULTIPLIERS_MAP.get(workflow_model_type, 8)
|
| 96 |
+
img_w, img_h = 0, 0
|
| 97 |
+
if task_type == 'txt2img':
|
| 98 |
+
img_w = int(ui_inputs.get('width', 0))
|
| 99 |
+
img_h = int(ui_inputs.get('height', 0))
|
| 100 |
+
elif task_type == 'img2img':
|
| 101 |
+
input_image_pil = ui_inputs.get('img2img_image')
|
| 102 |
+
if input_image_pil:
|
| 103 |
+
img_w, img_h = input_image_pil.width, input_image_pil.height
|
| 104 |
+
elif task_type == 'inpaint':
|
| 105 |
+
inpaint_img = ui_inputs.get('inpaint_image')
|
| 106 |
+
inpaint_dict = ui_inputs.get('inpaint_image_dict')
|
| 107 |
+
if inpaint_img:
|
| 108 |
+
img_w, img_h = inpaint_img.width, inpaint_img.height
|
| 109 |
+
elif inpaint_dict and inpaint_dict.get('background'):
|
| 110 |
+
img_w, img_h = inpaint_dict['background'].width, inpaint_dict['background'].height
|
| 111 |
+
elif task_type == 'outpaint':
|
| 112 |
+
input_image_pil = ui_inputs.get('outpaint_image')
|
| 113 |
+
if input_image_pil:
|
| 114 |
+
img_w, img_h = input_image_pil.width, input_image_pil.height
|
| 115 |
+
elif task_type == 'hires_fix':
|
| 116 |
+
input_image_pil = ui_inputs.get('hires_image')
|
| 117 |
+
if input_image_pil:
|
| 118 |
+
img_w, img_h = input_image_pil.width, input_image_pil.height
|
| 119 |
+
|
| 120 |
+
if task_type == "txt2img" and (img_w <= 0 or img_h <= 0):
|
| 121 |
+
raise gr.Error("文生图的宽度和高度必须为正整数。")
|
| 122 |
+
|
| 123 |
+
if img_w > 0 and img_h > 0:
|
| 124 |
+
input_megapixels = (img_w * img_h) / 1_000_000
|
| 125 |
+
if input_megapixels > CONFIG.max_input_megapixels:
|
| 126 |
+
scale = (CONFIG.max_input_megapixels / input_megapixels) ** 0.5
|
| 127 |
+
suggested_w = max(multiplier, int(img_w * scale) // multiplier * multiplier)
|
| 128 |
+
suggested_h = max(multiplier, int(img_h * scale) // multiplier * multiplier)
|
| 129 |
+
raise gr.Error(
|
| 130 |
+
f"输入图片为 {input_megapixels:.1f}MP,超过当前上限 "
|
| 131 |
+
f"{CONFIG.max_input_megapixels:g}MP;建议缩小到约 "
|
| 132 |
+
f"{suggested_w}×{suggested_h}。"
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
projected_w, projected_h = img_w, img_h
|
| 136 |
+
if task_type == "hires_fix":
|
| 137 |
+
upscale = float(ui_inputs.get("hires_scale_by") or 1.5)
|
| 138 |
+
projected_w, projected_h = int(img_w * upscale), int(img_h * upscale)
|
| 139 |
+
elif task_type == "outpaint":
|
| 140 |
+
projected_w = img_w + int(ui_inputs.get("left") or 0) + int(ui_inputs.get("right") or 0)
|
| 141 |
+
projected_h = img_h + int(ui_inputs.get("top") or 0) + int(ui_inputs.get("bottom") or 0)
|
| 142 |
+
projected_megapixels = (projected_w * projected_h) / 1_000_000
|
| 143 |
+
if projected_megapixels > CONFIG.max_output_megapixels:
|
| 144 |
+
raise gr.Error(
|
| 145 |
+
f"预计输出为 {projected_w}×{projected_h}({projected_megapixels:.1f}MP),"
|
| 146 |
+
f"超过当前上限 {CONFIG.max_output_megapixels:g}MP;请降低放大倍数或扩边尺寸。"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
if (img_w % multiplier != 0) or (img_h % multiplier != 0):
|
| 150 |
+
suggested_w = max(multiplier, round(img_w / multiplier) * multiplier)
|
| 151 |
+
suggested_h = max(multiplier, round(img_h / multiplier) * multiplier)
|
| 152 |
+
warning_msg = (
|
| 153 |
+
f"当前模型要求宽高均为 {multiplier} 的倍数;"
|
| 154 |
+
f"收到 {img_w}×{img_h},可调整为约 {suggested_w}×{suggested_h}。"
|
| 155 |
+
)
|
| 156 |
+
raise gr.Error(warning_msg)
|
| 157 |
+
|
| 158 |
+
lora_data = ui_inputs.get('lora_data', [])
|
| 159 |
+
active_loras_for_gpu, active_loras_for_meta = [], []
|
| 160 |
+
if lora_data:
|
| 161 |
+
sources, ids, scales, files = lora_data[0::4], lora_data[1::4], lora_data[2::4], lora_data[3::4]
|
| 162 |
+
for i, (source, lora_id, scale, _) in enumerate(zip(sources, ids, scales, files)):
|
| 163 |
+
if scale > 0 and lora_id and lora_id.strip():
|
| 164 |
+
lora_filename = None
|
| 165 |
+
if source == "File":
|
| 166 |
+
lora_filename = sanitize_filename(lora_id)
|
| 167 |
+
local_path = os.path.join(LORA_DIR, lora_filename)
|
| 168 |
+
if not os.path.exists(local_path):
|
| 169 |
+
raise gr.Error(f"已上传的 LoRA“{lora_id}”已不存在,请重新上传。")
|
| 170 |
+
elif source in ("Civitai", "Hugging Face"):
|
| 171 |
+
local_path, status = get_lora_path(source, lora_id, os.environ.get("CIVITAI_API_KEY", ""), progress)
|
| 172 |
+
if local_path: lora_filename = os.path.basename(local_path)
|
| 173 |
+
else: raise gr.Error(f"LoRA“{lora_id}”准备失败:{status}")
|
| 174 |
+
|
| 175 |
+
if lora_filename:
|
| 176 |
+
active_loras_for_gpu.append({"lora_name": lora_filename, "strength_model": scale, "strength_clip": scale})
|
| 177 |
+
active_loras_for_meta.append(f"{source} {lora_id}:{scale}")
|
| 178 |
+
|
| 179 |
+
ui_inputs['denoise'] = 1.0
|
| 180 |
+
if task_type == 'img2img': ui_inputs['denoise'] = ui_inputs.get('img2img_denoise', 0.7)
|
| 181 |
+
elif task_type == 'hires_fix': ui_inputs['denoise'] = ui_inputs.get('hires_denoise', 0.55)
|
| 182 |
+
elif task_type == 'inpaint': ui_inputs['denoise'] = ui_inputs.get('inpaint_denoise', 1.0)
|
| 183 |
+
|
| 184 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 185 |
+
|
| 186 |
+
if task_type == 'img2img':
|
| 187 |
+
input_image_pil = ui_inputs.get('img2img_image')
|
| 188 |
+
if not input_image_pil:
|
| 189 |
+
raise gr.Error("图生图需要先上传源图片。")
|
| 190 |
+
temp_file_path = _temp_png("temp_input")
|
| 191 |
+
input_image_pil.save(temp_file_path, "PNG")
|
| 192 |
+
ui_inputs['input_image'] = os.path.basename(temp_file_path)
|
| 193 |
+
temp_files_to_clean.append(temp_file_path)
|
| 194 |
+
ui_inputs['width'] = input_image_pil.width
|
| 195 |
+
ui_inputs['height'] = input_image_pil.height
|
| 196 |
+
|
| 197 |
+
elif task_type == 'inpaint':
|
| 198 |
+
inpaint_img = ui_inputs.get('inpaint_image')
|
| 199 |
+
inpaint_dict = ui_inputs.get('inpaint_image_dict')
|
| 200 |
+
|
| 201 |
+
if inpaint_img:
|
| 202 |
+
temp_file_path = _temp_png("temp_inpaint")
|
| 203 |
+
inpaint_img.save(temp_file_path, "PNG")
|
| 204 |
+
ui_inputs['input_image'] = os.path.basename(temp_file_path)
|
| 205 |
+
temp_files_to_clean.append(temp_file_path)
|
| 206 |
+
ui_inputs['width'] = inpaint_img.width
|
| 207 |
+
ui_inputs['height'] = inpaint_img.height
|
| 208 |
+
elif inpaint_dict and inpaint_dict.get('background') and inpaint_dict.get('layers'):
|
| 209 |
+
background_img = inpaint_dict['background'].convert("RGBA")
|
| 210 |
+
composite_mask_pil = Image.new('L', background_img.size, 0)
|
| 211 |
+
for layer in inpaint_dict['layers']:
|
| 212 |
+
if layer:
|
| 213 |
+
layer_alpha = layer.split()[-1]
|
| 214 |
+
composite_mask_pil = ImageChops.lighter(composite_mask_pil, layer_alpha)
|
| 215 |
+
|
| 216 |
+
inverted_mask_alpha = Image.fromarray(255 - np.array(composite_mask_pil), mode='L')
|
| 217 |
+
r, g, b, _ = background_img.split()
|
| 218 |
+
composite_image_with_mask = Image.merge('RGBA', [r, g, b, inverted_mask_alpha])
|
| 219 |
+
|
| 220 |
+
temp_file_path = _temp_png("temp_inpaint_composite")
|
| 221 |
+
composite_image_with_mask.save(temp_file_path, "PNG")
|
| 222 |
+
|
| 223 |
+
ui_inputs['input_image'] = os.path.basename(temp_file_path)
|
| 224 |
+
temp_files_to_clean.append(temp_file_path)
|
| 225 |
+
ui_inputs.pop('inpaint_mask', None)
|
| 226 |
+
ui_inputs['width'] = background_img.width
|
| 227 |
+
ui_inputs['height'] = background_img.height
|
| 228 |
+
else:
|
| 229 |
+
raise gr.Error("局部重绘需要输入图片和有效蒙版。")
|
| 230 |
+
|
| 231 |
+
elif task_type == 'outpaint':
|
| 232 |
+
input_image_pil = ui_inputs.get('outpaint_image')
|
| 233 |
+
if not input_image_pil:
|
| 234 |
+
raise gr.Error("扩图需要先上传源图片。")
|
| 235 |
+
temp_file_path = _temp_png("temp_input")
|
| 236 |
+
input_image_pil.save(temp_file_path, "PNG")
|
| 237 |
+
ui_inputs['input_image'] = os.path.basename(temp_file_path)
|
| 238 |
+
temp_files_to_clean.append(temp_file_path)
|
| 239 |
+
|
| 240 |
+
ui_inputs['megapixels'] = 0.25
|
| 241 |
+
ui_inputs['grow_mask_by'] = ui_inputs.get('feathering', 10)
|
| 242 |
+
ui_inputs['width'] = input_image_pil.width + int(ui_inputs.get('left') or 0) + int(ui_inputs.get('right') or 0)
|
| 243 |
+
ui_inputs['height'] = input_image_pil.height + int(ui_inputs.get('top') or 0) + int(ui_inputs.get('bottom') or 0)
|
| 244 |
+
|
| 245 |
+
elif task_type == 'hires_fix':
|
| 246 |
+
input_image_pil = ui_inputs.get('hires_image')
|
| 247 |
+
if not input_image_pil:
|
| 248 |
+
raise gr.Error("高清修复需要先上传源图片。")
|
| 249 |
+
temp_file_path = _temp_png("temp_input")
|
| 250 |
+
input_image_pil.save(temp_file_path, "PNG")
|
| 251 |
+
ui_inputs['input_image'] = os.path.basename(temp_file_path)
|
| 252 |
+
temp_files_to_clean.append(temp_file_path)
|
| 253 |
+
hires_scale = float(ui_inputs.get('hires_scale_by') or 1.5)
|
| 254 |
+
ui_inputs['width'] = int(input_image_pil.width * hires_scale)
|
| 255 |
+
ui_inputs['height'] = int(input_image_pil.height * hires_scale)
|
| 256 |
+
|
| 257 |
+
embedding_data = ui_inputs.get('embedding_data', [])
|
| 258 |
+
embedding_filenames = []
|
| 259 |
+
if embedding_data:
|
| 260 |
+
emb_sources, emb_ids, emb_files = embedding_data[0::3], embedding_data[1::3], embedding_data[2::3]
|
| 261 |
+
for i, (source, emb_id, _) in enumerate(zip(emb_sources, emb_ids, emb_files)):
|
| 262 |
+
if emb_id and emb_id.strip():
|
| 263 |
+
emb_filename = None
|
| 264 |
+
if source == "File":
|
| 265 |
+
emb_filename = sanitize_filename(emb_id)
|
| 266 |
+
local_path = os.path.join(EMBEDDING_DIR, emb_filename)
|
| 267 |
+
if not os.path.exists(local_path):
|
| 268 |
+
raise gr.Error(f"已上传的 Embedding“{emb_id}”已不存在,请重新上传。")
|
| 269 |
+
elif source in ("Civitai", "Hugging Face"):
|
| 270 |
+
local_path, status = get_embedding_path(source, emb_id, os.environ.get("CIVITAI_API_KEY", ""), progress)
|
| 271 |
+
if local_path: emb_filename = os.path.basename(local_path)
|
| 272 |
+
else: raise gr.Error(f"Embedding“{emb_id}”准备失败:{status}")
|
| 273 |
+
|
| 274 |
+
if emb_filename:
|
| 275 |
+
embedding_filenames.append(emb_filename)
|
| 276 |
+
|
| 277 |
+
controlnet_data = ui_inputs.get('controlnet_data', [])
|
| 278 |
+
active_controlnets = []
|
| 279 |
+
if controlnet_data:
|
| 280 |
+
(cn_images, _, _, cn_strengths, cn_filepaths) = [controlnet_data[i::5] for i in range(5)]
|
| 281 |
+
for i in range(len(cn_images)):
|
| 282 |
+
if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None":
|
| 283 |
+
ensure_controlnet_model_downloaded(cn_filepaths[i], progress)
|
| 284 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 285 |
+
cn_temp_path = _temp_png(f"temp_cn_{i}")
|
| 286 |
+
cn_images[i].save(cn_temp_path, "PNG")
|
| 287 |
+
temp_files_to_clean.append(cn_temp_path)
|
| 288 |
+
active_controlnets.append({
|
| 289 |
+
"image": os.path.basename(cn_temp_path), "strength": cn_strengths[i],
|
| 290 |
+
"start_percent": 0.0, "end_percent": 1.0, "control_net_name": cn_filepaths[i]
|
| 291 |
+
})
|
| 292 |
+
|
| 293 |
+
anima_controlnet_lllite_data = ui_inputs.get('anima_controlnet_lllite_data', [])
|
| 294 |
+
active_anima_controlnets = []
|
| 295 |
+
if anima_controlnet_lllite_data:
|
| 296 |
+
(cn_images, _, _, cn_strengths, cn_filepaths, cn_starts, cn_ends) = [anima_controlnet_lllite_data[i::7] for i in range(7)]
|
| 297 |
+
for i in range(len(cn_images)):
|
| 298 |
+
if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None":
|
| 299 |
+
_ensure_model_downloaded(cn_filepaths[i], progress)
|
| 300 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 301 |
+
cn_temp_path = _temp_png(f"temp_anima_cn_{i}")
|
| 302 |
+
cn_images[i].save(cn_temp_path, "PNG")
|
| 303 |
+
temp_files_to_clean.append(cn_temp_path)
|
| 304 |
+
active_anima_controlnets.append({
|
| 305 |
+
"image": os.path.basename(cn_temp_path), "strength": cn_strengths[i],
|
| 306 |
+
"start_percent": cn_starts[i], "end_percent": cn_ends[i], "control_net_name": cn_filepaths[i]
|
| 307 |
+
})
|
| 308 |
+
|
| 309 |
+
diffsynth_controlnet_data = ui_inputs.get('diffsynth_controlnet_data', [])
|
| 310 |
+
active_diffsynth_controlnets = []
|
| 311 |
+
if diffsynth_controlnet_data:
|
| 312 |
+
(cn_images, _, _, cn_strengths, cn_filepaths) = [diffsynth_controlnet_data[i::5] for i in range(5)]
|
| 313 |
+
for i in range(len(cn_images)):
|
| 314 |
+
if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None":
|
| 315 |
+
ensure_controlnet_model_downloaded(cn_filepaths[i], progress)
|
| 316 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 317 |
+
cn_temp_path = _temp_png(f"temp_diffsynth_cn_{i}")
|
| 318 |
+
cn_images[i].save(cn_temp_path, "PNG")
|
| 319 |
+
temp_files_to_clean.append(cn_temp_path)
|
| 320 |
+
active_diffsynth_controlnets.append({
|
| 321 |
+
"image": os.path.basename(cn_temp_path), "strength": cn_strengths[i],
|
| 322 |
+
"control_net_name": cn_filepaths[i]
|
| 323 |
+
})
|
| 324 |
+
|
| 325 |
+
krea2_controlnet_data = ui_inputs.get('krea2_controlnet_data', [])
|
| 326 |
+
active_krea2_controlnets = []
|
| 327 |
+
if krea2_controlnet_data:
|
| 328 |
+
(cn_images, _, _, cn_strengths, cn_filepaths) = [krea2_controlnet_data[i::5] for i in range(5)]
|
| 329 |
+
for i in range(len(cn_images)):
|
| 330 |
+
if cn_images[i] and cn_strengths[i] > 0 and cn_filepaths[i] and cn_filepaths[i] != "None":
|
| 331 |
+
ensure_controlnet_model_downloaded(cn_filepaths[i], progress)
|
| 332 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 333 |
+
cn_temp_path = _temp_png(f"temp_krea2_cn_{i}")
|
| 334 |
+
cn_images[i].save(cn_temp_path, "PNG")
|
| 335 |
+
temp_files_to_clean.append(cn_temp_path)
|
| 336 |
+
active_krea2_controlnets.append({
|
| 337 |
+
"image": os.path.basename(cn_temp_path), "strength": cn_strengths[i],
|
| 338 |
+
"control_net_name": cn_filepaths[i]
|
| 339 |
+
})
|
| 340 |
+
|
| 341 |
+
ipadapter_data = ui_inputs.get('ipadapter_data', [])
|
| 342 |
+
active_ipadapters = []
|
| 343 |
+
if ipadapter_data:
|
| 344 |
+
num_ipa_units = (len(ipadapter_data) - 5) // 3
|
| 345 |
+
final_preset, final_weight, final_lora_strength, final_embeds_scaling, final_combine_method = ipadapter_data[-5:]
|
| 346 |
+
ipa_images, ipa_weights, ipa_lora_strengths = [ipadapter_data[i*num_ipa_units:(i+1)*num_ipa_units] for i in range(3)]
|
| 347 |
+
all_presets_to_download = set()
|
| 348 |
+
for i in range(num_ipa_units):
|
| 349 |
+
if ipa_images[i] and ipa_weights[i] > 0 and final_preset:
|
| 350 |
+
all_presets_to_download.add(final_preset)
|
| 351 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 352 |
+
ipa_temp_path = _temp_png(f"temp_ipa_{i}")
|
| 353 |
+
ipa_images[i].save(ipa_temp_path, "PNG")
|
| 354 |
+
temp_files_to_clean.append(ipa_temp_path)
|
| 355 |
+
active_ipadapters.append({
|
| 356 |
+
"image": os.path.basename(ipa_temp_path), "preset": final_preset,
|
| 357 |
+
"weight": ipa_weights[i], "lora_strength": ipa_lora_strengths[i]
|
| 358 |
+
})
|
| 359 |
+
if active_ipadapters and final_preset:
|
| 360 |
+
all_presets_to_download.add(final_preset)
|
| 361 |
+
for preset in all_presets_to_download:
|
| 362 |
+
ensure_ipadapter_models_downloaded(preset, progress)
|
| 363 |
+
|
| 364 |
+
model_type_key = 'sd15' if workflow_model_type == 'sd15' else 'sdxl'
|
| 365 |
+
if active_ipadapters:
|
| 366 |
+
active_ipadapters.append({
|
| 367 |
+
'is_final_settings': True, 'model_type': model_type_key, 'final_preset': final_preset,
|
| 368 |
+
'final_weight': final_weight, 'final_lora_strength': final_lora_strength,
|
| 369 |
+
'final_embeds_scaling': final_embeds_scaling, 'final_combine_method': final_combine_method
|
| 370 |
+
})
|
| 371 |
+
|
| 372 |
+
flux1_ipadapter_data = ui_inputs.get('flux1_ipadapter_data', [])
|
| 373 |
+
active_flux1_ipadapters = []
|
| 374 |
+
if flux1_ipadapter_data:
|
| 375 |
+
num_units = len(flux1_ipadapter_data) // 4
|
| 376 |
+
f_images = flux1_ipadapter_data[0*num_units : 1*num_units]
|
| 377 |
+
f_weights = flux1_ipadapter_data[1*num_units : 2*num_units]
|
| 378 |
+
f_starts = flux1_ipadapter_data[2*num_units : 3*num_units]
|
| 379 |
+
f_ends = flux1_ipadapter_data[3*num_units : 4*num_units]
|
| 380 |
+
for i in range(len(f_images)):
|
| 381 |
+
if f_images[i] and f_weights[i] > 0:
|
| 382 |
+
for filename in ["ip-adapter.bin"]:
|
| 383 |
+
_ensure_model_downloaded(filename, progress)
|
| 384 |
+
|
| 385 |
+
from huggingface_hub import snapshot_download
|
| 386 |
+
progress(0.5, desc="Caching HF SigLIP model...")
|
| 387 |
+
snapshot_download(
|
| 388 |
+
repo_id="google/siglip-so400m-patch14-384",
|
| 389 |
+
allow_patterns=["*.json", "*.safetensors", "*.txt"],
|
| 390 |
+
ignore_patterns=["*.msgpack", "*.h5", "*.bin"]
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
temp_path = _temp_png(f"temp_fipa_{i}")
|
| 394 |
+
f_images[i].save(temp_path, "PNG")
|
| 395 |
+
temp_files_to_clean.append(temp_path)
|
| 396 |
+
active_flux1_ipadapters.append({
|
| 397 |
+
"image": os.path.basename(temp_path),
|
| 398 |
+
"weight": f_weights[i], "start_percent": f_starts[i], "end_percent": f_ends[i]
|
| 399 |
+
})
|
| 400 |
+
|
| 401 |
+
sd3_ipadapter_data = ui_inputs.get('sd3_ipadapter_chain', [])
|
| 402 |
+
active_sd3_ipadapters = []
|
| 403 |
+
if sd3_ipadapter_data:
|
| 404 |
+
num_units = len(sd3_ipadapter_data) // 4
|
| 405 |
+
s_images = sd3_ipadapter_data[0*num_units : 1*num_units]
|
| 406 |
+
s_weights = sd3_ipadapter_data[1*num_units : 2*num_units]
|
| 407 |
+
s_starts = sd3_ipadapter_data[2*num_units : 3*num_units]
|
| 408 |
+
s_ends = sd3_ipadapter_data[3*num_units : 4*num_units]
|
| 409 |
+
sd3_ipa_downloaded = False
|
| 410 |
+
for i in range(len(s_images)):
|
| 411 |
+
if s_images[i] and s_weights[i] > 0:
|
| 412 |
+
if not sd3_ipa_downloaded:
|
| 413 |
+
ensure_sd3_ipadapter_models_downloaded(progress)
|
| 414 |
+
sd3_ipa_downloaded = True
|
| 415 |
+
temp_path = _temp_png(f"temp_s3ipa_{i}")
|
| 416 |
+
s_images[i].save(temp_path, "PNG")
|
| 417 |
+
temp_files_to_clean.append(temp_path)
|
| 418 |
+
active_sd3_ipadapters.append({
|
| 419 |
+
"image": os.path.basename(temp_path),
|
| 420 |
+
"weight": s_weights[i], "start_percent": s_starts[i], "end_percent": s_ends[i]
|
| 421 |
+
})
|
| 422 |
+
|
| 423 |
+
style_data = ui_inputs.get('style_data', [])
|
| 424 |
+
active_styles = []
|
| 425 |
+
if style_data:
|
| 426 |
+
num_units = len(style_data) // 2
|
| 427 |
+
st_images = style_data[0*num_units : 1*num_units]
|
| 428 |
+
st_strengths = style_data[1*num_units : 2*num_units]
|
| 429 |
+
style_models_downloaded = False
|
| 430 |
+
for i in range(len(st_images)):
|
| 431 |
+
if st_images[i] and st_strengths[i] > 0:
|
| 432 |
+
if not style_models_downloaded:
|
| 433 |
+
_ensure_model_downloaded("sigclip_vision_patch14_384.safetensors", progress)
|
| 434 |
+
_ensure_model_downloaded("flux1-redux-dev.safetensors", progress)
|
| 435 |
+
style_models_downloaded = True
|
| 436 |
+
temp_path = _temp_png(f"temp_style_{i}")
|
| 437 |
+
st_images[i].save(temp_path, "PNG")
|
| 438 |
+
temp_files_to_clean.append(temp_path)
|
| 439 |
+
active_styles.append({
|
| 440 |
+
"image": os.path.basename(temp_path), "strength": st_strengths[i]
|
| 441 |
+
})
|
| 442 |
+
|
| 443 |
+
reference_latent_data = ui_inputs.get('reference_latent_data', [])
|
| 444 |
+
active_reference_latents = []
|
| 445 |
+
if reference_latent_data:
|
| 446 |
+
for img in reference_latent_data:
|
| 447 |
+
if img:
|
| 448 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 449 |
+
temp_path = _temp_png("temp_ref")
|
| 450 |
+
img.save(temp_path, "PNG")
|
| 451 |
+
temp_files_to_clean.append(temp_path)
|
| 452 |
+
active_reference_latents.append(os.path.basename(temp_path))
|
| 453 |
+
|
| 454 |
+
hidream_o1_reference_data = ui_inputs.get('hidream_o1_reference_data', [])
|
| 455 |
+
active_hidream_o1_reference = []
|
| 456 |
+
if hidream_o1_reference_data:
|
| 457 |
+
for img in hidream_o1_reference_data:
|
| 458 |
+
if img:
|
| 459 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 460 |
+
temp_path = _temp_png("temp_ho1_ref")
|
| 461 |
+
img.save(temp_path, "PNG")
|
| 462 |
+
temp_files_to_clean.append(temp_path)
|
| 463 |
+
active_hidream_o1_reference.append(os.path.basename(temp_path))
|
| 464 |
+
|
| 465 |
+
joyai_reference_data = ui_inputs.get('joyai_reference_data', [])
|
| 466 |
+
active_joyai_reference = []
|
| 467 |
+
if joyai_reference_data:
|
| 468 |
+
for img in joyai_reference_data:
|
| 469 |
+
if img:
|
| 470 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 471 |
+
temp_path = _temp_png("temp_joyai_ref")
|
| 472 |
+
img.save(temp_path, "PNG")
|
| 473 |
+
temp_files_to_clean.append(temp_path)
|
| 474 |
+
active_joyai_reference.append(os.path.basename(temp_path))
|
| 475 |
+
|
| 476 |
+
krea2_identity_edit_data = ui_inputs.get('krea2_identity_edit_data', [])
|
| 477 |
+
active_krea2_identity_edit = []
|
| 478 |
+
if krea2_identity_edit_data:
|
| 479 |
+
for img in krea2_identity_edit_data:
|
| 480 |
+
if img:
|
| 481 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 482 |
+
temp_path = _temp_png("temp_krea2_id_ref")
|
| 483 |
+
img.save(temp_path, "PNG")
|
| 484 |
+
temp_files_to_clean.append(temp_path)
|
| 485 |
+
active_krea2_identity_edit.append(os.path.basename(temp_path))
|
| 486 |
+
|
| 487 |
+
krea2_reference_edit_data = ui_inputs.get('krea2_reference_edit_data', [])
|
| 488 |
+
active_krea2_reference_edit = []
|
| 489 |
+
if krea2_reference_edit_data:
|
| 490 |
+
for img in krea2_reference_edit_data:
|
| 491 |
+
if img:
|
| 492 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 493 |
+
temp_path = _temp_png("temp_krea2_reference_ref")
|
| 494 |
+
img.save(temp_path, "PNG")
|
| 495 |
+
temp_files_to_clean.append(temp_path)
|
| 496 |
+
active_krea2_reference_edit.append(os.path.basename(temp_path))
|
| 497 |
+
|
| 498 |
+
qwen_image_edit_data = ui_inputs.get('qwen_image_edit_data', [])
|
| 499 |
+
active_qwen_image_edit = []
|
| 500 |
+
if qwen_image_edit_data:
|
| 501 |
+
for img in qwen_image_edit_data:
|
| 502 |
+
if img:
|
| 503 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 504 |
+
temp_path = _temp_png("temp_qwen_edit_ref")
|
| 505 |
+
img.save(temp_path, "PNG")
|
| 506 |
+
temp_files_to_clean.append(temp_path)
|
| 507 |
+
active_qwen_image_edit.append(os.path.basename(temp_path))
|
| 508 |
+
|
| 509 |
+
boogu_edit_data = ui_inputs.get('boogu_edit_data', [])
|
| 510 |
+
active_boogu_edit = []
|
| 511 |
+
if boogu_edit_data:
|
| 512 |
+
for img in boogu_edit_data:
|
| 513 |
+
if img:
|
| 514 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 515 |
+
temp_path = _temp_png("temp_boogu_edit_ref")
|
| 516 |
+
img.save(temp_path, "PNG")
|
| 517 |
+
temp_files_to_clean.append(temp_path)
|
| 518 |
+
active_boogu_edit.append(os.path.basename(temp_path))
|
| 519 |
+
|
| 520 |
+
reference_image_data = ui_inputs.get('reference_image_data', [])
|
| 521 |
+
active_reference_images = []
|
| 522 |
+
if reference_image_data:
|
| 523 |
+
for img in reference_image_data:
|
| 524 |
+
if img:
|
| 525 |
+
if not os.path.exists(INPUT_DIR): os.makedirs(INPUT_DIR)
|
| 526 |
+
temp_path = _temp_png("temp_ref_img")
|
| 527 |
+
img.save(temp_path, "PNG")
|
| 528 |
+
temp_files_to_clean.append(temp_path)
|
| 529 |
+
active_reference_images.append(os.path.basename(temp_path))
|
| 530 |
+
|
| 531 |
+
vae_source = ui_inputs.get('vae_source')
|
| 532 |
+
vae_id = ui_inputs.get('vae_id')
|
| 533 |
+
vae_name_override = None
|
| 534 |
+
if vae_source and vae_source != "None":
|
| 535 |
+
if vae_source == "File":
|
| 536 |
+
vae_name_override = sanitize_filename(vae_id)
|
| 537 |
+
local_path = os.path.join(VAE_DIR, vae_name_override)
|
| 538 |
+
if not os.path.exists(local_path):
|
| 539 |
+
raise gr.Error(f"已上传的 VAE“{vae_id}”已不存在,请重新上传。")
|
| 540 |
+
elif vae_source in ("Civitai", "Hugging Face") and vae_id and vae_id.strip():
|
| 541 |
+
local_path, status = get_vae_path(vae_source, vae_id, os.environ.get("CIVITAI_API_KEY", ""), progress)
|
| 542 |
+
if local_path: vae_name_override = os.path.basename(local_path)
|
| 543 |
+
else: raise gr.Error(f"VAE“{vae_id}”准备失败:{status}")
|
| 544 |
+
if vae_name_override:
|
| 545 |
+
ui_inputs['vae_name'] = vae_name_override
|
| 546 |
+
|
| 547 |
+
conditioning_data = ui_inputs.get('conditioning_data', [])
|
| 548 |
+
active_conditioning = []
|
| 549 |
+
if conditioning_data:
|
| 550 |
+
num_units = len(conditioning_data) // 6
|
| 551 |
+
prompts, widths, heights, xs, ys, strengths = [conditioning_data[i*num_units : (i+1)*num_units] for i in range(6)]
|
| 552 |
+
for i in range(num_units):
|
| 553 |
+
if prompts[i] and prompts[i].strip():
|
| 554 |
+
active_conditioning.append({
|
| 555 |
+
"prompt": prompts[i], "width": int(widths[i]), "height": int(heights[i]),
|
| 556 |
+
"x": int(xs[i]), "y": int(ys[i]), "strength": float(strengths[i])
|
| 557 |
+
})
|
| 558 |
+
|
| 559 |
+
return {
|
| 560 |
+
"active_loras_for_gpu": active_loras_for_gpu,
|
| 561 |
+
"active_loras_for_meta": active_loras_for_meta,
|
| 562 |
+
"active_controlnets": active_controlnets,
|
| 563 |
+
"active_anima_controlnets": active_anima_controlnets,
|
| 564 |
+
"active_diffsynth_controlnets": active_diffsynth_controlnets,
|
| 565 |
+
"active_krea2_controlnets": active_krea2_controlnets,
|
| 566 |
+
"active_ipadapters": active_ipadapters,
|
| 567 |
+
"active_flux1_ipadapters": active_flux1_ipadapters,
|
| 568 |
+
"active_sd3_ipadapters": active_sd3_ipadapters,
|
| 569 |
+
"active_styles": active_styles,
|
| 570 |
+
"active_reference_latents": active_reference_latents,
|
| 571 |
+
"active_hidream_o1_reference": active_hidream_o1_reference,
|
| 572 |
+
"active_joyai_reference": active_joyai_reference,
|
| 573 |
+
"active_krea2_identity_edit": active_krea2_identity_edit,
|
| 574 |
+
"active_krea2_reference_edit": active_krea2_reference_edit,
|
| 575 |
+
"active_qwen_image_edit": active_qwen_image_edit,
|
| 576 |
+
"active_boogu_edit": active_boogu_edit,
|
| 577 |
+
"active_reference_images": active_reference_images,
|
| 578 |
+
"active_conditioning": active_conditioning,
|
| 579 |
+
"temp_files_to_clean": temp_files_to_clean
|
| 580 |
+
}
|
core/pipelines/sd_image_pipeline.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
import shutil
|
| 4 |
+
import torch
|
| 5 |
+
import uuid
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from PIL import Image
|
| 8 |
+
from typing import List, Dict, Any
|
| 9 |
+
|
| 10 |
+
from .base_pipeline import BasePipeline
|
| 11 |
+
from core.settings import *
|
| 12 |
+
from core.model_capabilities import supports_chain_for_model
|
| 13 |
+
from imagegen_utils.app_utils import sanitize_prompt
|
| 14 |
+
from core.workflow_assembler import WorkflowAssembler
|
| 15 |
+
from core.runtime_config import CONFIG, estimate_gpu_duration
|
| 16 |
+
from core.task_scheduler import TaskCancelledError, generation_guard
|
| 17 |
+
from .workflow_executor import WorkflowExecutor
|
| 18 |
+
from .pipeline_input_processor import process_pipeline_inputs
|
| 19 |
+
|
| 20 |
+
class SdImagePipeline(BasePipeline):
|
| 21 |
+
CHAIN_INPUT_KEYS = {
|
| 22 |
+
"lora": ("lora_data",),
|
| 23 |
+
"controlnet": ("controlnet_data",),
|
| 24 |
+
"anima_controlnet_lllite": ("anima_controlnet_lllite_data",),
|
| 25 |
+
"diffsynth_controlnet": ("diffsynth_controlnet_data",),
|
| 26 |
+
"krea2_controlnet": ("krea2_controlnet_data",),
|
| 27 |
+
"ipadapter": ("ipadapter_data",),
|
| 28 |
+
"flux1_ipadapter": ("flux1_ipadapter_data",),
|
| 29 |
+
"sd3_ipadapter": ("sd3_ipadapter_chain",),
|
| 30 |
+
"style": ("style_data",),
|
| 31 |
+
"embedding": ("embedding_data",),
|
| 32 |
+
"conditioning": ("conditioning_data",),
|
| 33 |
+
"reference_latent": ("reference_latent_data",),
|
| 34 |
+
"hidream_o1_reference": ("hidream_o1_reference_data",),
|
| 35 |
+
"joyai_image": ("joyai_reference_data",),
|
| 36 |
+
"krea2_identity_edit": ("krea2_identity_edit_data",),
|
| 37 |
+
"krea2_style_reference": ("krea2_reference_edit_data",),
|
| 38 |
+
"qwen_image_edit": ("qwen_image_edit_data",),
|
| 39 |
+
"boogu_image_edit": ("boogu_edit_data",),
|
| 40 |
+
"reference_image": ("reference_image_data",),
|
| 41 |
+
}
|
| 42 |
+
NATIVE_REFERENCE_CHAINS = {
|
| 43 |
+
"reference_latent",
|
| 44 |
+
"hidream_o1_reference",
|
| 45 |
+
"joyai_image",
|
| 46 |
+
"krea2_identity_edit",
|
| 47 |
+
"krea2_style_reference",
|
| 48 |
+
"qwen_image_edit",
|
| 49 |
+
"boogu_image_edit",
|
| 50 |
+
"reference_image",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
def get_required_models(self, model_display_name: str, **kwargs) -> List[str]:
|
| 54 |
+
model_info = ALL_MODEL_MAP.get(model_display_name)
|
| 55 |
+
if not model_info:
|
| 56 |
+
return [model_display_name]
|
| 57 |
+
|
| 58 |
+
path_or_components = model_info[1]
|
| 59 |
+
if isinstance(path_or_components, dict):
|
| 60 |
+
return [v for v in path_or_components.values() if v and v != "pixel_space"]
|
| 61 |
+
else:
|
| 62 |
+
return [model_display_name]
|
| 63 |
+
|
| 64 |
+
def _gpu_logic(self, ui_inputs: Dict, loras_string: str, workflow: Dict[str, Any], assembler: WorkflowAssembler, progress=gr.Progress(track_tqdm=True)):
|
| 65 |
+
model_display_name = ui_inputs['model_display_name']
|
| 66 |
+
succeeded = False
|
| 67 |
+
try:
|
| 68 |
+
progress(0.4, desc="正在执行工作流…")
|
| 69 |
+
|
| 70 |
+
initial_objects = {}
|
| 71 |
+
decoded_images_tensor = WorkflowExecutor.execute_workflow(
|
| 72 |
+
workflow, initial_objects=initial_objects
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
output_images = []
|
| 76 |
+
raw_seed = ui_inputs.get('seed')
|
| 77 |
+
start_seed = int(raw_seed) if (raw_seed is not None and raw_seed != -1) else random.randint(0, 2**64 - 1)
|
| 78 |
+
image_count = int(decoded_images_tensor.shape[0])
|
| 79 |
+
for i in range(image_count):
|
| 80 |
+
img_tensor = decoded_images_tensor[i]
|
| 81 |
+
pil_image = Image.fromarray((img_tensor.cpu().numpy() * 255.0).astype("uint8"))
|
| 82 |
+
|
| 83 |
+
width_for_meta = ui_inputs.get('width', 'N/A')
|
| 84 |
+
height_for_meta = ui_inputs.get('height', 'N/A')
|
| 85 |
+
|
| 86 |
+
params_string = f"{ui_inputs['positive_prompt']}\nNegative prompt: {ui_inputs['negative_prompt']}\n"
|
| 87 |
+
params_string += f"Steps: {ui_inputs['num_inference_steps']}, Sampler: {ui_inputs['sampler']}, Scheduler: {ui_inputs['scheduler']}, CFG scale: {ui_inputs['guidance_scale']}, Seed: {start_seed}, Size: {width_for_meta}x{height_for_meta}, Base Model: {model_display_name}"
|
| 88 |
+
if image_count > 1:
|
| 89 |
+
params_string += f", Batch index: {i + 1}/{image_count}"
|
| 90 |
+
if ui_inputs['task_type'] != 'txt2img': params_string += f", Denoise: {ui_inputs['denoise']}"
|
| 91 |
+
if ui_inputs.get('clip_skip') and ui_inputs['clip_skip'] != 1: params_string += f", Clip skip: {abs(ui_inputs['clip_skip'])}"
|
| 92 |
+
if loras_string: params_string += f", {loras_string}"
|
| 93 |
+
|
| 94 |
+
pil_image.info = {'parameters': params_string.strip()}
|
| 95 |
+
output_images.append(pil_image)
|
| 96 |
+
|
| 97 |
+
succeeded = True
|
| 98 |
+
return output_images
|
| 99 |
+
finally:
|
| 100 |
+
if not succeeded or ui_inputs.get("_release_models_after_run"):
|
| 101 |
+
from core.model_manager import release_loaded_models
|
| 102 |
+
|
| 103 |
+
release_loaded_models()
|
| 104 |
+
|
| 105 |
+
@generation_guard
|
| 106 |
+
def run(self, ui_inputs: Dict, progress):
|
| 107 |
+
progress(0, desc="正在准备模型…")
|
| 108 |
+
|
| 109 |
+
task_type = ui_inputs['task_type']
|
| 110 |
+
model_display_name = ui_inputs['model_display_name']
|
| 111 |
+
model_type = MODEL_TYPE_MAP.get(model_display_name, 'sdxl')
|
| 112 |
+
|
| 113 |
+
architectures_dict = ARCHITECTURES_CONFIG.get('architectures', {})
|
| 114 |
+
workflow_model_type = architectures_dict.get(model_type, {}).get("model_type", model_type.lower().replace(" ", "").replace(".", ""))
|
| 115 |
+
|
| 116 |
+
enabled_chains = set(
|
| 117 |
+
FEATURES_CONFIG.get(workflow_model_type, {}).get("enabled_chains", [])
|
| 118 |
+
)
|
| 119 |
+
if task_type != "txt2img":
|
| 120 |
+
has_native_references = any(
|
| 121 |
+
any(ui_inputs.get(input_key) or [])
|
| 122 |
+
for chain_name in self.NATIVE_REFERENCE_CHAINS
|
| 123 |
+
for input_key in self.CHAIN_INPUT_KEYS[chain_name]
|
| 124 |
+
)
|
| 125 |
+
if has_native_references:
|
| 126 |
+
raise gr.Error(
|
| 127 |
+
"原生多图参考编辑目前只支持“文生图 / 多图融合”。"
|
| 128 |
+
"普通逐张重绘请使用图生图;不要同时叠加源图 latent 与参考图链。"
|
| 129 |
+
)
|
| 130 |
+
for chain_name, input_keys in self.CHAIN_INPUT_KEYS.items():
|
| 131 |
+
if (
|
| 132 |
+
chain_name not in enabled_chains
|
| 133 |
+
or not supports_chain_for_model(model_display_name, chain_name)
|
| 134 |
+
):
|
| 135 |
+
for input_key in input_keys:
|
| 136 |
+
ui_inputs[input_key] = []
|
| 137 |
+
if "pid" not in enabled_chains:
|
| 138 |
+
ui_inputs["pid_settings"] = "OFF"
|
| 139 |
+
if "vae" not in enabled_chains:
|
| 140 |
+
ui_inputs["vae_source"] = None
|
| 141 |
+
ui_inputs["vae_id"] = None
|
| 142 |
+
ui_inputs["vae_file"] = None
|
| 143 |
+
|
| 144 |
+
try:
|
| 145 |
+
batch_size = int(ui_inputs.get("batch_size") or 1)
|
| 146 |
+
except (TypeError, ValueError):
|
| 147 |
+
batch_size = 1
|
| 148 |
+
if batch_size < 1 or batch_size > CONFIG.max_batch_size:
|
| 149 |
+
raise gr.Error(f"单次生成数量需为 1–{CONFIG.max_batch_size}。")
|
| 150 |
+
ui_inputs["batch_size"] = batch_size
|
| 151 |
+
|
| 152 |
+
ui_inputs['positive_prompt'] = sanitize_prompt(ui_inputs.get('positive_prompt', ''))
|
| 153 |
+
ui_inputs['negative_prompt'] = sanitize_prompt(ui_inputs.get('negative_prompt', ''))
|
| 154 |
+
|
| 155 |
+
if 'clip_skip' in ui_inputs and ui_inputs['clip_skip'] is not None:
|
| 156 |
+
ui_inputs['clip_skip'] = -int(ui_inputs['clip_skip'])
|
| 157 |
+
else:
|
| 158 |
+
ui_inputs['clip_skip'] = -1
|
| 159 |
+
|
| 160 |
+
required_models = self.get_required_models(model_display_name=model_display_name)
|
| 161 |
+
|
| 162 |
+
is_pid_enabled = (ui_inputs.get('pid_settings', 'OFF') == 'ON' and task_type == 'txt2img')
|
| 163 |
+
if is_pid_enabled:
|
| 164 |
+
import yaml
|
| 165 |
+
pid_config_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'yaml', 'pid.yaml')
|
| 166 |
+
pid_unet_name = "pid_flux1_1024_to_4096_4step_mxfp8.safetensors"
|
| 167 |
+
try:
|
| 168 |
+
with open(pid_config_path, 'r', encoding='utf-8') as f:
|
| 169 |
+
pid_config = yaml.safe_load(f) or {}
|
| 170 |
+
pid_items = pid_config.get("PiD", [])
|
| 171 |
+
for item in pid_items:
|
| 172 |
+
archs = item.get("architectures", [])
|
| 173 |
+
if workflow_model_type in archs:
|
| 174 |
+
pid_unet_name = item.get("filepath")
|
| 175 |
+
break
|
| 176 |
+
except Exception as e:
|
| 177 |
+
print(f"Error loading PiD config for download: {e}")
|
| 178 |
+
|
| 179 |
+
if pid_unet_name not in required_models:
|
| 180 |
+
required_models.append(pid_unet_name)
|
| 181 |
+
if "gemma_2_2b_it_elm_fp8_scaled.safetensors" not in required_models:
|
| 182 |
+
required_models.append("gemma_2_2b_it_elm_fp8_scaled.safetensors")
|
| 183 |
+
|
| 184 |
+
self.model_manager.ensure_models_downloaded(required_models, progress=progress)
|
| 185 |
+
cancel_event = ui_inputs.get("_cancel_event")
|
| 186 |
+
if cancel_event is not None and cancel_event.is_set():
|
| 187 |
+
raise TaskCancelledError("任务已在模型准备完成后取消,未进入 GPU 生成。")
|
| 188 |
+
|
| 189 |
+
temp_files_to_clean = []
|
| 190 |
+
try:
|
| 191 |
+
processed = process_pipeline_inputs(ui_inputs, progress, workflow_model_type)
|
| 192 |
+
temp_files_to_clean.extend(processed["temp_files_to_clean"])
|
| 193 |
+
|
| 194 |
+
active_loras_for_gpu = processed["active_loras_for_gpu"]
|
| 195 |
+
active_loras_for_meta = processed["active_loras_for_meta"]
|
| 196 |
+
active_controlnets = processed["active_controlnets"]
|
| 197 |
+
active_anima_controlnets = processed["active_anima_controlnets"]
|
| 198 |
+
active_diffsynth_controlnets = processed["active_diffsynth_controlnets"]
|
| 199 |
+
active_krea2_controlnets = processed.get("active_krea2_controlnets", [])
|
| 200 |
+
active_ipadapters = processed["active_ipadapters"]
|
| 201 |
+
active_flux1_ipadapters = processed["active_flux1_ipadapters"]
|
| 202 |
+
active_sd3_ipadapters = processed["active_sd3_ipadapters"]
|
| 203 |
+
active_styles = processed["active_styles"]
|
| 204 |
+
active_reference_latents = processed["active_reference_latents"]
|
| 205 |
+
active_hidream_o1_reference = processed["active_hidream_o1_reference"]
|
| 206 |
+
active_joyai_reference = processed.get("active_joyai_reference", [])
|
| 207 |
+
active_krea2_identity_edit = processed.get("active_krea2_identity_edit", [])
|
| 208 |
+
active_krea2_reference_edit = processed.get("active_krea2_reference_edit", [])
|
| 209 |
+
active_qwen_image_edit = processed.get("active_qwen_image_edit", [])
|
| 210 |
+
active_boogu_edit = processed.get("active_boogu_edit", [])
|
| 211 |
+
active_reference_images = processed.get("active_reference_images", [])
|
| 212 |
+
active_conditioning = processed["active_conditioning"]
|
| 213 |
+
|
| 214 |
+
loras_string = f"LoRAs: [{', '.join(active_loras_for_meta)}]" if active_loras_for_meta else ""
|
| 215 |
+
|
| 216 |
+
progress(0.8, desc="正在组装工作流…")
|
| 217 |
+
|
| 218 |
+
seed_val = ui_inputs.get('seed')
|
| 219 |
+
if seed_val is None or seed_val == -1:
|
| 220 |
+
ui_inputs['seed'] = random.randint(0, 2**32 - 1)
|
| 221 |
+
|
| 222 |
+
model_info = ALL_MODEL_MAP[model_display_name]
|
| 223 |
+
path_or_components = model_info[1]
|
| 224 |
+
latent_type = model_info[3] if len(model_info) > 3 and model_info[3] else 'latent'
|
| 225 |
+
latent_generator_template = "EmptyLatentImage"
|
| 226 |
+
if latent_type == 'sd3_latent':
|
| 227 |
+
latent_generator_template = "EmptySD3LatentImage"
|
| 228 |
+
elif latent_type == 'chroma_radiance_latent':
|
| 229 |
+
latent_generator_template = "EmptyChromaRadianceLatentImage"
|
| 230 |
+
elif latent_type == 'hunyuan_latent':
|
| 231 |
+
latent_generator_template = "EmptyHunyuanImageLatent"
|
| 232 |
+
|
| 233 |
+
dynamic_values = {
|
| 234 |
+
'task_type': ui_inputs['task_type'],
|
| 235 |
+
'model_type': workflow_model_type,
|
| 236 |
+
'latent_type': latent_type,
|
| 237 |
+
'latent_generator_template': latent_generator_template
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
recipe_path = os.path.join(os.path.dirname(__file__), "workflow_recipes", "unified_recipe.yaml")
|
| 241 |
+
assembler = WorkflowAssembler(recipe_path, dynamic_values=dynamic_values)
|
| 242 |
+
|
| 243 |
+
hidream_o1_smoothing_data = []
|
| 244 |
+
if workflow_model_type == 'hidream-o1' and model_display_name == "HiDream-O1-Image":
|
| 245 |
+
hidream_o1_smoothing_data.append({})
|
| 246 |
+
|
| 247 |
+
workflow_inputs = {
|
| 248 |
+
**ui_inputs,
|
| 249 |
+
"positive_prompt": ui_inputs['positive_prompt'], "negative_prompt": ui_inputs['negative_prompt'],
|
| 250 |
+
"seed": ui_inputs['seed'], "steps": ui_inputs['num_inference_steps'], "cfg": ui_inputs['guidance_scale'],
|
| 251 |
+
"sampler_name": ui_inputs['sampler'], "scheduler": ui_inputs['scheduler'],
|
| 252 |
+
"batch_size": ui_inputs['batch_size'],
|
| 253 |
+
"clip_skip": ui_inputs['clip_skip'],
|
| 254 |
+
"denoise": ui_inputs['denoise'],
|
| 255 |
+
"vae_name": ui_inputs.get('vae_name'),
|
| 256 |
+
"guidance": ui_inputs.get('guidance', 3.5),
|
| 257 |
+
"lora_chain": active_loras_for_gpu,
|
| 258 |
+
"controlnet_chain": active_controlnets if not active_anima_controlnets else [],
|
| 259 |
+
"anima_controlnet_lllite_chain": active_anima_controlnets,
|
| 260 |
+
"diffsynth_controlnet_chain": active_diffsynth_controlnets,
|
| 261 |
+
"krea2_controlnet_chain": active_krea2_controlnets,
|
| 262 |
+
"ipadapter_chain": active_ipadapters,
|
| 263 |
+
"flux1_ipadapter_chain": active_flux1_ipadapters,
|
| 264 |
+
"sd3_ipadapter_chain": active_sd3_ipadapters,
|
| 265 |
+
"style_chain": active_styles,
|
| 266 |
+
"conditioning_chain": active_conditioning,
|
| 267 |
+
"reference_latent_chain": active_reference_latents,
|
| 268 |
+
"hidream_o1_reference_chain": active_hidream_o1_reference,
|
| 269 |
+
"joyai_image_chain": active_joyai_reference,
|
| 270 |
+
"krea2_identity_edit_chain": active_krea2_identity_edit,
|
| 271 |
+
"krea2_style_reference_chain": active_krea2_reference_edit,
|
| 272 |
+
"qwen_image_edit_chain": active_qwen_image_edit,
|
| 273 |
+
"boogu_image_edit_chain": active_boogu_edit,
|
| 274 |
+
"reference_image_chain": active_reference_images,
|
| 275 |
+
"vae_chain": [ui_inputs.get('vae_name')] if ui_inputs.get('vae_name') else [],
|
| 276 |
+
"hidream_o1_smoothing_chain": hidream_o1_smoothing_data,
|
| 277 |
+
"pid_chain": [ui_inputs.get('pid_settings', 'OFF')] if is_pid_enabled else [],
|
| 278 |
+
"scheduler_width": ui_inputs.get('width', 1024),
|
| 279 |
+
"scheduler_height": ui_inputs.get('height', 1024),
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
if isinstance(path_or_components, dict):
|
| 283 |
+
workflow_inputs.update({
|
| 284 |
+
'unet_name': path_or_components.get('unet'),
|
| 285 |
+
'unet_uncond_name': path_or_components.get('unet_uncond'),
|
| 286 |
+
'vae_name': ui_inputs.get('vae_name') or path_or_components.get('vae'),
|
| 287 |
+
'clip_name': path_or_components.get('clip'),
|
| 288 |
+
'clip1_name': path_or_components.get('clip1'),
|
| 289 |
+
'clip2_name': path_or_components.get('clip2'),
|
| 290 |
+
'clip3_name': path_or_components.get('clip3'),
|
| 291 |
+
'clip4_name': path_or_components.get('clip4'),
|
| 292 |
+
'lora_name': path_or_components.get('lora'),
|
| 293 |
+
})
|
| 294 |
+
else:
|
| 295 |
+
workflow_inputs['model_name'] = path_or_components
|
| 296 |
+
|
| 297 |
+
if task_type == 'txt2img':
|
| 298 |
+
workflow_inputs['width'] = ui_inputs['width']
|
| 299 |
+
workflow_inputs['height'] = ui_inputs['height']
|
| 300 |
+
|
| 301 |
+
workflow = assembler.assemble(workflow_inputs)
|
| 302 |
+
|
| 303 |
+
if cancel_event is not None and cancel_event.is_set():
|
| 304 |
+
raise TaskCancelledError("任务已在进入 GPU 前取消。")
|
| 305 |
+
|
| 306 |
+
gpu_duration = estimate_gpu_duration(ui_inputs)
|
| 307 |
+
progress(1.0, desc=f"模型已就绪,正在申请 GPU(预计上限 {gpu_duration} 秒)…")
|
| 308 |
+
|
| 309 |
+
results = self._execute_gpu_logic(
|
| 310 |
+
self._gpu_logic,
|
| 311 |
+
duration=gpu_duration,
|
| 312 |
+
default_duration=60,
|
| 313 |
+
task_name=f"ImageGen ({task_type})",
|
| 314 |
+
ui_inputs=ui_inputs,
|
| 315 |
+
loras_string=loras_string,
|
| 316 |
+
workflow=workflow,
|
| 317 |
+
assembler=assembler,
|
| 318 |
+
progress=progress
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
import json
|
| 322 |
+
import glob
|
| 323 |
+
from PIL import PngImagePlugin
|
| 324 |
+
|
| 325 |
+
prompt_json = json.dumps(workflow)
|
| 326 |
+
|
| 327 |
+
out_dir = os.path.abspath(OUTPUT_DIR)
|
| 328 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 329 |
+
|
| 330 |
+
try:
|
| 331 |
+
existing_files = glob.glob(os.path.join(out_dir, "gen_*.png"))
|
| 332 |
+
existing_files.sort(key=os.path.getmtime)
|
| 333 |
+
keep_existing = max(0, CONFIG.output_retention - len(results))
|
| 334 |
+
while len(existing_files) > keep_existing:
|
| 335 |
+
os.remove(existing_files.pop(0))
|
| 336 |
+
except Exception as e:
|
| 337 |
+
print(f"Warning: Failed to cleanup output dir: {e}")
|
| 338 |
+
|
| 339 |
+
final_results = []
|
| 340 |
+
for img in results:
|
| 341 |
+
if not isinstance(img, Image.Image):
|
| 342 |
+
final_results.append(img)
|
| 343 |
+
continue
|
| 344 |
+
|
| 345 |
+
metadata = PngImagePlugin.PngInfo()
|
| 346 |
+
params_string = img.info.get("parameters", "")
|
| 347 |
+
if params_string:
|
| 348 |
+
metadata.add_text("parameters", params_string)
|
| 349 |
+
metadata.add_text("prompt", prompt_json)
|
| 350 |
+
|
| 351 |
+
filename = f"gen_{uuid.uuid4().hex}.png"
|
| 352 |
+
filepath = os.path.join(out_dir, filename)
|
| 353 |
+
img.save(filepath, "PNG", pnginfo=metadata)
|
| 354 |
+
final_results.append(filepath)
|
| 355 |
+
|
| 356 |
+
results = final_results
|
| 357 |
+
|
| 358 |
+
finally:
|
| 359 |
+
for temp_file in temp_files_to_clean:
|
| 360 |
+
if temp_file and os.path.exists(temp_file):
|
| 361 |
+
os.remove(temp_file)
|
| 362 |
+
print(f"✅ Cleaned up temp file: {temp_file}")
|
| 363 |
+
|
| 364 |
+
return results
|
core/pipelines/workflow_executor.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from collections import defaultdict, deque
|
| 3 |
+
from typing import Dict, Any, List
|
| 4 |
+
from comfy_integration.nodes import NODE_CLASS_MAPPINGS
|
| 5 |
+
from imagegen_utils.app_utils import get_value_at_index
|
| 6 |
+
|
| 7 |
+
class WorkflowExecutor:
|
| 8 |
+
@staticmethod
|
| 9 |
+
def topological_sort(workflow: Dict[str, Any]) -> List[str]:
|
| 10 |
+
graph = defaultdict(list)
|
| 11 |
+
in_degree = {node_id: 0 for node_id in workflow}
|
| 12 |
+
|
| 13 |
+
for node_id, node_info in workflow.items():
|
| 14 |
+
for input_value in node_info.get('inputs', {}).values():
|
| 15 |
+
if isinstance(input_value, list) and len(input_value) == 2 and isinstance(input_value[0], str):
|
| 16 |
+
source_node_id = input_value[0]
|
| 17 |
+
if source_node_id in workflow:
|
| 18 |
+
graph[source_node_id].append(node_id)
|
| 19 |
+
in_degree[node_id] += 1
|
| 20 |
+
|
| 21 |
+
queue = deque([node_id for node_id, degree in in_degree.items() if degree == 0])
|
| 22 |
+
|
| 23 |
+
sorted_nodes = []
|
| 24 |
+
while queue:
|
| 25 |
+
current_node_id = queue.popleft()
|
| 26 |
+
sorted_nodes.append(current_node_id)
|
| 27 |
+
|
| 28 |
+
for neighbor_node_id in graph[current_node_id]:
|
| 29 |
+
in_degree[neighbor_node_id] -= 1
|
| 30 |
+
if in_degree[neighbor_node_id] == 0:
|
| 31 |
+
queue.append(neighbor_node_id)
|
| 32 |
+
|
| 33 |
+
if len(sorted_nodes) != len(workflow):
|
| 34 |
+
raise RuntimeError("Workflow contains a cycle and cannot be executed.")
|
| 35 |
+
|
| 36 |
+
return sorted_nodes
|
| 37 |
+
|
| 38 |
+
@staticmethod
|
| 39 |
+
def execute_workflow(workflow: Dict[str, Any], initial_objects: Dict[str, Any]):
|
| 40 |
+
with torch.no_grad():
|
| 41 |
+
computed_outputs = initial_objects
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
sorted_node_ids = WorkflowExecutor.topological_sort(workflow)
|
| 45 |
+
|
| 46 |
+
final_node_id = None
|
| 47 |
+
for node_id in reversed(sorted_node_ids):
|
| 48 |
+
if workflow[node_id].get('class_type') == 'SaveImage':
|
| 49 |
+
final_node_id = node_id
|
| 50 |
+
break
|
| 51 |
+
|
| 52 |
+
if final_node_id:
|
| 53 |
+
required_nodes = set()
|
| 54 |
+
nodes_to_visit = [final_node_id]
|
| 55 |
+
while nodes_to_visit:
|
| 56 |
+
curr_id = nodes_to_visit.pop()
|
| 57 |
+
if curr_id in required_nodes:
|
| 58 |
+
continue
|
| 59 |
+
required_nodes.add(curr_id)
|
| 60 |
+
curr_info = workflow.get(curr_id, {})
|
| 61 |
+
for input_val in curr_info.get('inputs', {}).values():
|
| 62 |
+
if isinstance(input_val, list) and len(input_val) == 2 and isinstance(input_val[0], str):
|
| 63 |
+
src_id = input_val[0]
|
| 64 |
+
if src_id in workflow and src_id not in required_nodes:
|
| 65 |
+
nodes_to_visit.append(src_id)
|
| 66 |
+
|
| 67 |
+
sorted_node_ids = [nid for nid in sorted_node_ids if nid in required_nodes]
|
| 68 |
+
|
| 69 |
+
print(f"--- [Workflow Executor] Execution order: {sorted_node_ids}")
|
| 70 |
+
except RuntimeError as e:
|
| 71 |
+
print("--- [Workflow Executor] ERROR: Failed to sort workflow. Dumping graph details. ---")
|
| 72 |
+
for node_id, node_info in workflow.items():
|
| 73 |
+
print(f" Node {node_id} ({node_info['class_type']}):")
|
| 74 |
+
for input_name, input_value in node_info['inputs'].items():
|
| 75 |
+
if isinstance(input_value, list) and len(input_value) == 2 and isinstance(input_value[0], str):
|
| 76 |
+
print(f" - {input_name} <- [{input_value[0]}, {input_value[1]}]")
|
| 77 |
+
raise e
|
| 78 |
+
|
| 79 |
+
for node_id in sorted_node_ids:
|
| 80 |
+
if node_id in computed_outputs:
|
| 81 |
+
continue
|
| 82 |
+
|
| 83 |
+
node_info = workflow[node_id]
|
| 84 |
+
class_type = node_info['class_type']
|
| 85 |
+
|
| 86 |
+
# The pipeline writes the final PNG itself so it can attach the
|
| 87 |
+
# canonical parameters and full workflow metadata. Executing
|
| 88 |
+
# ComfyUI's SaveImage here would create an untracked duplicate.
|
| 89 |
+
if class_type == 'SaveImage':
|
| 90 |
+
continue
|
| 91 |
+
|
| 92 |
+
is_loader_with_filename = 'Loader' in class_type and any(key.endswith('_name') for key in node_info['inputs'])
|
| 93 |
+
if node_id in initial_objects and is_loader_with_filename:
|
| 94 |
+
continue
|
| 95 |
+
|
| 96 |
+
node_class = NODE_CLASS_MAPPINGS.get(class_type)
|
| 97 |
+
if node_class is None:
|
| 98 |
+
raise RuntimeError(f"Could not find node class '{class_type}'. Is it imported in comfy_integration/nodes.py?")
|
| 99 |
+
|
| 100 |
+
node_instance = node_class()
|
| 101 |
+
|
| 102 |
+
kwargs = {}
|
| 103 |
+
for param_name, param_value in node_info['inputs'].items():
|
| 104 |
+
if isinstance(param_value, list) and len(param_value) == 2 and isinstance(param_value[0], str):
|
| 105 |
+
source_node_id, output_index = param_value
|
| 106 |
+
if source_node_id not in computed_outputs:
|
| 107 |
+
raise RuntimeError(f"Workflow integrity error: Output of node {source_node_id} needed for {node_id} but not yet computed.")
|
| 108 |
+
|
| 109 |
+
source_output_tuple = computed_outputs[source_node_id]
|
| 110 |
+
actual_value = get_value_at_index(source_output_tuple, output_index)
|
| 111 |
+
else:
|
| 112 |
+
actual_value = param_value
|
| 113 |
+
|
| 114 |
+
if '.' in param_name:
|
| 115 |
+
parent_key, child_key = param_name.split('.', 1)
|
| 116 |
+
if parent_key not in kwargs or not isinstance(kwargs[parent_key], dict):
|
| 117 |
+
kwargs[parent_key] = {}
|
| 118 |
+
kwargs[parent_key][child_key] = actual_value
|
| 119 |
+
else:
|
| 120 |
+
kwargs[param_name] = actual_value
|
| 121 |
+
|
| 122 |
+
function_name = getattr(node_class, 'FUNCTION')
|
| 123 |
+
execution_method = getattr(node_instance, function_name)
|
| 124 |
+
|
| 125 |
+
result = execution_method(**kwargs)
|
| 126 |
+
computed_outputs[node_id] = result
|
| 127 |
+
|
| 128 |
+
final_node_id = None
|
| 129 |
+
for node_id in reversed(sorted_node_ids):
|
| 130 |
+
if workflow[node_id]['class_type'] == 'SaveImage':
|
| 131 |
+
final_node_id = node_id
|
| 132 |
+
break
|
| 133 |
+
|
| 134 |
+
if not final_node_id:
|
| 135 |
+
raise RuntimeError("Workflow does not contain a 'SaveImage' node as the output.")
|
| 136 |
+
|
| 137 |
+
save_image_inputs = workflow[final_node_id]['inputs']
|
| 138 |
+
image_source_node_id, image_source_index = save_image_inputs['images']
|
| 139 |
+
|
| 140 |
+
return get_value_at_index(computed_outputs[image_source_node_id], image_source_index)
|
core/pipelines/workflow_recipes/_partials/_base_sampler.yaml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
ksampler:
|
| 3 |
+
class_type: KSampler
|
| 4 |
+
title: "KSampler"
|
| 5 |
+
params:
|
| 6 |
+
denoise: 1.0
|
| 7 |
+
vae_decode:
|
| 8 |
+
class_type: VAEDecode
|
| 9 |
+
title: "VAE Decode"
|
| 10 |
+
save_image:
|
| 11 |
+
class_type: SaveImage
|
| 12 |
+
title: "Save Image"
|
| 13 |
+
params: {}
|
| 14 |
+
|
| 15 |
+
connections:
|
| 16 |
+
- from: "ksampler:0"
|
| 17 |
+
to: "vae_decode:samples"
|
| 18 |
+
- from: "vae_decode:0"
|
| 19 |
+
to: "save_image:images"
|
| 20 |
+
|
| 21 |
+
ui_map:
|
| 22 |
+
seed: "ksampler:seed"
|
| 23 |
+
steps: "ksampler:steps"
|
| 24 |
+
cfg: "ksampler:cfg"
|
| 25 |
+
sampler_name: "ksampler:sampler_name"
|
| 26 |
+
scheduler: "ksampler:scheduler"
|
| 27 |
+
denoise: "ksampler:denoise"
|
| 28 |
+
filename_prefix: "save_image:filename_prefix"
|
core/pipelines/workflow_recipes/_partials/conditioning/anima.yaml
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load Diffusion Model"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load VAE"
|
| 16 |
+
clip_loader:
|
| 17 |
+
class_type: CLIPLoader
|
| 18 |
+
title: "Load CLIP"
|
| 19 |
+
params:
|
| 20 |
+
type: "stable_diffusion"
|
| 21 |
+
device: "default"
|
| 22 |
+
|
| 23 |
+
connections:
|
| 24 |
+
- from: "unet_loader:0"
|
| 25 |
+
to: "ksampler:model"
|
| 26 |
+
- from: "clip_loader:0"
|
| 27 |
+
to: "pos_prompt:clip"
|
| 28 |
+
- from: "clip_loader:0"
|
| 29 |
+
to: "neg_prompt:clip"
|
| 30 |
+
- from: "vae_loader:0"
|
| 31 |
+
to: "vae_decode:vae"
|
| 32 |
+
- from: "vae_loader:0"
|
| 33 |
+
to: "vae_encode:vae"
|
| 34 |
+
- from: "pos_prompt:0"
|
| 35 |
+
to: "ksampler:positive"
|
| 36 |
+
- from: "neg_prompt:0"
|
| 37 |
+
to: "ksampler:negative"
|
| 38 |
+
|
| 39 |
+
dynamic_lora_chains:
|
| 40 |
+
lora_chain:
|
| 41 |
+
template: "LoraLoader"
|
| 42 |
+
output_map:
|
| 43 |
+
"unet_loader:0": "model"
|
| 44 |
+
"clip_loader:0": "clip"
|
| 45 |
+
input_map:
|
| 46 |
+
"model": "model"
|
| 47 |
+
"clip": "clip"
|
| 48 |
+
end_input_map:
|
| 49 |
+
"model": ["ksampler:model"]
|
| 50 |
+
"clip": ["pos_prompt:clip", "neg_prompt:clip"]
|
| 51 |
+
|
| 52 |
+
dynamic_anima_controlnet_lllite_chains:
|
| 53 |
+
anima_controlnet_lllite_chain:
|
| 54 |
+
ksampler_node: "ksampler"
|
| 55 |
+
|
| 56 |
+
dynamic_conditioning_chains:
|
| 57 |
+
conditioning_chain:
|
| 58 |
+
ksampler_node: "ksampler"
|
| 59 |
+
clip_source: "clip_loader:0"
|
| 60 |
+
|
| 61 |
+
dynamic_pid_chains:
|
| 62 |
+
pid_chain:
|
| 63 |
+
ksampler_node: "ksampler"
|
| 64 |
+
|
| 65 |
+
ui_map:
|
| 66 |
+
positive_prompt: "pos_prompt:text"
|
| 67 |
+
negative_prompt: "neg_prompt:text"
|
| 68 |
+
unet_name: "unet_loader:unet_name"
|
| 69 |
+
vae_name: "vae_loader:vae_name"
|
| 70 |
+
clip_name: "clip_loader:clip_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/auraflow.yaml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
ckpt_loader:
|
| 9 |
+
class_type: CheckpointLoaderSimple
|
| 10 |
+
title: "Load Checkpoint"
|
| 11 |
+
|
| 12 |
+
connections:
|
| 13 |
+
- from: "ckpt_loader:0"
|
| 14 |
+
to: "ksampler:model"
|
| 15 |
+
- from: "ckpt_loader:1"
|
| 16 |
+
to: "pos_prompt:clip"
|
| 17 |
+
- from: "ckpt_loader:1"
|
| 18 |
+
to: "neg_prompt:clip"
|
| 19 |
+
- from: "pos_prompt:0"
|
| 20 |
+
to: "ksampler:positive"
|
| 21 |
+
- from: "neg_prompt:0"
|
| 22 |
+
to: "ksampler:negative"
|
| 23 |
+
- from: "ckpt_loader:2"
|
| 24 |
+
to: "vae_decode:vae"
|
| 25 |
+
- from: "ckpt_loader:2"
|
| 26 |
+
to: "vae_encode:vae"
|
| 27 |
+
|
| 28 |
+
dynamic_vae_chains:
|
| 29 |
+
vae_chain:
|
| 30 |
+
targets:
|
| 31 |
+
- "vae_decode:vae"
|
| 32 |
+
- "vae_encode:vae"
|
| 33 |
+
|
| 34 |
+
dynamic_lora_chains:
|
| 35 |
+
lora_chain:
|
| 36 |
+
template: "LoraLoader"
|
| 37 |
+
start: "ckpt_loader"
|
| 38 |
+
output_map:
|
| 39 |
+
"0": "model"
|
| 40 |
+
"1": "clip"
|
| 41 |
+
input_map:
|
| 42 |
+
"model": "model"
|
| 43 |
+
"clip": "clip"
|
| 44 |
+
end_input_map:
|
| 45 |
+
"model": ["ksampler:model"]
|
| 46 |
+
"clip": ["pos_prompt:clip", "neg_prompt:clip"]
|
| 47 |
+
|
| 48 |
+
dynamic_conditioning_chains:
|
| 49 |
+
conditioning_chain:
|
| 50 |
+
ksampler_node: "ksampler"
|
| 51 |
+
clip_source: "ckpt_loader:1"
|
| 52 |
+
|
| 53 |
+
ui_map:
|
| 54 |
+
positive_prompt: "pos_prompt:text"
|
| 55 |
+
negative_prompt: "neg_prompt:text"
|
| 56 |
+
model_name: "ckpt_loader:ckpt_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/boogu-image.yaml
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
boogu_prompt:
|
| 3 |
+
class_type: TextEncodeBooguEdit
|
| 4 |
+
title: "Text Encode Boogu Edit"
|
| 5 |
+
unet_loader:
|
| 6 |
+
class_type: UNETLoader
|
| 7 |
+
title: "Load Diffusion Model"
|
| 8 |
+
params:
|
| 9 |
+
weight_dtype: "default"
|
| 10 |
+
clip_loader:
|
| 11 |
+
class_type: CLIPLoader
|
| 12 |
+
title: "Load CLIP"
|
| 13 |
+
params:
|
| 14 |
+
type: "boogu"
|
| 15 |
+
device: "default"
|
| 16 |
+
vae_loader:
|
| 17 |
+
class_type: VAELoader
|
| 18 |
+
title: "Load VAE"
|
| 19 |
+
|
| 20 |
+
connections:
|
| 21 |
+
- from: "unet_loader:0"
|
| 22 |
+
to: "ksampler:model"
|
| 23 |
+
- from: "clip_loader:0"
|
| 24 |
+
to: "boogu_prompt:clip"
|
| 25 |
+
- from: "boogu_prompt:0"
|
| 26 |
+
to: "ksampler:positive"
|
| 27 |
+
- from: "boogu_prompt:1"
|
| 28 |
+
to: "ksampler:negative"
|
| 29 |
+
- from: "vae_loader:0"
|
| 30 |
+
to: "vae_decode:vae"
|
| 31 |
+
- from: "vae_loader:0"
|
| 32 |
+
to: "vae_encode:vae"
|
| 33 |
+
|
| 34 |
+
dynamic_lora_chains:
|
| 35 |
+
lora_chain:
|
| 36 |
+
template: "LoraLoader"
|
| 37 |
+
output_map:
|
| 38 |
+
"unet_loader:0": "model"
|
| 39 |
+
"clip_loader:0": "clip"
|
| 40 |
+
input_map:
|
| 41 |
+
"model": "model"
|
| 42 |
+
"clip": "clip"
|
| 43 |
+
end_input_map:
|
| 44 |
+
"model": ["ksampler:model"]
|
| 45 |
+
"clip": ["boogu_prompt:clip"]
|
| 46 |
+
|
| 47 |
+
dynamic_conditioning_chains:
|
| 48 |
+
conditioning_chain:
|
| 49 |
+
ksampler_node: "ksampler"
|
| 50 |
+
clip_source: "clip_loader:0"
|
| 51 |
+
|
| 52 |
+
dynamic_boogu_image_edit_chains:
|
| 53 |
+
boogu_image_edit_chain:
|
| 54 |
+
ksampler_node: "ksampler"
|
| 55 |
+
boogu_prompt_node: "boogu_prompt"
|
| 56 |
+
vae_loader_node: "vae_loader"
|
| 57 |
+
|
| 58 |
+
dynamic_pid_chains:
|
| 59 |
+
pid_chain:
|
| 60 |
+
ksampler_node: "ksampler"
|
| 61 |
+
|
| 62 |
+
ui_map:
|
| 63 |
+
positive_prompt: "boogu_prompt:prompt"
|
| 64 |
+
negative_prompt: "boogu_prompt:negative_prompt"
|
| 65 |
+
unet_name: "unet_loader:unet_name"
|
| 66 |
+
clip_name: "clip_loader:clip_name"
|
| 67 |
+
vae_name: "vae_loader:vae_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/chroma1-radiance.yaml
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load Diffusion Model"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load VAE"
|
| 16 |
+
params:
|
| 17 |
+
vae_name: "pixel_space"
|
| 18 |
+
clip_loader:
|
| 19 |
+
class_type: CLIPLoader
|
| 20 |
+
title: "Load CLIP"
|
| 21 |
+
params:
|
| 22 |
+
type: "chroma"
|
| 23 |
+
device: "default"
|
| 24 |
+
t5_tokenizer:
|
| 25 |
+
class_type: T5TokenizerOptions
|
| 26 |
+
title: "T5TokenizerOptions"
|
| 27 |
+
params:
|
| 28 |
+
min_padding: 0
|
| 29 |
+
min_length: 3
|
| 30 |
+
model_sampler:
|
| 31 |
+
class_type: ModelSamplingAuraFlow
|
| 32 |
+
params:
|
| 33 |
+
shift: 3.0
|
| 34 |
+
|
| 35 |
+
connections:
|
| 36 |
+
- from: "unet_loader:0"
|
| 37 |
+
to: "model_sampler:model"
|
| 38 |
+
- from: "model_sampler:0"
|
| 39 |
+
to: "ksampler:model"
|
| 40 |
+
|
| 41 |
+
- from: "clip_loader:0"
|
| 42 |
+
to: "t5_tokenizer:clip"
|
| 43 |
+
- from: "t5_tokenizer:0"
|
| 44 |
+
to: "pos_prompt:clip"
|
| 45 |
+
- from: "t5_tokenizer:0"
|
| 46 |
+
to: "neg_prompt:clip"
|
| 47 |
+
|
| 48 |
+
- from: "pos_prompt:0"
|
| 49 |
+
to: "ksampler:positive"
|
| 50 |
+
- from: "neg_prompt:0"
|
| 51 |
+
to: "ksampler:negative"
|
| 52 |
+
|
| 53 |
+
- from: "vae_loader:0"
|
| 54 |
+
to: "vae_decode:vae"
|
| 55 |
+
- from: "vae_loader:0"
|
| 56 |
+
to: "vae_encode:vae"
|
| 57 |
+
|
| 58 |
+
dynamic_conditioning_chains:
|
| 59 |
+
conditioning_chain:
|
| 60 |
+
ksampler_node: "ksampler"
|
| 61 |
+
clip_source: "t5_tokenizer:0"
|
| 62 |
+
|
| 63 |
+
ui_map:
|
| 64 |
+
positive_prompt: "pos_prompt:text"
|
| 65 |
+
negative_prompt: "neg_prompt:text"
|
| 66 |
+
unet_name: "unet_loader:unet_name"
|
| 67 |
+
clip_name: "clip_loader:clip_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/chroma1.yaml
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load Diffusion Model"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load VAE"
|
| 16 |
+
clip_loader:
|
| 17 |
+
class_type: CLIPLoader
|
| 18 |
+
title: "Load CLIP"
|
| 19 |
+
params:
|
| 20 |
+
type: "chroma"
|
| 21 |
+
device: "default"
|
| 22 |
+
t5_tokenizer:
|
| 23 |
+
class_type: T5TokenizerOptions
|
| 24 |
+
title: "T5TokenizerOptions"
|
| 25 |
+
params:
|
| 26 |
+
min_padding: 1
|
| 27 |
+
min_length: 0
|
| 28 |
+
fresca:
|
| 29 |
+
class_type: FreSca
|
| 30 |
+
title: "FreSca"
|
| 31 |
+
params:
|
| 32 |
+
scale_low: 1.0
|
| 33 |
+
scale_high: 2.5
|
| 34 |
+
freq_cutoff: 30
|
| 35 |
+
|
| 36 |
+
connections:
|
| 37 |
+
- from: "unet_loader:0"
|
| 38 |
+
to: "fresca:model"
|
| 39 |
+
- from: "fresca:0"
|
| 40 |
+
to: "ksampler:model"
|
| 41 |
+
|
| 42 |
+
- from: "clip_loader:0"
|
| 43 |
+
to: "t5_tokenizer:clip"
|
| 44 |
+
- from: "t5_tokenizer:0"
|
| 45 |
+
to: "pos_prompt:clip"
|
| 46 |
+
- from: "t5_tokenizer:0"
|
| 47 |
+
to: "neg_prompt:clip"
|
| 48 |
+
|
| 49 |
+
- from: "pos_prompt:0"
|
| 50 |
+
to: "ksampler:positive"
|
| 51 |
+
- from: "neg_prompt:0"
|
| 52 |
+
to: "ksampler:negative"
|
| 53 |
+
|
| 54 |
+
- from: "vae_loader:0"
|
| 55 |
+
to: "vae_decode:vae"
|
| 56 |
+
- from: "vae_loader:0"
|
| 57 |
+
to: "vae_encode:vae"
|
| 58 |
+
|
| 59 |
+
dynamic_conditioning_chains:
|
| 60 |
+
conditioning_chain:
|
| 61 |
+
ksampler_node: "ksampler"
|
| 62 |
+
clip_source: "t5_tokenizer:0"
|
| 63 |
+
|
| 64 |
+
dynamic_pid_chains:
|
| 65 |
+
pid_chain:
|
| 66 |
+
ksampler_node: "ksampler"
|
| 67 |
+
|
| 68 |
+
ui_map:
|
| 69 |
+
positive_prompt: "pos_prompt:text"
|
| 70 |
+
negative_prompt: "neg_prompt:text"
|
| 71 |
+
unet_name: "unet_loader:unet_name"
|
| 72 |
+
vae_name: "vae_loader:vae_name"
|
| 73 |
+
clip_name: "clip_loader:clip_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/cosmos-predict2.yaml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load Diffusion Model"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load VAE"
|
| 16 |
+
clip_loader:
|
| 17 |
+
class_type: CLIPLoader
|
| 18 |
+
title: "Load CLIP"
|
| 19 |
+
params:
|
| 20 |
+
type: "cosmos"
|
| 21 |
+
device: "default"
|
| 22 |
+
|
| 23 |
+
connections:
|
| 24 |
+
- from: "unet_loader:0"
|
| 25 |
+
to: "ksampler:model"
|
| 26 |
+
- from: "clip_loader:0"
|
| 27 |
+
to: "pos_prompt:clip"
|
| 28 |
+
- from: "clip_loader:0"
|
| 29 |
+
to: "neg_prompt:clip"
|
| 30 |
+
- from: "pos_prompt:0"
|
| 31 |
+
to: "ksampler:positive"
|
| 32 |
+
- from: "neg_prompt:0"
|
| 33 |
+
to: "ksampler:negative"
|
| 34 |
+
- from: "vae_loader:0"
|
| 35 |
+
to: "vae_decode:vae"
|
| 36 |
+
- from: "vae_loader:0"
|
| 37 |
+
to: "vae_encode:vae"
|
| 38 |
+
|
| 39 |
+
dynamic_vae_chains:
|
| 40 |
+
vae_chain:
|
| 41 |
+
targets:
|
| 42 |
+
- "vae_decode:vae"
|
| 43 |
+
- "vae_encode:vae"
|
| 44 |
+
|
| 45 |
+
dynamic_conditioning_chains:
|
| 46 |
+
conditioning_chain:
|
| 47 |
+
ksampler_node: "ksampler"
|
| 48 |
+
clip_source: "clip_loader:0"
|
| 49 |
+
|
| 50 |
+
ui_map:
|
| 51 |
+
positive_prompt: "pos_prompt:text"
|
| 52 |
+
negative_prompt: "neg_prompt:text"
|
| 53 |
+
unet_name: "unet_loader:unet_name"
|
| 54 |
+
vae_name: "vae_loader:vae_name"
|
| 55 |
+
clip_name: "clip_loader:clip_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/ernie-image.yaml
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load Diffusion Model"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
clip_loader:
|
| 14 |
+
class_type: CLIPLoader
|
| 15 |
+
title: "Load CLIP"
|
| 16 |
+
params:
|
| 17 |
+
type: "flux2"
|
| 18 |
+
device: "default"
|
| 19 |
+
vae_loader:
|
| 20 |
+
class_type: VAELoader
|
| 21 |
+
title: "Load VAE"
|
| 22 |
+
|
| 23 |
+
connections:
|
| 24 |
+
- from: "unet_loader:0"
|
| 25 |
+
to: "ksampler:model"
|
| 26 |
+
- from: "clip_loader:0"
|
| 27 |
+
to: "pos_prompt:clip"
|
| 28 |
+
- from: "clip_loader:0"
|
| 29 |
+
to: "neg_prompt:clip"
|
| 30 |
+
- from: "pos_prompt:0"
|
| 31 |
+
to: "ksampler:positive"
|
| 32 |
+
- from: "neg_prompt:0"
|
| 33 |
+
to: "ksampler:negative"
|
| 34 |
+
- from: "vae_loader:0"
|
| 35 |
+
to: "vae_decode:vae"
|
| 36 |
+
- from: "vae_loader:0"
|
| 37 |
+
to: "vae_encode:vae"
|
| 38 |
+
|
| 39 |
+
dynamic_lora_chains:
|
| 40 |
+
lora_chain:
|
| 41 |
+
template: "LoraLoader"
|
| 42 |
+
output_map:
|
| 43 |
+
"unet_loader:0": "model"
|
| 44 |
+
"clip_loader:0": "clip"
|
| 45 |
+
input_map:
|
| 46 |
+
"model": "model"
|
| 47 |
+
"clip": "clip"
|
| 48 |
+
end_input_map:
|
| 49 |
+
"model": ["ksampler:model"]
|
| 50 |
+
"clip": ["pos_prompt:clip", "neg_prompt:clip"]
|
| 51 |
+
|
| 52 |
+
dynamic_conditioning_chains:
|
| 53 |
+
conditioning_chain:
|
| 54 |
+
ksampler_node: "ksampler"
|
| 55 |
+
clip_source: "clip_loader:0"
|
| 56 |
+
|
| 57 |
+
dynamic_pid_chains:
|
| 58 |
+
pid_chain:
|
| 59 |
+
ksampler_node: "ksampler"
|
| 60 |
+
|
| 61 |
+
ui_map:
|
| 62 |
+
positive_prompt: "pos_prompt:text"
|
| 63 |
+
negative_prompt: "neg_prompt:text"
|
| 64 |
+
unet_name: "unet_loader:unet_name"
|
| 65 |
+
clip_name: "clip_loader:clip_name"
|
| 66 |
+
vae_name: "vae_loader:vae_name"
|
core/pipelines/workflow_recipes/_partials/conditioning/flux1.yaml
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
pos_prompt:
|
| 3 |
+
class_type: CLIPTextEncode
|
| 4 |
+
title: "CLIP Text Encode (Positive)"
|
| 5 |
+
neg_prompt:
|
| 6 |
+
class_type: CLIPTextEncode
|
| 7 |
+
title: "CLIP Text Encode (Negative)"
|
| 8 |
+
unet_loader:
|
| 9 |
+
class_type: UNETLoader
|
| 10 |
+
title: "Load FLUX UNET"
|
| 11 |
+
params:
|
| 12 |
+
weight_dtype: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load FLUX VAE"
|
| 16 |
+
clip_loader:
|
| 17 |
+
class_type: DualCLIPLoader
|
| 18 |
+
title: "Load FLUX Dual CLIP"
|
| 19 |
+
params:
|
| 20 |
+
type: "flux"
|
| 21 |
+
device: "default"
|
| 22 |
+
flux_guidance:
|
| 23 |
+
class_type: FluxGuidance
|
| 24 |
+
title: "FluxGuidance"
|
| 25 |
+
|
| 26 |
+
connections:
|
| 27 |
+
- from: "unet_loader:0"
|
| 28 |
+
to: "ksampler:model"
|
| 29 |
+
- from: "clip_loader:0"
|
| 30 |
+
to: "pos_prompt:clip"
|
| 31 |
+
- from: "clip_loader:0"
|
| 32 |
+
to: "neg_prompt:clip"
|
| 33 |
+
- from: "vae_loader:0"
|
| 34 |
+
to: "vae_decode:vae"
|
| 35 |
+
- from: "vae_loader:0"
|
| 36 |
+
to: "vae_encode:vae"
|
| 37 |
+
- from: "pos_prompt:0"
|
| 38 |
+
to: "flux_guidance:conditioning"
|
| 39 |
+
- from: "flux_guidance:0"
|
| 40 |
+
to: "ksampler:positive"
|
| 41 |
+
- from: "neg_prompt:0"
|
| 42 |
+
to: "ksampler:negative"
|
| 43 |
+
|
| 44 |
+
dynamic_controlnet_chains:
|
| 45 |
+
controlnet_chain:
|
| 46 |
+
template: "ControlNetApplyAdvanced"
|
| 47 |
+
ksampler_node: "ksampler"
|
| 48 |
+
vae_source: "vae_loader:0"
|
| 49 |
+
|
| 50 |
+
dynamic_flux1_ipadapter_chains:
|
| 51 |
+
flux1_ipadapter_chain:
|
| 52 |
+
ksampler_node: "ksampler"
|
| 53 |
+
|
| 54 |
+
dynamic_style_chains:
|
| 55 |
+
style_chain:
|
| 56 |
+
flux_guidance_node: "flux_guidance"
|
| 57 |
+
ksampler_node: "ksampler"
|
| 58 |
+
|
| 59 |
+
dynamic_conditioning_chains:
|
| 60 |
+
conditioning_chain:
|
| 61 |
+
flux_guidance_node: "flux_guidance"
|
| 62 |
+
ksampler_node: "ksampler"
|
| 63 |
+
clip_source: "clip_loader:0"
|
| 64 |
+
|
| 65 |
+
dynamic_pid_chains:
|
| 66 |
+
pid_chain:
|
| 67 |
+
ksampler_node: "ksampler"
|
| 68 |
+
|
| 69 |
+
ui_map:
|
| 70 |
+
positive_prompt: "pos_prompt:text"
|
| 71 |
+
negative_prompt: "neg_prompt:text"
|
| 72 |
+
unet_name: "unet_loader:unet_name"
|
| 73 |
+
vae_name: "vae_loader:vae_name"
|
| 74 |
+
clip1_name: "clip_loader:clip_name1"
|
| 75 |
+
clip2_name: "clip_loader:clip_name2"
|
| 76 |
+
guidance: "flux_guidance:guidance"
|
core/pipelines/workflow_recipes/_partials/conditioning/flux2-kv.yaml
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nodes:
|
| 2 |
+
unet_loader:
|
| 3 |
+
class_type: UNETLoader
|
| 4 |
+
title: "Load Diffusion Model"
|
| 5 |
+
params:
|
| 6 |
+
weight_dtype: "default"
|
| 7 |
+
clip_loader:
|
| 8 |
+
class_type: CLIPLoader
|
| 9 |
+
title: "Load CLIP"
|
| 10 |
+
params:
|
| 11 |
+
type: "flux2"
|
| 12 |
+
device: "default"
|
| 13 |
+
vae_loader:
|
| 14 |
+
class_type: VAELoader
|
| 15 |
+
title: "Load VAE"
|
| 16 |
+
|
| 17 |
+
flux_kv_cache:
|
| 18 |
+
class_type: FluxKVCache
|
| 19 |
+
title: "Flux KV Cache"
|
| 20 |
+
|
| 21 |
+
pos_prompt:
|
| 22 |
+
class_type: CLIPTextEncode
|
| 23 |
+
title: "CLIP Text Encode (Positive)"
|
| 24 |
+
neg_prompt:
|
| 25 |
+
class_type: CLIPTextEncode
|
| 26 |
+
title: "CLIP Text Encode (Negative)"
|
| 27 |
+
|
| 28 |
+
ksampler:
|
| 29 |
+
class_type: KSampler
|
| 30 |
+
title: "KSampler"
|
| 31 |
+
params:
|
| 32 |
+
denoise: 1.0
|
| 33 |
+
|
| 34 |
+
vae_decode:
|
| 35 |
+
class_type: VAEDecode
|
| 36 |
+
title: "VAE Decode"
|
| 37 |
+
|
| 38 |
+
save_image:
|
| 39 |
+
class_type: SaveImage
|
| 40 |
+
title: "Save Image"
|
| 41 |
+
|
| 42 |
+
connections:
|
| 43 |
+
- from: "unet_loader:0"
|
| 44 |
+
to: "flux_kv_cache:model"
|
| 45 |
+
- from: "flux_kv_cache:0"
|
| 46 |
+
to: "ksampler:model"
|
| 47 |
+
|
| 48 |
+
- from: "clip_loader:0"
|
| 49 |
+
to: "pos_prompt:clip"
|
| 50 |
+
- from: "clip_loader:0"
|
| 51 |
+
to: "neg_prompt:clip"
|
| 52 |
+
|
| 53 |
+
- from: "vae_loader:0"
|
| 54 |
+
to: "vae_decode:vae"
|
| 55 |
+
- from: "vae_loader:0"
|
| 56 |
+
to: "vae_encode:vae"
|
| 57 |
+
|
| 58 |
+
- from: "pos_prompt:0"
|
| 59 |
+
to: "ksampler:positive"
|
| 60 |
+
- from: "neg_prompt:0"
|
| 61 |
+
to: "ksampler:negative"
|
| 62 |
+
|
| 63 |
+
- from: "latent_source:0"
|
| 64 |
+
to: "ksampler:latent_image"
|
| 65 |
+
|
| 66 |
+
- from: "ksampler:0"
|
| 67 |
+
to: "vae_decode:samples"
|
| 68 |
+
- from: "vae_decode:0"
|
| 69 |
+
to: "save_image:images"
|
| 70 |
+
|
| 71 |
+
dynamic_lora_chains:
|
| 72 |
+
lora_chain:
|
| 73 |
+
template: "LoraLoader"
|
| 74 |
+
output_map:
|
| 75 |
+
"unet_loader:0": "model"
|
| 76 |
+
"clip_loader:0": "clip"
|
| 77 |
+
input_map:
|
| 78 |
+
"model": "model"
|
| 79 |
+
"clip": "clip"
|
| 80 |
+
end_input_map:
|
| 81 |
+
"model": ["flux_kv_cache:model"]
|
| 82 |
+
"clip": ["pos_prompt:clip", "neg_prompt:clip"]
|
| 83 |
+
|
| 84 |
+
dynamic_reference_latent_chains:
|
| 85 |
+
reference_latent_chain:
|
| 86 |
+
ksampler_node: "ksampler"
|
| 87 |
+
vae_node: "vae_loader"
|
| 88 |
+
|
| 89 |
+
dynamic_pid_chains:
|
| 90 |
+
pid_chain:
|
| 91 |
+
ksampler_node: "ksampler"
|
| 92 |
+
|
| 93 |
+
ui_map:
|
| 94 |
+
unet_name: "unet_loader:unet_name"
|
| 95 |
+
clip_name: "clip_loader:clip_name"
|
| 96 |
+
vae_name: "vae_loader:vae_name"
|
| 97 |
+
|
| 98 |
+
positive_prompt: "pos_prompt:text"
|
| 99 |
+
negative_prompt: "neg_prompt:text"
|
| 100 |
+
|
| 101 |
+
seed: "ksampler:seed"
|
| 102 |
+
steps: "ksampler:steps"
|
| 103 |
+
cfg: "ksampler:cfg"
|
| 104 |
+
sampler_name: "ksampler:sampler_name"
|
| 105 |
+
scheduler: "ksampler:scheduler"
|
| 106 |
+
denoise: "ksampler:denoise"
|
| 107 |
+
|
| 108 |
+
filename_prefix: "save_image:filename_prefix"
|