├── .github └── workflows │ └── publish_action.yaml ├── .gitignore ├── LICENSE ├── README.md ├── __init__.py ├── examples ├── full_compare.json ├── omost_ipa.json └── omost_llm.json ├── js └── omost_canvas_editor_index.js ├── lib_omost ├── __init__.py ├── canvas.py ├── greedy_encode.py └── utils.py ├── omost_nodes.py ├── pyproject.toml ├── requirements.txt └── tests ├── __init__.py └── greedy_encode_test.py /.github/workflows/publish_action.yaml: -------------------------------------------------------------------------------- 1 | name: Publish to Comfy registry 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - "pyproject.toml" 9 | 10 | permissions: 11 | issues: write 12 | 13 | jobs: 14 | publish-node: 15 | name: Publish Custom Node to registry 16 | runs-on: ubuntu-latest 17 | if: ${{ github.repository_owner == 'huchenlei' }} 18 | steps: 19 | - name: Check out code 20 | uses: actions/checkout@v4 21 | - name: Publish Custom Node 22 | uses: Comfy-Org/publish-node-action@v1 23 | with: 24 | personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }} 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 110 | .pdm.toml 111 | .pdm-python 112 | .pdm-build/ 113 | 114 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 115 | __pypackages__/ 116 | 117 | # Celery stuff 118 | celerybeat-schedule 119 | celerybeat.pid 120 | 121 | # SageMath parsed files 122 | *.sage.py 123 | 124 | # Environments 125 | .env 126 | .venv 127 | env/ 128 | venv/ 129 | ENV/ 130 | env.bak/ 131 | venv.bak/ 132 | 133 | # Spyder project settings 134 | .spyderproject 135 | .spyproject 136 | 137 | # Rope project settings 138 | .ropeproject 139 | 140 | # mkdocs documentation 141 | /site 142 | 143 | # mypy 144 | .mypy_cache/ 145 | .dmypy.json 146 | dmypy.json 147 | 148 | # Pyre type checker 149 | .pyre/ 150 | 151 | # pytype static type analyzer 152 | .pytype/ 153 | 154 | # Cython debug symbols 155 | cython_debug/ 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComfyUI_omost 2 | 3 | ComfyUI implementation of [Omost](https://github.com/lllyasviel/Omost), and everything about regional prompt. 4 | 5 | ## News 6 | - [2024-06-10] Add OmostDenseDiffusion regional prompt backend support (The same as original Omost repo) https://github.com/huchenlei/ComfyUI_omost/pull/27 7 | - [2024-06-09] Canvas editor added https://github.com/huchenlei/ComfyUI_omost/pull/28 8 | - [2024-06-09] Add option to connect to external LLM service https://github.com/huchenlei/ComfyUI_omost/pull/25 9 | 10 | ## TODOs 11 | - Add a progress bar to the Chat node 12 | - Implement gradient optimization regional prompt 13 | - Implement multi-diffusion regional prompt 14 | 15 | ## How to use 16 | 17 | As you can see from the screenshot, there are 2 parts of omost: 18 | - LLM Chat 19 | - Region Condition 20 | 21 | ### LLM Chat 22 | LLM Chat allows user interact with LLM to obtain a JSON-like structure. There are 3 nodes in this pack to interact with the Omost LLM: 23 | - `Omost LLM Loader`: Load a LLM 24 | - `Omost LLM Chat`: Chat with LLM to obtain JSON layout prompt 25 | - `Omost Load Canvas Conditioning`: Load the JSON layout prompt previously saved 26 | 27 | Optionally you can use the show-anything node to display the json text and save it for later. 28 | The official LLM's method runs slow. Each chat takes about 3~5min on 4090. (But now we can use TGI to deploy accelerated inference. For details, refer [**Accelerating LLM**](#accelerating-llm).) 29 | 30 | Examples: 31 | - Simple LLM Chat: ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/896eb810-6137-4682-8236-67cfefdbae99) 32 | - Multi-round LLM Chat: ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/fada801a-0116-4b39-8334-b62664dbf153) 33 | 34 | 35 | Here is the a sample JSON output used in the examples: 36 |
37 | Click to expand JSON 38 | 39 | ```json 40 | [ 41 | { 42 | "rect": [ 43 | 0, 44 | 90, 45 | 0, 46 | 90 47 | ], 48 | "prefixes": [ 49 | "An Asian girl sitting on a chair." 50 | ], 51 | "suffixes": [ 52 | "The image depicts an Asian girl sitting gracefully on a chair.", 53 | "She has long, flowing black hair and is wearing a traditional Korean dress, known as a hanbok, which is adorned with intricate floral patterns.", 54 | "Her posture is relaxed yet elegant, with one hand gently resting on her knee and the other hand holding a delicate fan.", 55 | "The background is a simple, neutral-colored room with soft, natural light filtering in from a window.", 56 | "The overall atmosphere is serene and contemplative, capturing a moment of quiet reflection.", 57 | "Asian girl, sitting, chair, traditional dress, hanbok, floral patterns, long black hair, elegant posture, delicate fan, neutral background, natural light, serene atmosphere, contemplative, quiet reflection, simple room, graceful, intricate patterns, flowing hair, cultural attire, traditional Korean dress, relaxed posture." 58 | ], 59 | "color": [ 60 | 211, 61 | 211, 62 | 211 63 | ] 64 | }, 65 | { 66 | "color": [ 67 | 173, 68 | 216, 69 | 230 70 | ], 71 | "rect": [ 72 | 5, 73 | 45, 74 | 0, 75 | 55 76 | ], 77 | "prefixes": [ 78 | "An Asian girl sitting on a chair.", 79 | "Window." 80 | ], 81 | "suffixes": [ 82 | "The window is a simple, rectangular frame with clear glass panes.", 83 | "It allows natural light to filter into the room, casting soft, diffused light over the scene.", 84 | "The window is partially open, with a gentle breeze creating a soft, flowing motion in the curtains.", 85 | "The view outside is blurred, suggesting a peaceful outdoor setting.", 86 | "The window adds a sense of openness and connection to the outside world, enhancing the serene and contemplative atmosphere of the image.", 87 | "window, rectangular frame, clear glass panes, natural light, soft light, diffused light, partially open window, gentle breeze, flowing curtains, blurred view, peaceful outdoor setting, sense of openness, connection to outside, serene atmosphere, contemplative.", 88 | "The window adds a sense of openness and connection to the outside world.", 89 | "The style is simple and natural, with a focus on soft light and gentle breeze.", 90 | "High-quality image with detailed textures and natural lighting." 91 | ] 92 | }, 93 | { 94 | "color": [ 95 | 139, 96 | 69, 97 | 19 98 | ], 99 | "rect": [ 100 | 25, 101 | 85, 102 | 5, 103 | 45 104 | ], 105 | "prefixes": [ 106 | "An Asian girl sitting on a chair.", 107 | "Chair." 108 | ], 109 | "suffixes": [ 110 | "The chair on which the girl is sitting is a simple, elegant wooden chair.", 111 | "It has a smooth, polished finish and a classic design with curved legs and a high backrest.", 112 | "The chair's wood is a rich, dark brown, adding a touch of warmth to the overall scene.", 113 | "The girl sits gracefully on the chair, her posture relaxed yet elegant.", 114 | "The chair complements her traditional Korean dress, enhancing the cultural and elegant atmosphere of the image.", 115 | "chair, wooden chair, elegant design, curved legs, high backrest, polished finish, dark brown wood, warm touch, traditional Korean dress, cultural attire, elegant posture, graceful sitting, classic design, simple chair, rich wood, polished finish.", 116 | "The chair adds a touch of warmth and elegance to the overall scene.", 117 | "The style is classic and simple, with a focus on elegant design and polished finish.", 118 | "High-quality image with detailed textures and natural lighting." 119 | ] 120 | }, 121 | { 122 | "color": [ 123 | 245, 124 | 245, 125 | 220 126 | ], 127 | "rect": [ 128 | 40, 129 | 90, 130 | 40, 131 | 90 132 | ], 133 | "prefixes": [ 134 | "An Asian girl sitting on a chair.", 135 | "Delicate fan." 136 | ], 137 | "suffixes": [ 138 | "The delicate fan held by the girl is a traditional accessory, crafted from fine bamboo with intricate carvings.", 139 | "The fan is adorned with delicate floral designs, adding to its beauty and cultural significance.", 140 | "The girl holds the fan gently, its soft movements enhancing the graceful and elegant atmosphere of the image.", 141 | "The fan is a symbol of refinement and tradition, adding a touch of cultural elegance to the overall scene.", 142 | "delicate fan, traditional accessory, fine bamboo, intricate carvings, floral designs, cultural significance, graceful holding, soft movements, elegant atmosphere, symbol of refinement, cultural elegance, intricate carvings, delicate floral designs, traditional accessory, fine craftsmanship.", 143 | "The delicate fan adds a touch of cultural elegance and refinement to the scene.", 144 | "The style is traditional and refined, with a focus on intricate carvings and delicate designs.", 145 | "High-quality image with detailed textures and natural lighting." 146 | ] 147 | }, 148 | { 149 | "color": [ 150 | 255, 151 | 255, 152 | 240 153 | ], 154 | "rect": [ 155 | 15, 156 | 75, 157 | 15, 158 | 75 159 | ], 160 | "prefixes": [ 161 | "An Asian girl sitting on a chair.", 162 | "Asian girl." 163 | ], 164 | "suffixes": [ 165 | "The Asian girl is the focal point of the image.", 166 | "She is dressed in a traditional Korean hanbok, which is a beautiful garment made from silk and adorned with intricate floral patterns.", 167 | "Her black hair is long and flowing, cascading down her back in soft waves.", 168 | "Her expression is calm and thoughtful, with a slight smile playing on her lips.", 169 | "She sits gracefully on the chair, her posture relaxed yet elegant.", 170 | "One hand rests gently on her knee, while the other hand holds a delicate fan, adding a touch of grace to her appearance.", 171 | "Asian girl, focal point, traditional Korean dress, hanbok, intricate floral patterns, long black hair, flowing hair, calm expression, thoughtful, slight smile, graceful posture, relaxed, elegant, delicate fan, cultural attire.", 172 | "The atmosphere is serene and contemplative, capturing a moment of quiet reflection.", 173 | "The style is elegant and traditional, with a focus on cultural attire and graceful posture.", 174 | "High-quality image with detailed textures and natural lighting." 175 | ] 176 | }, 177 | { 178 | "color": [ 179 | 218, 180 | 165, 181 | 32 182 | ], 183 | "rect": [ 184 | 5, 185 | 65, 186 | 45, 187 | 85 188 | ], 189 | "prefixes": [ 190 | "An Asian girl sitting on a chair.", 191 | "Traditional Korean dress." 192 | ], 193 | "suffixes": [ 194 | "The traditional Korean dress, known as a hanbok, is a beautiful garment made from silk.", 195 | "It is adorned with intricate floral patterns in vibrant colors, including reds, blues, and yellows.", 196 | "The dress is designed to flow gracefully, with delicate folds and soft movements.", 197 | "The girl wears the dress with pride, its cultural significance evident in its elegant design and intricate details.", 198 | "The hanbok complements her graceful posture and adds a touch of cultural elegance to the overall scene.", 199 | "traditional Korean dress, hanbok, beautiful garment, silk fabric, intricate floral patterns, vibrant colors, reds, blues, yellows, graceful flow, delicate folds, soft movements, cultural significance, elegant design, intricate details, graceful posture, cultural elegance.", 200 | "The hanbok adds a touch of cultural elegance and intricate beauty to the scene.", 201 | "The style is traditional and elegant, with a focus on intricate floral patterns and vibrant colors.", 202 | "High-quality image with detailed textures and natural lighting." 203 | ] 204 | } 205 | ] 206 | ``` 207 |
208 | 209 | ### Region condition 210 | According to https://github.com/lllyasviel/Omost#regional-prompter, there are 6 ways to perform region guided diffusion. 211 | 212 | #### Method 1: Multi-diffusion / mixture-of-diffusers 213 | > These method run UNet on different locations, and then merge the estimated epsilon or x0 using weights or masks for different regions. 214 | 215 | TO be implemented 216 | 217 | #### Method 2: Attention decomposition 218 | > lets say attention is like y=softmax(q@k)@v, then one can achieve attention decomposition like y=mask_A * softmax(q@k_A)@v_A + mask_B * softmax(q@k_B)@v_B where mask_A, k_A, v_A are masks, k, v for region A; mask_B, k_B, v_B are masks, k, v for region B. This method usually yields image quality a bit better than (1) and some people call it Attention Couple or Region Prompter Attention Mode. But this method has a consideration: the mask only makes regional attention numerically possible, but it does not force the UNet to really attend its activations in those regions. That is to say, the attention is indeed masked, but there is no promise that the attention softmax will really be activated in the masked area, and there is also no promise that the attention softmax will never be activated outside the masked area. 219 | 220 | This is the built-in regional prompt method in ComfyUI. Use `Omost Layout Cond (ComfyUI-Area)` node for this method. 221 | 222 | There are 2 overlap methods: 223 | - Overlay: The layer on top completely overwrites layer below 224 | - Average: The overlapped area is the average of all conditions 225 | ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/e7d007e4-1175-4435-adf4-a9211937d8c1) 226 | 227 | #### Method 3: Attention score manipulation 228 | > this is a more advanced method compared to (2). It directly manipulates the attention scores to make sure that the activations in mask each area are encouraged and those outside the masks are discouraged. The formulation is like y=softmax(modify(q@k))@v where modify() is a complicated non-linear function with many normalizations and tricks to change the score's distributions. This method goes beyond a simple masked attention to really make sure that those layers get wanted activations. A typical example is Dense Diffusion. 229 | 230 | This is the method used by original Omost repo. To use this method: 231 | - Install https://github.com/huchenlei/ComfyUI_densediffusion 232 | - Include `Omost Layout Cond (OmostDenseDiffusion)` node to your workflow 233 | 234 | Note: ComfyUI_densediffusion does not compose with IPAdapter. 235 | 236 | ![10 06 2024_16 37 22_REC](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/30cf059d-929a-4f11-8f5d-0160d9c5cd22) 237 | 238 | #### Method 4: Gradient optimization 239 | > since the attention can tell us where each part is corresponding to what prompts, we can split prompts into segments and then get attention activations to each prompt segment. Then we compare those activations with external masks to compute a loss function, and back propagate the gradients. Those methods are usually very high quality but VRAM hungry and very slow. Typical methods are BoxDiff and Attend-and-Excite. 240 | 241 | To be implemented 242 | 243 | #### Method 5: Use external control models like gligen and InstanceDiffusion 244 | > Those methods give the highest benchmark performance on region following but will also introduce some style offset to the base model since they are trained parameters. Also, those methods need to convert prompts to vectors and usually do not support prompts of arbitary length (but one can use them together with other attention methods to achieve arbitrary length). 245 | 246 | To be implemented 247 | 248 | #### Method 6: Some more possible layer options like layerdiffuse and mulan 249 | To be implemented 250 | 251 | Optionally you can also pass the image generated from Omost canvas as initial latent as described in the original Omost repo: 252 | ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/f913d141-9045-41fa-998f-770a840adc69) 253 | 254 | ### Edit Region condition 255 | You can use the built-in region editor on `Omost Load Canvas Conditioning` node to freely manipulate the LLM output. 256 | ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/bff0f6d5-ea28-41b2-ae7c-fec29691584f) 257 | ![image](https://github.com/huchenlei/ComfyUI_omost/assets/20929282/eb2a692f-3643-434a-a1d9-4443c82629b8) 258 | 259 | ### Accelerating LLM 260 | 261 | Now you can leverage [TGI](https://huggingface.co/docs/text-generation-inference) to deploy LLM services and achieve up to 6x faster inference speeds. If you need long-term support for your work, this method is highly recommended to save you a lot of time. 262 | 263 | **Preparation**: You will need an additional 20GB of VRAM to deploy an 8B LLM (trading space for time). 264 | 265 | **First**, you can easily start the service using Docker with the following steps: 266 | ``` 267 | port=8080 268 | modelID=lllyasviel/omost-llama-3-8b 269 | memoryRate=0.9 # Normal operation requires 20GB of VRAM, adjust the ratio according to the VRAM of the deployment machine 270 | volume=$HOME/.cache/huggingface/hub # Model cache files 271 | 272 | docker run --gpus all -p $port:80 \ 273 | -v $volume:/data \ 274 | ghcr.io/huggingface/text-generation-inference:2.0.4 \ 275 | --model-id $modelID --max-total-tokens 9216 --cuda-memory-fraction $memoryRate 276 | ``` 277 | Once the service is successfully started, you will see a Connected log message. 278 | 279 | (Note: If you get stuck while downloading the model, try using a network proxy.) 280 | 281 | **Then**, test if the LLM service has successfully started. 282 | ``` 283 | curl 127.0.0.1:8080/generate \ 284 | -X POST \ 285 | -d '{"inputs":"What is Deep Omost?","parameters":{"max_new_tokens":20}}' \ 286 | -H 'Content-Type: application/json' 287 | ``` 288 | 289 | **Next**, add an `Omost LLM HTTP Server` node and enter the service address of the LLM. 290 | ![image](https://github.com/huchenlei/ComfyUI_omost/assets/6883957/8cf1f3a8-f4d7-416c-a1d0-be27bc300c96) 291 | 292 | 293 | For more information about TGI, refer to the official documentation: https://huggingface.co/docs/text-generation-inference/quicktour 294 | 295 | 296 | ### Using llama.cpp HTTP Server 297 | 298 | Utilizing a quantized GGUF model can also lead to significant performance improvements. 299 | 300 | 1. **Download the Model** 301 | 302 | You can download the [omost-llama-3-8b-Q8_0-GGUF](https://huggingface.co/zhaijunxiao/omost-llama-3-8b-Q8_0-GGUF) model here. Alternatively, you can quantize other models yourself using the [GGUF-my-repo](https://huggingface.co/spaces/ggml-org/gguf-my-repo). 303 | 304 | 2. **Start the HTTP Server** 305 | 306 | Clone and compile [llama.cpp](https://github.com/ggerganov/llama.cpp). Then, start the service with the following command: 307 | 308 | ```sh 309 | ./llama-server -m ../model/omost-llama-3-8b-q8_0.gguf -ngl 33 -c 8192 --port 8080 310 | ``` 311 | 312 | Alternatively, you can directly use llama-cpp-python to start an HTTP Server. 313 | 314 | Reference: [llama-cpp-python OpenAI-Compatible Web Server](https://github.com/abetlen/llama-cpp-python?tab=readme-ov-file#openai-compatible-web-server) 315 | 316 | However, in my tests on the 3090Ti, using llama-server directly yields better performance. When generating an image, using llama-cpp-python takes approximately 50-60 seconds, whereas using llama-server takes around 30-40 seconds. 317 | 318 | 319 | 3. **Add a Node** 320 | 321 | Add an `Omost LLM HTTP Server` node and enter the service address of the LLM. 322 | ![image](https://github.com/zhaijunxiao/ComfyUI_omost/assets/40786117/cfbcf41c-e5cd-4b40-b8ec-1a492856abf6) 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from .omost_nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS 2 | 3 | 4 | WEB_DIRECTORY = "js" 5 | 6 | __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"] 7 | -------------------------------------------------------------------------------- /examples/full_compare.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_node_id": 91, 3 | "last_link_id": 147, 4 | "nodes": [ 5 | { 6 | "id": 27, 7 | "type": "VAEDecode", 8 | "pos": [ 9 | 1680, 10 | 1050 11 | ], 12 | "size": { 13 | "0": 210, 14 | "1": 46 15 | }, 16 | "flags": {}, 17 | "order": 13, 18 | "mode": 0, 19 | "inputs": [ 20 | { 21 | "name": "samples", 22 | "type": "LATENT", 23 | "link": 25 24 | }, 25 | { 26 | "name": "vae", 27 | "type": "VAE", 28 | "link": 26, 29 | "slot_index": 1 30 | } 31 | ], 32 | "outputs": [ 33 | { 34 | "name": "IMAGE", 35 | "type": "IMAGE", 36 | "links": [ 37 | 72 38 | ], 39 | "shape": 3, 40 | "slot_index": 0 41 | } 42 | ], 43 | "properties": { 44 | "Node name for S&R": "VAEDecode" 45 | } 46 | }, 47 | { 48 | "id": 47, 49 | "type": "SaveImage", 50 | "pos": [ 51 | 1940, 52 | 1050 53 | ], 54 | "size": { 55 | "0": 513.570068359375, 56 | "1": 555.1339111328125 57 | }, 58 | "flags": {}, 59 | "order": 17, 60 | "mode": 0, 61 | "inputs": [ 62 | { 63 | "name": "images", 64 | "type": "IMAGE", 65 | "link": 72 66 | } 67 | ], 68 | "properties": { 69 | "Node name for S&R": "SaveImage" 70 | }, 71 | "widgets_values": [ 72 | "ComfyUI/omost" 73 | ] 74 | }, 75 | { 76 | "id": 33, 77 | "type": "EmptyLatentImage", 78 | "pos": [ 79 | 804, 80 | 1218 81 | ], 82 | "size": { 83 | "0": 315, 84 | "1": 106 85 | }, 86 | "flags": {}, 87 | "order": 0, 88 | "mode": 0, 89 | "outputs": [ 90 | { 91 | "name": "LATENT", 92 | "type": "LATENT", 93 | "links": [ 94 | 35, 95 | 119, 96 | 131, 97 | 143 98 | ], 99 | "shape": 3, 100 | "slot_index": 0 101 | } 102 | ], 103 | "properties": { 104 | "Node name for S&R": "EmptyLatentImage" 105 | }, 106 | "widgets_values": [ 107 | 1024, 108 | 768, 109 | 1 110 | ] 111 | }, 112 | { 113 | "id": 77, 114 | "type": "VAEDecode", 115 | "pos": [ 116 | 1681, 117 | 439 118 | ], 119 | "size": { 120 | "0": 210, 121 | "1": 46 122 | }, 123 | "flags": {}, 124 | "order": 14, 125 | "mode": 0, 126 | "inputs": [ 127 | { 128 | "name": "samples", 129 | "type": "LATENT", 130 | "link": 120 131 | }, 132 | { 133 | "name": "vae", 134 | "type": "VAE", 135 | "link": 121, 136 | "slot_index": 1 137 | } 138 | ], 139 | "outputs": [ 140 | { 141 | "name": "IMAGE", 142 | "type": "IMAGE", 143 | "links": [ 144 | 122 145 | ], 146 | "shape": 3, 147 | "slot_index": 0 148 | } 149 | ], 150 | "properties": { 151 | "Node name for S&R": "VAEDecode" 152 | } 153 | }, 154 | { 155 | "id": 20, 156 | "type": "CLIPTextEncode", 157 | "pos": [ 158 | 724, 159 | 960 160 | ], 161 | "size": { 162 | "0": 400, 163 | "1": 200 164 | }, 165 | "flags": {}, 166 | "order": 3, 167 | "mode": 0, 168 | "inputs": [ 169 | { 170 | "name": "clip", 171 | "type": "CLIP", 172 | "link": 15 173 | } 174 | ], 175 | "outputs": [ 176 | { 177 | "name": "CONDITIONING", 178 | "type": "CONDITIONING", 179 | "links": [ 180 | 20, 181 | 118, 182 | 130, 183 | 142 184 | ], 185 | "shape": 3, 186 | "slot_index": 0 187 | } 188 | ], 189 | "properties": { 190 | "Node name for S&R": "CLIPTextEncode" 191 | }, 192 | "widgets_values": [ 193 | "lowres, bad anatomy, bad hands, cropped, worst quality" 194 | ] 195 | }, 196 | { 197 | "id": 19, 198 | "type": "CheckpointLoaderSimple", 199 | "pos": [ 200 | 316, 201 | 695 202 | ], 203 | "size": { 204 | "0": 315, 205 | "1": 98 206 | }, 207 | "flags": {}, 208 | "order": 1, 209 | "mode": 0, 210 | "outputs": [ 211 | { 212 | "name": "MODEL", 213 | "type": "MODEL", 214 | "links": [ 215 | 110, 216 | 123, 217 | 128, 218 | 140 219 | ], 220 | "shape": 3, 221 | "slot_index": 0 222 | }, 223 | { 224 | "name": "CLIP", 225 | "type": "CLIP", 226 | "links": [ 227 | 15, 228 | 68, 229 | 115, 230 | 139 231 | ], 232 | "shape": 3, 233 | "slot_index": 1 234 | }, 235 | { 236 | "name": "VAE", 237 | "type": "VAE", 238 | "links": [ 239 | 26, 240 | 121, 241 | 133, 242 | 145 243 | ], 244 | "shape": 3 245 | } 246 | ], 247 | "properties": { 248 | "Node name for S&R": "CheckpointLoaderSimple" 249 | }, 250 | "widgets_values": [ 251 | "animagine-xl-2.0.safetensors" 252 | ] 253 | }, 254 | { 255 | "id": 76, 256 | "type": "KSampler", 257 | "pos": [ 258 | 1310, 259 | 442 260 | ], 261 | "size": { 262 | "0": 315, 263 | "1": 262 264 | }, 265 | "flags": {}, 266 | "order": 10, 267 | "mode": 0, 268 | "inputs": [ 269 | { 270 | "name": "model", 271 | "type": "MODEL", 272 | "link": 124 273 | }, 274 | { 275 | "name": "positive", 276 | "type": "CONDITIONING", 277 | "link": 125 278 | }, 279 | { 280 | "name": "negative", 281 | "type": "CONDITIONING", 282 | "link": 118 283 | }, 284 | { 285 | "name": "latent_image", 286 | "type": "LATENT", 287 | "link": 119 288 | } 289 | ], 290 | "outputs": [ 291 | { 292 | "name": "LATENT", 293 | "type": "LATENT", 294 | "links": [ 295 | 120 296 | ], 297 | "shape": 3, 298 | "slot_index": 0 299 | } 300 | ], 301 | "properties": { 302 | "Node name for S&R": "KSampler" 303 | }, 304 | "widgets_values": [ 305 | 12349, 306 | "fixed", 307 | 20, 308 | 8, 309 | "dpmpp_2m_sde_gpu", 310 | "karras", 311 | 1 312 | ] 313 | }, 314 | { 315 | "id": 82, 316 | "type": "KSampler", 317 | "pos": [ 318 | 1320, 319 | -170 320 | ], 321 | "size": { 322 | "0": 315, 323 | "1": 262 324 | }, 325 | "flags": {}, 326 | "order": 11, 327 | "mode": 0, 328 | "inputs": [ 329 | { 330 | "name": "model", 331 | "type": "MODEL", 332 | "link": 128 333 | }, 334 | { 335 | "name": "positive", 336 | "type": "CONDITIONING", 337 | "link": 135 338 | }, 339 | { 340 | "name": "negative", 341 | "type": "CONDITIONING", 342 | "link": 130 343 | }, 344 | { 345 | "name": "latent_image", 346 | "type": "LATENT", 347 | "link": 131 348 | } 349 | ], 350 | "outputs": [ 351 | { 352 | "name": "LATENT", 353 | "type": "LATENT", 354 | "links": [ 355 | 132 356 | ], 357 | "shape": 3, 358 | "slot_index": 0 359 | } 360 | ], 361 | "properties": { 362 | "Node name for S&R": "KSampler" 363 | }, 364 | "widgets_values": [ 365 | 12349, 366 | "fixed", 367 | 20, 368 | 8, 369 | "dpmpp_2m_sde_gpu", 370 | "karras", 371 | 1 372 | ] 373 | }, 374 | { 375 | "id": 78, 376 | "type": "SaveImage", 377 | "pos": [ 378 | 1940, 379 | 440 380 | ], 381 | "size": { 382 | "0": 513.570068359375, 383 | "1": 555.1339111328125 384 | }, 385 | "flags": {}, 386 | "order": 18, 387 | "mode": 0, 388 | "inputs": [ 389 | { 390 | "name": "images", 391 | "type": "IMAGE", 392 | "link": 122 393 | } 394 | ], 395 | "properties": { 396 | "Node name for S&R": "SaveImage" 397 | }, 398 | "widgets_values": [ 399 | "ComfyUI/omost" 400 | ] 401 | }, 402 | { 403 | "id": 21, 404 | "type": "KSampler", 405 | "pos": [ 406 | 1329, 407 | 1064 408 | ], 409 | "size": { 410 | "0": 315, 411 | "1": 262 412 | }, 413 | "flags": {}, 414 | "order": 9, 415 | "mode": 0, 416 | "inputs": [ 417 | { 418 | "name": "model", 419 | "type": "MODEL", 420 | "link": 110 421 | }, 422 | { 423 | "name": "positive", 424 | "type": "CONDITIONING", 425 | "link": 69 426 | }, 427 | { 428 | "name": "negative", 429 | "type": "CONDITIONING", 430 | "link": 20 431 | }, 432 | { 433 | "name": "latent_image", 434 | "type": "LATENT", 435 | "link": 35 436 | } 437 | ], 438 | "outputs": [ 439 | { 440 | "name": "LATENT", 441 | "type": "LATENT", 442 | "links": [ 443 | 25 444 | ], 445 | "shape": 3, 446 | "slot_index": 0 447 | } 448 | ], 449 | "properties": { 450 | "Node name for S&R": "KSampler" 451 | }, 452 | "widgets_values": [ 453 | 12349, 454 | "fixed", 455 | 20, 456 | 8, 457 | "dpmpp_2m_sde_gpu", 458 | "karras", 459 | 1 460 | ] 461 | }, 462 | { 463 | "id": 35, 464 | "type": "OmostRenderCanvasConditioningNode", 465 | "pos": [ 466 | 1330, 467 | 1410 468 | ], 469 | "size": { 470 | "0": 271.7767639160156, 471 | "1": 46 472 | }, 473 | "flags": {}, 474 | "order": 4, 475 | "mode": 0, 476 | "inputs": [ 477 | { 478 | "name": "canvas_conds", 479 | "type": "OMOST_CANVAS_CONDITIONING", 480 | "link": 57, 481 | "slot_index": 0 482 | } 483 | ], 484 | "outputs": [ 485 | { 486 | "name": "IMAGE", 487 | "type": "IMAGE", 488 | "links": [ 489 | 41 490 | ], 491 | "shape": 3, 492 | "slot_index": 0 493 | }, 494 | { 495 | "name": "MASK", 496 | "type": "MASK", 497 | "links": null, 498 | "shape": 3 499 | } 500 | ], 501 | "properties": { 502 | "Node name for S&R": "OmostRenderCanvasConditioningNode" 503 | }, 504 | "color": "#232", 505 | "bgcolor": "#353" 506 | }, 507 | { 508 | "id": 83, 509 | "type": "VAEDecode", 510 | "pos": [ 511 | 1680, 512 | -169 513 | ], 514 | "size": { 515 | "0": 210, 516 | "1": 46 517 | }, 518 | "flags": {}, 519 | "order": 15, 520 | "mode": 0, 521 | "inputs": [ 522 | { 523 | "name": "samples", 524 | "type": "LATENT", 525 | "link": 132 526 | }, 527 | { 528 | "name": "vae", 529 | "type": "VAE", 530 | "link": 133, 531 | "slot_index": 1 532 | } 533 | ], 534 | "outputs": [ 535 | { 536 | "name": "IMAGE", 537 | "type": "IMAGE", 538 | "links": [ 539 | 134 540 | ], 541 | "shape": 3, 542 | "slot_index": 0 543 | } 544 | ], 545 | "properties": { 546 | "Node name for S&R": "VAEDecode" 547 | } 548 | }, 549 | { 550 | "id": 84, 551 | "type": "SaveImage", 552 | "pos": [ 553 | 1938, 554 | -172 555 | ], 556 | "size": { 557 | "0": 513.570068359375, 558 | "1": 555.1339111328125 559 | }, 560 | "flags": {}, 561 | "order": 19, 562 | "mode": 0, 563 | "inputs": [ 564 | { 565 | "name": "images", 566 | "type": "IMAGE", 567 | "link": 134 568 | } 569 | ], 570 | "properties": { 571 | "Node name for S&R": "SaveImage" 572 | }, 573 | "widgets_values": [ 574 | "ComfyUI/omost" 575 | ] 576 | }, 577 | { 578 | "id": 44, 579 | "type": "OmostLayoutCondNode", 580 | "pos": [ 581 | 787, 582 | 756 583 | ], 584 | "size": { 585 | "0": 330.0874938964844, 586 | "1": 147.511962890625 587 | }, 588 | "flags": {}, 589 | "order": 5, 590 | "mode": 0, 591 | "inputs": [ 592 | { 593 | "name": "canvas_conds", 594 | "type": "OMOST_CANVAS_CONDITIONING", 595 | "link": 67 596 | }, 597 | { 598 | "name": "clip", 599 | "type": "CLIP", 600 | "link": 68 601 | }, 602 | { 603 | "name": "positive", 604 | "type": "CONDITIONING", 605 | "link": null 606 | } 607 | ], 608 | "outputs": [ 609 | { 610 | "name": "CONDITIONING", 611 | "type": "CONDITIONING", 612 | "links": [ 613 | 69 614 | ], 615 | "shape": 3 616 | }, 617 | { 618 | "name": "MASK", 619 | "type": "MASK", 620 | "links": [], 621 | "shape": 3, 622 | "slot_index": 1 623 | } 624 | ], 625 | "properties": { 626 | "Node name for S&R": "OmostLayoutCondNode" 627 | }, 628 | "widgets_values": [ 629 | 0.18, 630 | 0.74, 631 | "average" 632 | ], 633 | "color": "#332922", 634 | "bgcolor": "#593930" 635 | }, 636 | { 637 | "id": 36, 638 | "type": "PreviewImage", 639 | "pos": [ 640 | 1655, 641 | 1411 642 | ], 643 | "size": { 644 | "0": 210, 645 | "1": 246 646 | }, 647 | "flags": { 648 | "collapsed": false 649 | }, 650 | "order": 8, 651 | "mode": 0, 652 | "inputs": [ 653 | { 654 | "name": "images", 655 | "type": "IMAGE", 656 | "link": 41 657 | } 658 | ], 659 | "properties": { 660 | "Node name for S&R": "PreviewImage" 661 | } 662 | }, 663 | { 664 | "id": 32, 665 | "type": "OmostLoadCanvasConditioningNode", 666 | "pos": [ 667 | 670, 668 | 1410 669 | ], 670 | "size": { 671 | "0": 605.3375854492188, 672 | "1": 525.603271484375 673 | }, 674 | "flags": {}, 675 | "order": 2, 676 | "mode": 0, 677 | "outputs": [ 678 | { 679 | "name": "OMOST_CANVAS_CONDITIONING", 680 | "type": "OMOST_CANVAS_CONDITIONING", 681 | "links": [ 682 | 57, 683 | 67, 684 | 113, 685 | 138 686 | ], 687 | "shape": 3, 688 | "slot_index": 0 689 | } 690 | ], 691 | "properties": { 692 | "Node name for S&R": "OmostLoadCanvasConditioningNode" 693 | }, 694 | "widgets_values": [ 695 | "[{\"rect\":[0,90,0,90],\"prefixes\":[\"An Asian girl sitting on a chair.\"],\"suffixes\":[\"The image depicts an Asian girl sitting gracefully on a chair.\",\"She has long, flowing black hair and is wearing a traditional Korean dress, known as a hanbok, which is adorned with intricate floral patterns.\",\"Her posture is relaxed yet elegant, with one hand gently resting on her knee and the other hand holding a delicate fan.\",\"The background is a simple, neutral-colored room with soft, natural light filtering in from a window.\",\"The overall atmosphere is serene and contemplative, capturing a moment of quiet reflection.\",\"Asian girl, sitting, chair, traditional dress, hanbok, floral patterns, long black hair, elegant posture, delicate fan, neutral background, natural light, serene atmosphere, contemplative, quiet reflection, simple room, graceful, intricate patterns, flowing hair, cultural attire, traditional Korean dress, relaxed posture.\"],\"color\":[211,211,211]},{\"color\":[167,202,214],\"rect\":[5,45,35,90],\"prefixes\":[\"An Asian girl sitting on a chair.\",\"Window.\"],\"suffixes\":[\"The window is a simple, rectangular frame with clear glass panes.\",\"It allows natural light to filter into the room, casting soft, diffused light over the scene.\",\"The window is partially open, with a gentle breeze creating a soft, flowing motion in the curtains.\",\"The view outside is blurred, suggesting a peaceful outdoor setting.\",\"The window adds a sense of openness and connection to the outside world, enhancing the serene and contemplative atmosphere of the image.\",\"window, rectangular frame, clear glass panes, natural light, soft light, diffused light, partially open window, gentle breeze, flowing curtains, blurred view, peaceful outdoor setting, sense of openness, connection to outside, serene atmosphere, contemplative.\",\"The window adds a sense of openness and connection to the outside world.\",\"The style is simple and natural, with a focus on soft light and gentle breeze.\",\"High-quality image with detailed textures and natural lighting.\"]},{\"color\":[255,255,240],\"rect\":[25,85,5,65],\"prefixes\":[\"An Asian girl sitting on a chair.\",\"Asian girl.\"],\"suffixes\":[\"The Asian girl is the focal point of the image.\",\"She is dressed in a traditional Korean hanbok, which is a beautiful garment made from silk and adorned with intricate floral patterns.\",\"Her black hair is long and flowing, cascading down her back in soft waves.\",\"Her expression is calm and thoughtful, with a slight smile playing on her lips.\",\"She sits gracefully on the chair, her posture relaxed yet elegant.\",\"One hand rests gently on her knee, while the other hand holds a delicate fan, adding a touch of grace to her appearance.\",\"Asian girl, focal point, traditional Korean dress, hanbok, intricate floral patterns, long black hair, flowing hair, calm expression, thoughtful, slight smile, graceful posture, relaxed, elegant, delicate fan, cultural attire.\",\"The atmosphere is serene and contemplative, capturing a moment of quiet reflection.\",\"The style is elegant and traditional, with a focus on cultural attire and graceful posture.\",\"High-quality image with detailed textures and natural lighting.\"]}]" 696 | ], 697 | "color": "#232", 698 | "bgcolor": "#353" 699 | }, 700 | { 701 | "id": 90, 702 | "type": "VAEDecode", 703 | "pos": [ 704 | 1680, 705 | -780 706 | ], 707 | "size": { 708 | "0": 210, 709 | "1": 46 710 | }, 711 | "flags": {}, 712 | "order": 16, 713 | "mode": 0, 714 | "inputs": [ 715 | { 716 | "name": "samples", 717 | "type": "LATENT", 718 | "link": 144 719 | }, 720 | { 721 | "name": "vae", 722 | "type": "VAE", 723 | "link": 145, 724 | "slot_index": 1 725 | } 726 | ], 727 | "outputs": [ 728 | { 729 | "name": "IMAGE", 730 | "type": "IMAGE", 731 | "links": [ 732 | 146 733 | ], 734 | "shape": 3, 735 | "slot_index": 0 736 | } 737 | ], 738 | "properties": { 739 | "Node name for S&R": "VAEDecode" 740 | } 741 | }, 742 | { 743 | "id": 91, 744 | "type": "SaveImage", 745 | "pos": [ 746 | 1940, 747 | -790 748 | ], 749 | "size": { 750 | "0": 513.570068359375, 751 | "1": 555.1339111328125 752 | }, 753 | "flags": {}, 754 | "order": 20, 755 | "mode": 0, 756 | "inputs": [ 757 | { 758 | "name": "images", 759 | "type": "IMAGE", 760 | "link": 146 761 | } 762 | ], 763 | "properties": { 764 | "Node name for S&R": "SaveImage" 765 | }, 766 | "widgets_values": [ 767 | "ComfyUI/omost" 768 | ] 769 | }, 770 | { 771 | "id": 89, 772 | "type": "KSampler", 773 | "pos": [ 774 | 1320, 775 | -780 776 | ], 777 | "size": { 778 | "0": 315, 779 | "1": 262 780 | }, 781 | "flags": {}, 782 | "order": 12, 783 | "mode": 0, 784 | "inputs": [ 785 | { 786 | "name": "model", 787 | "type": "MODEL", 788 | "link": 140 789 | }, 790 | { 791 | "name": "positive", 792 | "type": "CONDITIONING", 793 | "link": 147 794 | }, 795 | { 796 | "name": "negative", 797 | "type": "CONDITIONING", 798 | "link": 142 799 | }, 800 | { 801 | "name": "latent_image", 802 | "type": "LATENT", 803 | "link": 143 804 | } 805 | ], 806 | "outputs": [ 807 | { 808 | "name": "LATENT", 809 | "type": "LATENT", 810 | "links": [ 811 | 144 812 | ], 813 | "shape": 3, 814 | "slot_index": 0 815 | } 816 | ], 817 | "properties": { 818 | "Node name for S&R": "KSampler" 819 | }, 820 | "widgets_values": [ 821 | 12349, 822 | "fixed", 823 | 20, 824 | 8, 825 | "dpmpp_2m_sde_gpu", 826 | "karras", 827 | 1 828 | ] 829 | }, 830 | { 831 | "id": 88, 832 | "type": "OmostGreedyBagsTextEmbeddingNode", 833 | "pos": [ 834 | 853, 835 | -766 836 | ], 837 | "size": { 838 | "0": 336.2585754394531, 839 | "1": 52.690181732177734 840 | }, 841 | "flags": {}, 842 | "order": 7, 843 | "mode": 0, 844 | "inputs": [ 845 | { 846 | "name": "canvas_conds", 847 | "type": "OMOST_CANVAS_CONDITIONING", 848 | "link": 138 849 | }, 850 | { 851 | "name": "clip", 852 | "type": "CLIP", 853 | "link": 139, 854 | "slot_index": 1 855 | } 856 | ], 857 | "outputs": [ 858 | { 859 | "name": "CONDITIONING", 860 | "type": "CONDITIONING", 861 | "links": [ 862 | 147 863 | ], 864 | "shape": 3, 865 | "slot_index": 0 866 | } 867 | ], 868 | "properties": { 869 | "Node name for S&R": "OmostGreedyBagsTextEmbeddingNode" 870 | }, 871 | "color": "#223", 872 | "bgcolor": "#335" 873 | }, 874 | { 875 | "id": 74, 876 | "type": "OmostDenseDiffusionLayoutNode", 877 | "pos": [ 878 | 802, 879 | 444 880 | ], 881 | "size": { 882 | "0": 327.6000061035156, 883 | "1": 66 884 | }, 885 | "flags": {}, 886 | "order": 6, 887 | "mode": 0, 888 | "inputs": [ 889 | { 890 | "name": "model", 891 | "type": "MODEL", 892 | "link": 123, 893 | "slot_index": 0 894 | }, 895 | { 896 | "name": "canvas_conds", 897 | "type": "OMOST_CANVAS_CONDITIONING", 898 | "link": 113, 899 | "slot_index": 1 900 | }, 901 | { 902 | "name": "clip", 903 | "type": "CLIP", 904 | "link": 115, 905 | "slot_index": 2 906 | } 907 | ], 908 | "outputs": [ 909 | { 910 | "name": "MODEL", 911 | "type": "MODEL", 912 | "links": [ 913 | 124 914 | ], 915 | "shape": 3, 916 | "slot_index": 0 917 | }, 918 | { 919 | "name": "CONDITIONING", 920 | "type": "CONDITIONING", 921 | "links": [ 922 | 125, 923 | 135 924 | ], 925 | "shape": 3, 926 | "slot_index": 1 927 | } 928 | ], 929 | "properties": { 930 | "Node name for S&R": "OmostDenseDiffusionLayoutNode" 931 | }, 932 | "color": "#322", 933 | "bgcolor": "#533" 934 | } 935 | ], 936 | "links": [ 937 | [ 938 | 15, 939 | 19, 940 | 1, 941 | 20, 942 | 0, 943 | "CLIP" 944 | ], 945 | [ 946 | 20, 947 | 20, 948 | 0, 949 | 21, 950 | 2, 951 | "CONDITIONING" 952 | ], 953 | [ 954 | 25, 955 | 21, 956 | 0, 957 | 27, 958 | 0, 959 | "LATENT" 960 | ], 961 | [ 962 | 26, 963 | 19, 964 | 2, 965 | 27, 966 | 1, 967 | "VAE" 968 | ], 969 | [ 970 | 35, 971 | 33, 972 | 0, 973 | 21, 974 | 3, 975 | "LATENT" 976 | ], 977 | [ 978 | 41, 979 | 35, 980 | 0, 981 | 36, 982 | 0, 983 | "IMAGE" 984 | ], 985 | [ 986 | 57, 987 | 32, 988 | 0, 989 | 35, 990 | 0, 991 | "OMOST_CANVAS_CONDITIONING" 992 | ], 993 | [ 994 | 67, 995 | 32, 996 | 0, 997 | 44, 998 | 0, 999 | "OMOST_CANVAS_CONDITIONING" 1000 | ], 1001 | [ 1002 | 68, 1003 | 19, 1004 | 1, 1005 | 44, 1006 | 1, 1007 | "CLIP" 1008 | ], 1009 | [ 1010 | 69, 1011 | 44, 1012 | 0, 1013 | 21, 1014 | 1, 1015 | "CONDITIONING" 1016 | ], 1017 | [ 1018 | 72, 1019 | 27, 1020 | 0, 1021 | 47, 1022 | 0, 1023 | "IMAGE" 1024 | ], 1025 | [ 1026 | 110, 1027 | 19, 1028 | 0, 1029 | 21, 1030 | 0, 1031 | "MODEL" 1032 | ], 1033 | [ 1034 | 113, 1035 | 32, 1036 | 0, 1037 | 74, 1038 | 1, 1039 | "OMOST_CANVAS_CONDITIONING" 1040 | ], 1041 | [ 1042 | 115, 1043 | 19, 1044 | 1, 1045 | 74, 1046 | 2, 1047 | "CLIP" 1048 | ], 1049 | [ 1050 | 118, 1051 | 20, 1052 | 0, 1053 | 76, 1054 | 2, 1055 | "CONDITIONING" 1056 | ], 1057 | [ 1058 | 119, 1059 | 33, 1060 | 0, 1061 | 76, 1062 | 3, 1063 | "LATENT" 1064 | ], 1065 | [ 1066 | 120, 1067 | 76, 1068 | 0, 1069 | 77, 1070 | 0, 1071 | "LATENT" 1072 | ], 1073 | [ 1074 | 121, 1075 | 19, 1076 | 2, 1077 | 77, 1078 | 1, 1079 | "VAE" 1080 | ], 1081 | [ 1082 | 122, 1083 | 77, 1084 | 0, 1085 | 78, 1086 | 0, 1087 | "IMAGE" 1088 | ], 1089 | [ 1090 | 123, 1091 | 19, 1092 | 0, 1093 | 74, 1094 | 0, 1095 | "MODEL" 1096 | ], 1097 | [ 1098 | 124, 1099 | 74, 1100 | 0, 1101 | 76, 1102 | 0, 1103 | "MODEL" 1104 | ], 1105 | [ 1106 | 125, 1107 | 74, 1108 | 1, 1109 | 76, 1110 | 1, 1111 | "CONDITIONING" 1112 | ], 1113 | [ 1114 | 128, 1115 | 19, 1116 | 0, 1117 | 82, 1118 | 0, 1119 | "MODEL" 1120 | ], 1121 | [ 1122 | 130, 1123 | 20, 1124 | 0, 1125 | 82, 1126 | 2, 1127 | "CONDITIONING" 1128 | ], 1129 | [ 1130 | 131, 1131 | 33, 1132 | 0, 1133 | 82, 1134 | 3, 1135 | "LATENT" 1136 | ], 1137 | [ 1138 | 132, 1139 | 82, 1140 | 0, 1141 | 83, 1142 | 0, 1143 | "LATENT" 1144 | ], 1145 | [ 1146 | 133, 1147 | 19, 1148 | 2, 1149 | 83, 1150 | 1, 1151 | "VAE" 1152 | ], 1153 | [ 1154 | 134, 1155 | 83, 1156 | 0, 1157 | 84, 1158 | 0, 1159 | "IMAGE" 1160 | ], 1161 | [ 1162 | 135, 1163 | 74, 1164 | 1, 1165 | 82, 1166 | 1, 1167 | "CONDITIONING" 1168 | ], 1169 | [ 1170 | 138, 1171 | 32, 1172 | 0, 1173 | 88, 1174 | 0, 1175 | "OMOST_CANVAS_CONDITIONING" 1176 | ], 1177 | [ 1178 | 139, 1179 | 19, 1180 | 1, 1181 | 88, 1182 | 1, 1183 | "CLIP" 1184 | ], 1185 | [ 1186 | 140, 1187 | 19, 1188 | 0, 1189 | 89, 1190 | 0, 1191 | "MODEL" 1192 | ], 1193 | [ 1194 | 142, 1195 | 20, 1196 | 0, 1197 | 89, 1198 | 2, 1199 | "CONDITIONING" 1200 | ], 1201 | [ 1202 | 143, 1203 | 33, 1204 | 0, 1205 | 89, 1206 | 3, 1207 | "LATENT" 1208 | ], 1209 | [ 1210 | 144, 1211 | 89, 1212 | 0, 1213 | 90, 1214 | 0, 1215 | "LATENT" 1216 | ], 1217 | [ 1218 | 145, 1219 | 19, 1220 | 2, 1221 | 90, 1222 | 1, 1223 | "VAE" 1224 | ], 1225 | [ 1226 | 146, 1227 | 90, 1228 | 0, 1229 | 91, 1230 | 0, 1231 | "IMAGE" 1232 | ], 1233 | [ 1234 | 147, 1235 | 88, 1236 | 0, 1237 | 89, 1238 | 1, 1239 | "CONDITIONING" 1240 | ] 1241 | ], 1242 | "groups": [], 1243 | "config": {}, 1244 | "extra": { 1245 | "ds": { 1246 | "scale": 0.573085533011682, 1247 | "offset": [ 1248 | 954.0055989051052, 1249 | 447.9687976808276 1250 | ] 1251 | }, 1252 | "info": { 1253 | "name": "workflow", 1254 | "author": "", 1255 | "description": "", 1256 | "version": "1", 1257 | "created": "2024-06-03T15:41:46.655Z", 1258 | "modified": "2024-06-11T14:25:32.525Z", 1259 | "software": "ComfyUI" 1260 | } 1261 | }, 1262 | "version": 0.4 1263 | } -------------------------------------------------------------------------------- /examples/omost_ipa.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_node_id": 73, 3 | "last_link_id": 108, 4 | "nodes": [ 5 | { 6 | "id": 27, 7 | "type": "VAEDecode", 8 | "pos": [ 9 | 1600, 10 | 748 11 | ], 12 | "size": { 13 | "0": 210, 14 | "1": 46 15 | }, 16 | "flags": {}, 17 | "order": 18, 18 | "mode": 0, 19 | "inputs": [ 20 | { 21 | "name": "samples", 22 | "type": "LATENT", 23 | "link": 25 24 | }, 25 | { 26 | "name": "vae", 27 | "type": "VAE", 28 | "link": 26, 29 | "slot_index": 1 30 | } 31 | ], 32 | "outputs": [ 33 | { 34 | "name": "IMAGE", 35 | "type": "IMAGE", 36 | "links": [ 37 | 72 38 | ], 39 | "shape": 3, 40 | "slot_index": 0 41 | } 42 | ], 43 | "properties": { 44 | "Node name for S&R": "VAEDecode" 45 | } 46 | }, 47 | { 48 | "id": 21, 49 | "type": "KSampler", 50 | "pos": [ 51 | 1235, 52 | 756 53 | ], 54 | "size": { 55 | "0": 315, 56 | "1": 262 57 | }, 58 | "flags": {}, 59 | "order": 17, 60 | "mode": 0, 61 | "inputs": [ 62 | { 63 | "name": "model", 64 | "type": "MODEL", 65 | "link": 105 66 | }, 67 | { 68 | "name": "positive", 69 | "type": "CONDITIONING", 70 | "link": 69 71 | }, 72 | { 73 | "name": "negative", 74 | "type": "CONDITIONING", 75 | "link": 20 76 | }, 77 | { 78 | "name": "latent_image", 79 | "type": "LATENT", 80 | "link": 35 81 | } 82 | ], 83 | "outputs": [ 84 | { 85 | "name": "LATENT", 86 | "type": "LATENT", 87 | "links": [ 88 | 25 89 | ], 90 | "shape": 3, 91 | "slot_index": 0 92 | } 93 | ], 94 | "properties": { 95 | "Node name for S&R": "KSampler" 96 | }, 97 | "widgets_values": [ 98 | 12348, 99 | "fixed", 100 | 35, 101 | 8, 102 | "dpmpp_2m_sde_gpu", 103 | "karras", 104 | 1 105 | ] 106 | }, 107 | { 108 | "id": 46, 109 | "type": "PreviewImage", 110 | "pos": [ 111 | 1260, 112 | 1168 113 | ], 114 | "size": { 115 | "0": 262.6606140136719, 116 | "1": 336.4308166503906 117 | }, 118 | "flags": {}, 119 | "order": 10, 120 | "mode": 0, 121 | "inputs": [ 122 | { 123 | "name": "images", 124 | "type": "IMAGE", 125 | "link": 96 126 | } 127 | ], 128 | "properties": { 129 | "Node name for S&R": "PreviewImage" 130 | } 131 | }, 132 | { 133 | "id": 45, 134 | "type": "MaskToImage", 135 | "pos": [ 136 | 1240, 137 | 1076 138 | ], 139 | "size": { 140 | "0": 306.97039794921875, 141 | "1": 32.845237731933594 142 | }, 143 | "flags": {}, 144 | "order": 9, 145 | "mode": 0, 146 | "inputs": [ 147 | { 148 | "name": "mask", 149 | "type": "MASK", 150 | "link": 70 151 | } 152 | ], 153 | "outputs": [ 154 | { 155 | "name": "IMAGE", 156 | "type": "IMAGE", 157 | "links": [ 158 | 96, 159 | 97 160 | ], 161 | "shape": 3, 162 | "slot_index": 0 163 | } 164 | ], 165 | "properties": { 166 | "Node name for S&R": "MaskToImage" 167 | } 168 | }, 169 | { 170 | "id": 20, 171 | "type": "CLIPTextEncode", 172 | "pos": [ 173 | 754, 174 | 958 175 | ], 176 | "size": { 177 | "0": 400, 178 | "1": 200 179 | }, 180 | "flags": {}, 181 | "order": 5, 182 | "mode": 0, 183 | "inputs": [ 184 | { 185 | "name": "clip", 186 | "type": "CLIP", 187 | "link": 15 188 | } 189 | ], 190 | "outputs": [ 191 | { 192 | "name": "CONDITIONING", 193 | "type": "CONDITIONING", 194 | "links": [ 195 | 20 196 | ], 197 | "shape": 3, 198 | "slot_index": 0 199 | } 200 | ], 201 | "properties": { 202 | "Node name for S&R": "CLIPTextEncode" 203 | }, 204 | "widgets_values": [ 205 | "lowres, bad anatomy, bad hands, cropped, worst quality" 206 | ] 207 | }, 208 | { 209 | "id": 33, 210 | "type": "EmptyLatentImage", 211 | "pos": [ 212 | 804, 213 | 1218 214 | ], 215 | "size": { 216 | "0": 315, 217 | "1": 106 218 | }, 219 | "flags": {}, 220 | "order": 0, 221 | "mode": 0, 222 | "outputs": [ 223 | { 224 | "name": "LATENT", 225 | "type": "LATENT", 226 | "links": [ 227 | 35 228 | ], 229 | "shape": 3, 230 | "slot_index": 0 231 | } 232 | ], 233 | "properties": { 234 | "Node name for S&R": "EmptyLatentImage" 235 | }, 236 | "widgets_values": [ 237 | 1024, 238 | 1024, 239 | 1 240 | ] 241 | }, 242 | { 243 | "id": 65, 244 | "type": "ImageFromBatch+", 245 | "pos": [ 246 | 1245, 247 | 1570 248 | ], 249 | "size": { 250 | "0": 315, 251 | "1": 82 252 | }, 253 | "flags": {}, 254 | "order": 11, 255 | "mode": 0, 256 | "inputs": [ 257 | { 258 | "name": "image", 259 | "type": "IMAGE", 260 | "link": 97 261 | } 262 | ], 263 | "outputs": [ 264 | { 265 | "name": "IMAGE", 266 | "type": "IMAGE", 267 | "links": [ 268 | 99 269 | ], 270 | "shape": 3, 271 | "slot_index": 0 272 | } 273 | ], 274 | "properties": { 275 | "Node name for S&R": "ImageFromBatch+" 276 | }, 277 | "widgets_values": [ 278 | 4, 279 | 1 280 | ] 281 | }, 282 | { 283 | "id": 68, 284 | "type": "ImageToMask", 285 | "pos": [ 286 | 1589, 287 | 1567 288 | ], 289 | "size": { 290 | "0": 315, 291 | "1": 58 292 | }, 293 | "flags": {}, 294 | "order": 12, 295 | "mode": 0, 296 | "inputs": [ 297 | { 298 | "name": "image", 299 | "type": "IMAGE", 300 | "link": 99 301 | } 302 | ], 303 | "outputs": [ 304 | { 305 | "name": "MASK", 306 | "type": "MASK", 307 | "links": [ 308 | 100 309 | ], 310 | "shape": 3, 311 | "slot_index": 0 312 | } 313 | ], 314 | "properties": { 315 | "Node name for S&R": "ImageToMask" 316 | }, 317 | "widgets_values": [ 318 | "red" 319 | ] 320 | }, 321 | { 322 | "id": 67, 323 | "type": "ToBinaryMask", 324 | "pos": [ 325 | 1928, 326 | 1570 327 | ], 328 | "size": { 329 | "0": 315, 330 | "1": 58 331 | }, 332 | "flags": {}, 333 | "order": 13, 334 | "mode": 0, 335 | "inputs": [ 336 | { 337 | "name": "mask", 338 | "type": "MASK", 339 | "link": 100 340 | } 341 | ], 342 | "outputs": [ 343 | { 344 | "name": "MASK", 345 | "type": "MASK", 346 | "links": [ 347 | 101, 348 | 107 349 | ], 350 | "shape": 3, 351 | "slot_index": 0 352 | } 353 | ], 354 | "properties": { 355 | "Node name for S&R": "ToBinaryMask" 356 | }, 357 | "widgets_values": [ 358 | 1 359 | ] 360 | }, 361 | { 362 | "id": 69, 363 | "type": "MaskToImage", 364 | "pos": [ 365 | 1963, 366 | 1673 367 | ], 368 | "size": { 369 | "0": 210, 370 | "1": 26 371 | }, 372 | "flags": {}, 373 | "order": 14, 374 | "mode": 0, 375 | "inputs": [ 376 | { 377 | "name": "mask", 378 | "type": "MASK", 379 | "link": 101 380 | } 381 | ], 382 | "outputs": [ 383 | { 384 | "name": "IMAGE", 385 | "type": "IMAGE", 386 | "links": [ 387 | 102 388 | ], 389 | "shape": 3, 390 | "slot_index": 0 391 | } 392 | ], 393 | "properties": { 394 | "Node name for S&R": "MaskToImage" 395 | } 396 | }, 397 | { 398 | "id": 66, 399 | "type": "PreviewImage", 400 | "pos": [ 401 | 1969, 402 | 1750 403 | ], 404 | "size": { 405 | "0": 210, 406 | "1": 246 407 | }, 408 | "flags": {}, 409 | "order": 16, 410 | "mode": 0, 411 | "inputs": [ 412 | { 413 | "name": "images", 414 | "type": "IMAGE", 415 | "link": 102 416 | } 417 | ], 418 | "properties": { 419 | "Node name for S&R": "PreviewImage" 420 | } 421 | }, 422 | { 423 | "id": 19, 424 | "type": "CheckpointLoaderSimple", 425 | "pos": [ 426 | 316, 427 | 695 428 | ], 429 | "size": { 430 | "0": 315, 431 | "1": 98 432 | }, 433 | "flags": {}, 434 | "order": 1, 435 | "mode": 0, 436 | "outputs": [ 437 | { 438 | "name": "MODEL", 439 | "type": "MODEL", 440 | "links": [ 441 | 103 442 | ], 443 | "shape": 3, 444 | "slot_index": 0 445 | }, 446 | { 447 | "name": "CLIP", 448 | "type": "CLIP", 449 | "links": [ 450 | 15, 451 | 68 452 | ], 453 | "shape": 3, 454 | "slot_index": 1 455 | }, 456 | { 457 | "name": "VAE", 458 | "type": "VAE", 459 | "links": [ 460 | 26 461 | ], 462 | "shape": 3 463 | } 464 | ], 465 | "properties": { 466 | "Node name for S&R": "CheckpointLoaderSimple" 467 | }, 468 | "widgets_values": [ 469 | "animagine-xl-2.0.safetensors" 470 | ] 471 | }, 472 | { 473 | "id": 73, 474 | "type": "LoadImage", 475 | "pos": [ 476 | 835, 477 | 17 478 | ], 479 | "size": { 480 | "0": 315, 481 | "1": 314 482 | }, 483 | "flags": {}, 484 | "order": 2, 485 | "mode": 0, 486 | "outputs": [ 487 | { 488 | "name": "IMAGE", 489 | "type": "IMAGE", 490 | "links": [ 491 | 108 492 | ], 493 | "shape": 3, 494 | "slot_index": 0 495 | }, 496 | { 497 | "name": "MASK", 498 | "type": "MASK", 499 | "links": null, 500 | "shape": 3 501 | } 502 | ], 503 | "properties": { 504 | "Node name for S&R": "LoadImage" 505 | }, 506 | "widgets_values": [ 507 | "35877b78-8568-4242-8d87-9c9f3f69c238 (5).jpeg", 508 | "image" 509 | ] 510 | }, 511 | { 512 | "id": 70, 513 | "type": "IPAdapter", 514 | "pos": [ 515 | 1218, 516 | 393 517 | ], 518 | "size": { 519 | "0": 315, 520 | "1": 190 521 | }, 522 | "flags": {}, 523 | "order": 15, 524 | "mode": 0, 525 | "inputs": [ 526 | { 527 | "name": "model", 528 | "type": "MODEL", 529 | "link": 104 530 | }, 531 | { 532 | "name": "ipadapter", 533 | "type": "IPADAPTER", 534 | "link": 106 535 | }, 536 | { 537 | "name": "image", 538 | "type": "IMAGE", 539 | "link": 108 540 | }, 541 | { 542 | "name": "attn_mask", 543 | "type": "MASK", 544 | "link": 107, 545 | "slot_index": 3 546 | } 547 | ], 548 | "outputs": [ 549 | { 550 | "name": "MODEL", 551 | "type": "MODEL", 552 | "links": [ 553 | 105 554 | ], 555 | "shape": 3, 556 | "slot_index": 0 557 | } 558 | ], 559 | "properties": { 560 | "Node name for S&R": "IPAdapter" 561 | }, 562 | "widgets_values": [ 563 | 1, 564 | 0, 565 | 1, 566 | "standard" 567 | ] 568 | }, 569 | { 570 | "id": 72, 571 | "type": "IPAdapterUnifiedLoader", 572 | "pos": [ 573 | 839, 574 | 392 575 | ], 576 | "size": { 577 | "0": 315, 578 | "1": 78 579 | }, 580 | "flags": {}, 581 | "order": 4, 582 | "mode": 0, 583 | "inputs": [ 584 | { 585 | "name": "model", 586 | "type": "MODEL", 587 | "link": 103 588 | }, 589 | { 590 | "name": "ipadapter", 591 | "type": "IPADAPTER", 592 | "link": null 593 | } 594 | ], 595 | "outputs": [ 596 | { 597 | "name": "model", 598 | "type": "MODEL", 599 | "links": [ 600 | 104 601 | ], 602 | "shape": 3, 603 | "slot_index": 0 604 | }, 605 | { 606 | "name": "ipadapter", 607 | "type": "IPADAPTER", 608 | "links": [ 609 | 106 610 | ], 611 | "shape": 3, 612 | "slot_index": 1 613 | } 614 | ], 615 | "properties": { 616 | "Node name for S&R": "IPAdapterUnifiedLoader" 617 | }, 618 | "widgets_values": [ 619 | "STANDARD (medium strength)" 620 | ] 621 | }, 622 | { 623 | "id": 36, 624 | "type": "PreviewImage", 625 | "pos": [ 626 | 900, 627 | 1460 628 | ], 629 | "size": { 630 | "0": 210, 631 | "1": 246 632 | }, 633 | "flags": { 634 | "collapsed": false 635 | }, 636 | "order": 8, 637 | "mode": 0, 638 | "inputs": [ 639 | { 640 | "name": "images", 641 | "type": "IMAGE", 642 | "link": 41 643 | } 644 | ], 645 | "properties": { 646 | "Node name for S&R": "PreviewImage" 647 | } 648 | }, 649 | { 650 | "id": 47, 651 | "type": "SaveImage", 652 | "pos": [ 653 | 1861, 654 | 746 655 | ], 656 | "size": { 657 | "0": 513.570068359375, 658 | "1": 555.1339111328125 659 | }, 660 | "flags": {}, 661 | "order": 19, 662 | "mode": 0, 663 | "inputs": [ 664 | { 665 | "name": "images", 666 | "type": "IMAGE", 667 | "link": 72 668 | } 669 | ], 670 | "properties": { 671 | "Node name for S&R": "SaveImage" 672 | }, 673 | "widgets_values": [ 674 | "ComfyUI/omost" 675 | ] 676 | }, 677 | { 678 | "id": 44, 679 | "type": "OmostLayoutCondNode", 680 | "pos": [ 681 | 787, 682 | 756 683 | ], 684 | "size": { 685 | "0": 330.0874938964844, 686 | "1": 147.511962890625 687 | }, 688 | "flags": {}, 689 | "order": 7, 690 | "mode": 0, 691 | "inputs": [ 692 | { 693 | "name": "canvas_conds", 694 | "type": "OMOST_CANVAS_CONDITIONING", 695 | "link": 67 696 | }, 697 | { 698 | "name": "clip", 699 | "type": "CLIP", 700 | "link": 68 701 | }, 702 | { 703 | "name": "positive", 704 | "type": "CONDITIONING", 705 | "link": null 706 | } 707 | ], 708 | "outputs": [ 709 | { 710 | "name": "CONDITIONING", 711 | "type": "CONDITIONING", 712 | "links": [ 713 | 69 714 | ], 715 | "shape": 3 716 | }, 717 | { 718 | "name": "MASK", 719 | "type": "MASK", 720 | "links": [ 721 | 70 722 | ], 723 | "shape": 3, 724 | "slot_index": 1 725 | } 726 | ], 727 | "properties": { 728 | "Node name for S&R": "OmostLayoutCondNode" 729 | }, 730 | "widgets_values": [ 731 | 0.18, 732 | 0.74, 733 | "average" 734 | ], 735 | "color": "#232", 736 | "bgcolor": "#353" 737 | }, 738 | { 739 | "id": 32, 740 | "type": "OmostLoadCanvasConditioningNode", 741 | "pos": [ 742 | 11, 743 | 853 744 | ], 745 | "size": { 746 | "0": 605.3375854492188, 747 | "1": 525.603271484375 748 | }, 749 | "flags": {}, 750 | "order": 3, 751 | "mode": 0, 752 | "outputs": [ 753 | { 754 | "name": "OMOST_CANVAS_CONDITIONING", 755 | "type": "OMOST_CANVAS_CONDITIONING", 756 | "links": [ 757 | 57, 758 | 67 759 | ], 760 | "shape": 3, 761 | "slot_index": 0 762 | } 763 | ], 764 | "properties": { 765 | "Node name for S&R": "OmostLoadCanvasConditioningNode" 766 | }, 767 | "widgets_values": [ 768 | "[{\"rect\": [0, 90, 0, 90], \"prefixes\": [\"An Asian girl sitting on a chair.\"], \"suffixes\": [\"The image depicts an Asian girl sitting gracefully on a chair.\", \"She has long, flowing black hair and is wearing a traditional Korean dress, known as a hanbok, which is adorned with intricate floral patterns.\", \"Her posture is relaxed yet elegant, with one hand gently resting on her knee and the other hand holding a delicate fan.\", \"The background is a simple, neutral-colored room with soft, natural light filtering in from a window.\", \"The overall atmosphere is serene and contemplative, capturing a moment of quiet reflection.\", \"Asian girl, sitting, chair, traditional dress, hanbok, floral patterns, long black hair, elegant posture, delicate fan, neutral background, natural light, serene atmosphere, contemplative, quiet reflection, simple room, graceful, intricate patterns, flowing hair, cultural attire, traditional Korean dress, relaxed posture.\"], \"color\": [211, 211, 211]}, {\"color\": [173, 216, 230], \"rect\": [5, 45, 0, 55], \"prefixes\": [\"An Asian girl sitting on a chair.\", \"Window.\"], \"suffixes\": [\"The window is a simple, rectangular frame with clear glass panes.\", \"It allows natural light to filter into the room, casting soft, diffused light over the scene.\", \"The window is partially open, with a gentle breeze creating a soft, flowing motion in the curtains.\", \"The view outside is blurred, suggesting a peaceful outdoor setting.\", \"The window adds a sense of openness and connection to the outside world, enhancing the serene and contemplative atmosphere of the image.\", \"window, rectangular frame, clear glass panes, natural light, soft light, diffused light, partially open window, gentle breeze, flowing curtains, blurred view, peaceful outdoor setting, sense of openness, connection to outside, serene atmosphere, contemplative.\", \"The window adds a sense of openness and connection to the outside world.\", \"The style is simple and natural, with a focus on soft light and gentle breeze.\", \"High-quality image with detailed textures and natural lighting.\"]}, {\"color\": [139, 69, 19], \"rect\": [25, 85, 5, 45], \"prefixes\": [\"An Asian girl sitting on a chair.\", \"Chair.\"], \"suffixes\": [\"The chair on which the girl is sitting is a simple, elegant wooden chair.\", \"It has a smooth, polished finish and a classic design with curved legs and a high backrest.\", \"The chair's wood is a rich, dark brown, adding a touch of warmth to the overall scene.\", \"The girl sits gracefully on the chair, her posture relaxed yet elegant.\", \"The chair complements her traditional Korean dress, enhancing the cultural and elegant atmosphere of the image.\", \"chair, wooden chair, elegant design, curved legs, high backrest, polished finish, dark brown wood, warm touch, traditional Korean dress, cultural attire, elegant posture, graceful sitting, classic design, simple chair, rich wood, polished finish.\", \"The chair adds a touch of warmth and elegance to the overall scene.\", \"The style is classic and simple, with a focus on elegant design and polished finish.\", \"High-quality image with detailed textures and natural lighting.\"]}, {\"color\": [245, 245, 220], \"rect\": [40, 90, 40, 90], \"prefixes\": [\"An Asian girl sitting on a chair.\", \"Delicate fan.\"], \"suffixes\": [\"The delicate fan held by the girl is a traditional accessory, crafted from fine bamboo with intricate carvings.\", \"The fan is adorned with delicate floral designs, adding to its beauty and cultural significance.\", \"The girl holds the fan gently, its soft movements enhancing the graceful and elegant atmosphere of the image.\", \"The fan is a symbol of refinement and tradition, adding a touch of cultural elegance to the overall scene.\", \"delicate fan, traditional accessory, fine bamboo, intricate carvings, floral designs, cultural significance, graceful holding, soft movements, elegant atmosphere, symbol of refinement, cultural elegance, intricate carvings, delicate floral designs, traditional accessory, fine craftsmanship.\", \"The delicate fan adds a touch of cultural elegance and refinement to the scene.\", \"The style is traditional and refined, with a focus on intricate carvings and delicate designs.\", \"High-quality image with detailed textures and natural lighting.\"]}, {\"color\": [255, 255, 240], \"rect\": [15, 75, 15, 75], \"prefixes\": [\"An Asian girl sitting on a chair.\", \"Asian girl.\"], \"suffixes\": [\"The Asian girl is the focal point of the image.\", \"She is dressed in a traditional Korean hanbok, which is a beautiful garment made from silk and adorned with intricate floral patterns.\", \"Her black hair is long and flowing, cascading down her back in soft waves.\", \"Her expression is calm and thoughtful, with a slight smile playing on her lips.\", \"She sits gracefully on the chair, her posture relaxed yet elegant.\", \"One hand rests gently on her knee, while the other hand holds a delicate fan, adding a touch of grace to her appearance.\", \"Asian girl, focal point, traditional Korean dress, hanbok, intricate floral patterns, long black hair, flowing hair, calm expression, thoughtful, slight smile, graceful posture, relaxed, elegant, delicate fan, cultural attire.\", \"The atmosphere is serene and contemplative, capturing a moment of quiet reflection.\", \"The style is elegant and traditional, with a focus on cultural attire and graceful posture.\", \"High-quality image with detailed textures and natural lighting.\"]}, {\"color\": [218, 165, 32], \"rect\": [5, 65, 45, 85], \"prefixes\": [\"An Asian girl sitting on a chair.\", \"Traditional Korean dress.\"], \"suffixes\": [\"The traditional Korean dress, known as a hanbok, is a beautiful garment made from silk.\", \"It is adorned with intricate floral patterns in vibrant colors, including reds, blues, and yellows.\", \"The dress is designed to flow gracefully, with delicate folds and soft movements.\", \"The girl wears the dress with pride, its cultural significance evident in its elegant design and intricate details.\", \"The hanbok complements her graceful posture and adds a touch of cultural elegance to the overall scene.\", \"traditional Korean dress, hanbok, beautiful garment, silk fabric, intricate floral patterns, vibrant colors, reds, blues, yellows, graceful flow, delicate folds, soft movements, cultural significance, elegant design, intricate details, graceful posture, cultural elegance.\", \"The hanbok adds a touch of cultural elegance and intricate beauty to the scene.\", \"The style is traditional and elegant, with a focus on intricate floral patterns and vibrant colors.\", \"High-quality image with detailed textures and natural lighting.\"]}]" 769 | ], 770 | "color": "#232", 771 | "bgcolor": "#353" 772 | }, 773 | { 774 | "id": 35, 775 | "type": "OmostRenderCanvasConditioningNode", 776 | "pos": [ 777 | 600, 778 | 1460 779 | ], 780 | "size": { 781 | "0": 271.7767639160156, 782 | "1": 46 783 | }, 784 | "flags": {}, 785 | "order": 6, 786 | "mode": 0, 787 | "inputs": [ 788 | { 789 | "name": "canvas_conds", 790 | "type": "OMOST_CANVAS_CONDITIONING", 791 | "link": 57, 792 | "slot_index": 0 793 | } 794 | ], 795 | "outputs": [ 796 | { 797 | "name": "IMAGE", 798 | "type": "IMAGE", 799 | "links": [ 800 | 41 801 | ], 802 | "shape": 3, 803 | "slot_index": 0 804 | }, 805 | { 806 | "name": "MASK", 807 | "type": "MASK", 808 | "links": null, 809 | "shape": 3 810 | } 811 | ], 812 | "properties": { 813 | "Node name for S&R": "OmostRenderCanvasConditioningNode" 814 | } 815 | } 816 | ], 817 | "links": [ 818 | [ 819 | 15, 820 | 19, 821 | 1, 822 | 20, 823 | 0, 824 | "CLIP" 825 | ], 826 | [ 827 | 20, 828 | 20, 829 | 0, 830 | 21, 831 | 2, 832 | "CONDITIONING" 833 | ], 834 | [ 835 | 25, 836 | 21, 837 | 0, 838 | 27, 839 | 0, 840 | "LATENT" 841 | ], 842 | [ 843 | 26, 844 | 19, 845 | 2, 846 | 27, 847 | 1, 848 | "VAE" 849 | ], 850 | [ 851 | 35, 852 | 33, 853 | 0, 854 | 21, 855 | 3, 856 | "LATENT" 857 | ], 858 | [ 859 | 41, 860 | 35, 861 | 0, 862 | 36, 863 | 0, 864 | "IMAGE" 865 | ], 866 | [ 867 | 57, 868 | 32, 869 | 0, 870 | 35, 871 | 0, 872 | "OMOST_CANVAS_CONDITIONING" 873 | ], 874 | [ 875 | 67, 876 | 32, 877 | 0, 878 | 44, 879 | 0, 880 | "OMOST_CANVAS_CONDITIONING" 881 | ], 882 | [ 883 | 68, 884 | 19, 885 | 1, 886 | 44, 887 | 1, 888 | "CLIP" 889 | ], 890 | [ 891 | 69, 892 | 44, 893 | 0, 894 | 21, 895 | 1, 896 | "CONDITIONING" 897 | ], 898 | [ 899 | 70, 900 | 44, 901 | 1, 902 | 45, 903 | 0, 904 | "MASK" 905 | ], 906 | [ 907 | 72, 908 | 27, 909 | 0, 910 | 47, 911 | 0, 912 | "IMAGE" 913 | ], 914 | [ 915 | 96, 916 | 45, 917 | 0, 918 | 46, 919 | 0, 920 | "IMAGE" 921 | ], 922 | [ 923 | 97, 924 | 45, 925 | 0, 926 | 65, 927 | 0, 928 | "IMAGE" 929 | ], 930 | [ 931 | 99, 932 | 65, 933 | 0, 934 | 68, 935 | 0, 936 | "IMAGE" 937 | ], 938 | [ 939 | 100, 940 | 68, 941 | 0, 942 | 67, 943 | 0, 944 | "MASK" 945 | ], 946 | [ 947 | 101, 948 | 67, 949 | 0, 950 | 69, 951 | 0, 952 | "MASK" 953 | ], 954 | [ 955 | 102, 956 | 69, 957 | 0, 958 | 66, 959 | 0, 960 | "IMAGE" 961 | ], 962 | [ 963 | 103, 964 | 19, 965 | 0, 966 | 72, 967 | 0, 968 | "MODEL" 969 | ], 970 | [ 971 | 104, 972 | 72, 973 | 0, 974 | 70, 975 | 0, 976 | "MODEL" 977 | ], 978 | [ 979 | 105, 980 | 70, 981 | 0, 982 | 21, 983 | 0, 984 | "MODEL" 985 | ], 986 | [ 987 | 106, 988 | 72, 989 | 1, 990 | 70, 991 | 1, 992 | "IPADAPTER" 993 | ], 994 | [ 995 | 107, 996 | 67, 997 | 0, 998 | 70, 999 | 3, 1000 | "MASK" 1001 | ], 1002 | [ 1003 | 108, 1004 | 73, 1005 | 0, 1006 | 70, 1007 | 2, 1008 | "IMAGE" 1009 | ] 1010 | ], 1011 | "groups": [], 1012 | "config": {}, 1013 | "extra": { 1014 | "ds": { 1015 | "scale": 0.5730855330116845, 1016 | "offset": [ 1017 | 848.0209102622539, 1018 | 163.70301716121608 1019 | ] 1020 | }, 1021 | "info": { 1022 | "name": "workflow", 1023 | "author": "", 1024 | "description": "", 1025 | "version": "1", 1026 | "created": "2024-06-03T15:41:46.655Z", 1027 | "modified": "2024-06-11T14:25:09.646Z", 1028 | "software": "ComfyUI" 1029 | } 1030 | }, 1031 | "version": 0.4 1032 | } -------------------------------------------------------------------------------- /examples/omost_llm.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_node_id": 26, 3 | "last_link_id": 30, 4 | "nodes": [ 5 | { 6 | "id": 10, 7 | "type": "OmostLLMLoaderNode", 8 | "pos": [ 9 | 71, 10 | 107 11 | ], 12 | "size": { 13 | "0": 315, 14 | "1": 58 15 | }, 16 | "flags": {}, 17 | "order": 0, 18 | "mode": 0, 19 | "outputs": [ 20 | { 21 | "name": "OMOST_LLM", 22 | "type": "OMOST_LLM", 23 | "links": [ 24 | 26, 25 | 28 26 | ], 27 | "shape": 3, 28 | "slot_index": 0 29 | } 30 | ], 31 | "properties": { 32 | "Node name for S&R": "OmostLLMLoaderNode" 33 | }, 34 | "widgets_values": [ 35 | "lllyasviel/omost-llama-3-8b-4bits" 36 | ] 37 | }, 38 | { 39 | "id": 25, 40 | "type": "OmostLLMChatNode", 41 | "pos": [ 42 | 490, 43 | 110 44 | ], 45 | "size": { 46 | "0": 400, 47 | "1": 216 48 | }, 49 | "flags": {}, 50 | "order": 1, 51 | "mode": 0, 52 | "inputs": [ 53 | { 54 | "name": "llm", 55 | "type": "OMOST_LLM", 56 | "link": 26 57 | }, 58 | { 59 | "name": "conversation", 60 | "type": "OMOST_CONVERSATION", 61 | "link": null 62 | } 63 | ], 64 | "outputs": [ 65 | { 66 | "name": "OMOST_CONVERSATION", 67 | "type": "OMOST_CONVERSATION", 68 | "links": [ 69 | 27 70 | ], 71 | "shape": 3, 72 | "slot_index": 0 73 | }, 74 | { 75 | "name": "OMOST_CANVAS_CONDITIONING", 76 | "type": "OMOST_CANVAS_CONDITIONING", 77 | "links": [ 78 | 29 79 | ], 80 | "shape": 3 81 | } 82 | ], 83 | "properties": { 84 | "Node name for S&R": "OmostLLMChatNode" 85 | }, 86 | "widgets_values": [ 87 | "generate an image of the fierce battle of warriors and a dragon", 88 | 4096, 89 | 0.9, 90 | 0.6, 91 | 492549861980888, 92 | "fixed" 93 | ] 94 | }, 95 | { 96 | "id": 23, 97 | "type": "easy showAnything", 98 | "pos": [ 99 | 982, 100 | 112 101 | ], 102 | "size": { 103 | "0": 385.9798278808594, 104 | "1": 208.11888122558594 105 | }, 106 | "flags": {}, 107 | "order": 3, 108 | "mode": 0, 109 | "inputs": [ 110 | { 111 | "name": "anything", 112 | "type": "*", 113 | "link": 29, 114 | "slot_index": 0 115 | } 116 | ], 117 | "properties": { 118 | "Node name for S&R": "easy showAnything" 119 | }, 120 | "widgets_values": [ 121 | "[{\"rect\": [0, 90, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dragon.\"], \"suffixes\": [\"In this image, we witness a dramatic and intense battle between brave warriors and a menacing dragon.\", \"The warriors, clad in medieval armor, are fighting valiantly with their swords and shields.\", \"They are positioned strategically around the battlefield, showcasing their bravery and skill.\", \"The dragon, a massive and fearsome creature with scales glinting in the sunlight, breathes fire that illuminates the darkening sky.\", \"Its wings are spread wide, creating a sense of chaos and destruction.\", \"The ground is littered with fallen warriors and debris, adding to the grim atmosphere of the scene.\", \"The sky is darkening, with clouds of smoke and ash swirling above.\", \"The overall mood is one of intense conflict and high stakes, as the warriors fight for their lives and the dragon seeks to dominate the land.\", \"battle, warriors, dragon, medieval armor, swords, shields, fire-breathing, chaos, destruction, fallen warriors, debris, darkening sky, clouds, smoke, ash, intense conflict, high stakes, bravery, skill, grim atmosphere.\"], \"color\": [47, 79, 79]}, {\"color\": [72, 61, 139], \"rect\": [0, 45, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dragon.\", \"The darkening sky.\"], \"suffixes\": [\"The sky above the battlefield is darkening, filled with clouds of smoke and ash swirling above.\", \"The sun is setting, casting a dramatic and intense light over the scene.\", \"The clouds are thick and ominous, adding to the grim and chaotic atmosphere of the battle.\", \"The darkening sky contrasts sharply with the fiery flames of the dragon, creating a dramatic and intense visual element.\", \"The overall mood of the sky is one of impending doom and high stakes, as if the fate of the warriors hangs in the balance.\", \"darkening sky, clouds, smoke, ash, swirling, sun setting, dramatic light, intense, thick clouds, ominous, grim atmosphere, chaotic, fiery flames, contrast, dramatic, visual element, impending doom, high stakes, fate, warriors.\", \"A sense of impending doom and high stakes fills the air.\", \"Dramatic and intense, with a focus on the contrast between the sky and the flames.\", \"High-quality rendering with dramatic lighting and intense visual elements.\"]}, {\"color\": [178, 34, 34], \"rect\": [10, 80, 10, 80], \"prefixes\": [\"A fierce battle between warriors and a dragon.\", \"The fierce dragon.\"], \"suffixes\": [\"The dragon is the focal point of this image, a massive creature with scales that glint in the sunlight.\", \"Its body is covered in intricate patterns of dark and light scales, giving it a fearsome appearance.\", \"The dragon's wings are spread wide, revealing their immense size and power.\", \"Its eyes are fierce and glowing, exuding a sense of malevolence and strength.\", \"As it breathes fire, the flames illuminate the darkening sky and add a dramatic and intense element to the scene.\", \"The ground around the dragon is scorched and charred, showing the devastating power of its fire.\", \"dragon, massive creature, scales, sunlight, wings, power, fierce eyes, glowing, malevolence, strength, fire-breathing, flames, darkening sky, dramatic, intense, scorched ground, charred.\", \"A sense of chaos and destruction fills the air.\", \"Dramatic and intense, with a focus on the dragon\\u2019s fearsome appearance.\", \"High-quality rendering with intricate details and dramatic lighting.\"]}, {\"color\": [105, 105, 105], \"rect\": [5, 85, 0, 40], \"prefixes\": [\"A fierce battle between warriors and a dragon.\", \"A group of brave warriors.\"], \"suffixes\": [\"A group of brave warriors is positioned on the left side of the image, clad in medieval armor.\", \"They are engaged in the battle, wielding swords and shields with great skill and bravery.\", \"The armor they wear is detailed and realistic, showcasing the craftsmanship of the era.\", \"Their faces are set in determined expressions, and their movements are fluid and coordinated, indicating their experience and training.\", \"Some warriors are fallen, lying on the ground with their weapons still clutched in their hands.\", \"The ground around them is littered with debris and fallen warriors, adding to the grim and intense atmosphere of the scene.\", \"warriors, brave, medieval armor, battle, swords, shields, skill, bravery, detailed armor, realistic, craftsmanship, determined expressions, fluid movements, experience, training, fallen warriors, debris, grim atmosphere.\", \"A sense of bravery and determination fills the air.\", \"Realistic and detailed, with a focus on the craftsmanship of the armor.\", \"High-quality rendering with detailed and realistic armor and expressions.\"]}, {\"color\": [105, 105, 105], \"rect\": [5, 85, 50, 90], \"prefixes\": [\"A fierce battle between warriors and a dragon.\", \"Another group of warriors.\"], \"suffixes\": [\"On the right side of the image, another group of warriors is engaged in the battle.\", \"They are also clad in medieval armor and are fighting valiantly with their weapons.\", \"The armor they wear is equally detailed and realistic, showcasing the same level of craftsmanship.\", \"Their movements are coordinated, and their expressions are determined, showing their bravery and skill.\", \"Some warriors are fallen, lying on the ground with their weapons still clutched in their hands.\", \"The ground around them is littered with debris and fallen warriors, adding to the grim and intense atmosphere of the scene.\", \"warriors, brave, medieval armor, battle, swords, shields, skill, bravery, detailed armor, realistic, craftsmanship, determined expressions, fluid movements, experience, training, fallen warriors, debris, grim atmosphere.\", \"A sense of bravery and determination fills the air.\", \"Realistic and detailed, with a focus on the craftsmanship of the armor.\", \"High-quality rendering with detailed and realistic armor and expressions.\"]}, {\"color\": [0, 0, 0], \"rect\": [45, 90, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dragon.\", \"The scorched and charred ground.\"], \"suffixes\": [\"The ground of the battlefield is scorched and charred, showing the devastating power of the dragon\\u2019s fire.\", \"Debris and fallen warriors litter the area, adding to the grim and intense atmosphere of the scene.\", \"The scorched earth is blackened and cracked, with patches of grass and vegetation still burning.\", \"The ground tells a story of destruction and chaos, as the remnants of the battle are scattered around.\", \"The overall mood of the ground is one of devastation and destruction, as if the land itself has been torn apart by the conflict.\", \"scorched ground, charred, dragon\\u2019s fire, debris, fallen warriors, grim atmosphere, intense, scorched earth, blackened, cracked, grass, vegetation, burning, destruction, chaos, battle remnants, devastation, conflict.\", \"A sense of devastation and destruction fills the air.\", \"Grim and intense, with a focus on the scorched and charred ground.\", \"High-quality rendering with detailed and realistic scorched earth and debris.\"]}]" 122 | ] 123 | }, 124 | { 125 | "id": 19, 126 | "type": "easy showAnything", 127 | "pos": [ 128 | 984, 129 | 395 130 | ], 131 | "size": { 132 | "0": 403.86956787109375, 133 | "1": 215.21694946289062 134 | }, 135 | "flags": {}, 136 | "order": 4, 137 | "mode": 0, 138 | "inputs": [ 139 | { 140 | "name": "anything", 141 | "type": "*", 142 | "link": 30, 143 | "slot_index": 0 144 | } 145 | ], 146 | "properties": { 147 | "Node name for S&R": "easy showAnything" 148 | }, 149 | "widgets_values": [ 150 | "[{\"rect\": [0, 90, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\"], \"suffixes\": [\"In this image, we witness a dramatic and intense battle between brave warriors and a menacing dinosaur.\", \"The warriors, clad in medieval armor, are fighting valiantly with their swords and shields.\", \"They are positioned strategically around the battlefield, showcasing their bravery and skill.\", \"The dinosaur, a massive and fearsome creature with scales glinting in the sunlight, charges forward with powerful movements.\", \"Its body is covered in intricate patterns of dark and light scales, giving it a fearsome appearance.\", \"The ground is littered with fallen warriors and debris, adding to the grim atmosphere of the scene.\", \"The sky is darkening, with clouds of smoke and ash swirling above.\", \"The overall mood is one of intense conflict and high stakes, as the warriors fight for their lives and the dinosaur seeks to dominate the land.\", \"battle, warriors, dinosaur, medieval armor, swords, shields, powerful movements, chaos, destruction, fallen warriors, debris, darkening sky, clouds, smoke, ash, intense conflict, high stakes, bravery, skill, grim atmosphere.\"], \"color\": [47, 79, 79]}, {\"color\": [72, 61, 139], \"rect\": [0, 45, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\", \"The darkening sky.\"], \"suffixes\": [\"The sky above the battlefield is darkening, filled with clouds of smoke and ash swirling above.\", \"The sun is setting, casting a dramatic and intense light over the scene.\", \"The clouds are thick and ominous, adding to the grim and chaotic atmosphere of the battle.\", \"The darkening sky contrasts sharply with the powerful movements of the dinosaur, creating a dramatic and intense visual element.\", \"The overall mood of the sky is one of impending doom and high stakes, as if the fate of the warriors hangs in the balance.\", \"darkening sky, clouds, smoke, ash, swirling, sun setting, dramatic light, intense, thick clouds, ominous, grim atmosphere, chaotic, powerful movements, contrast, dramatic, visual element, impending doom, high stakes, fate, warriors.\", \"A sense of impending doom and high stakes fills the air.\", \"Dramatic and intense, with a focus on the contrast between the sky and the powerful movements of the dinosaur.\", \"High-quality rendering with dramatic lighting and intense visual elements.\"]}, {\"color\": [178, 34, 34], \"rect\": [10, 80, 10, 80], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\", \"The fierce dinosaur.\"], \"suffixes\": [\"The dinosaur is the focal point of this image, a massive creature with scales that glint in the sunlight.\", \"Its body is covered in intricate patterns of dark and light scales, giving it a fearsome appearance.\", \"The dinosaur is charging forward with powerful movements, revealing its immense size and power.\", \"Its eyes are fierce and glowing, exuding a sense of malevolence and strength.\", \"As it moves, the ground around it is scorched and charred, showing the devastating power of its movements.\", \"dinosaur, massive creature, scales, sunlight, powerful movements, power, fierce eyes, glowing, malevolence, strength, charging, dramatic, intense, scorched ground, charred.\", \"A sense of chaos and destruction fills the air.\", \"Dramatic and intense, with a focus on the dinosaur\\u2019s fearsome appearance.\", \"High-quality rendering with intricate details and dramatic lighting.\"]}, {\"color\": [105, 105, 105], \"rect\": [5, 85, 0, 40], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\", \"A group of brave warriors.\"], \"suffixes\": [\"A group of brave warriors is positioned on the left side of the image, clad in medieval armor.\", \"They are engaged in the battle, wielding swords and shields with great skill and bravery.\", \"The armor they wear is detailed and realistic, showcasing the craftsmanship of the era.\", \"Their faces are set in determined expressions, and their movements are fluid and coordinated, indicating their experience and training.\", \"Some warriors are fallen, lying on the ground with their weapons still clutched in their hands.\", \"The ground around them is littered with debris and fallen warriors, adding to the grim and intense atmosphere of the scene.\", \"warriors, brave, medieval armor, battle, swords, shields, skill, bravery, detailed armor, realistic, craftsmanship, determined expressions, fluid movements, experience, training, fallen warriors, debris, grim atmosphere.\", \"A sense of bravery and determination fills the air.\", \"Realistic and detailed, with a focus on the craftsmanship of the armor.\", \"High-quality rendering with detailed and realistic armor and expressions.\"]}, {\"color\": [105, 105, 105], \"rect\": [5, 85, 50, 90], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\", \"Another group of warriors.\"], \"suffixes\": [\"On the right side of the image, another group of warriors is engaged in the battle.\", \"They are also clad in medieval armor and are fighting valiantly with their weapons.\", \"The armor they wear is equally detailed and realistic, showcasing the same level of craftsmanship.\", \"Their movements are coordinated, and their expressions are determined, showing their bravery and skill.\", \"Some warriors are fallen, lying on the ground with their weapons still clutched in their hands.\", \"The ground around them is littered with debris and fallen warriors, adding to the grim and intense atmosphere of the scene.\", \"warriors, brave, medieval armor, battle, swords, shields, skill, bravery, detailed armor, realistic, craftsmanship, determined expressions, fluid movements, experience, training, fallen warriors, debris, grim atmosphere.\", \"A sense of bravery and determination fills the air.\", \"Realistic and detailed, with a focus on the craftsmanship of the armor.\", \"High-quality rendering with detailed and realistic armor and expressions.\"]}, {\"color\": [0, 0, 0], \"rect\": [45, 90, 0, 90], \"prefixes\": [\"A fierce battle between warriors and a dinosaur.\", \"The scorched and charred ground.\"], \"suffixes\": [\"The ground of the battlefield is scorched and charred, showing the devastating power of the dinosaur\\u2019s movements.\", \"Debris and fallen warriors litter the area, adding to the grim and intense atmosphere of the scene.\", \"The scorched earth is blackened and cracked, with patches of grass and vegetation still burning.\", \"The ground tells a story of destruction and chaos, as the remnants of the battle are scattered around.\", \"The overall mood of the ground is one of devastation and destruction, as if the land itself has been torn apart by the conflict.\", \"scorched ground, charred, dinosaur\\u2019s movements, debris, fallen warriors, grim atmosphere, intense, scorched earth, blackened, cracked, grass, vegetation, burning, destruction, chaos, battle remnants, devastation, conflict.\", \"A sense of devastation and destruction fills the air.\", \"Grim and intense, with a focus on the scorched and charred ground.\", \"High-quality rendering with detailed and realistic scorched earth and debris.\"]}]" 151 | ] 152 | }, 153 | { 154 | "id": 26, 155 | "type": "OmostLLMChatNode", 156 | "pos": [ 157 | 489, 158 | 393 159 | ], 160 | "size": { 161 | "0": 400, 162 | "1": 216 163 | }, 164 | "flags": {}, 165 | "order": 2, 166 | "mode": 0, 167 | "inputs": [ 168 | { 169 | "name": "llm", 170 | "type": "OMOST_LLM", 171 | "link": 28, 172 | "slot_index": 0 173 | }, 174 | { 175 | "name": "conversation", 176 | "type": "OMOST_CONVERSATION", 177 | "link": 27 178 | } 179 | ], 180 | "outputs": [ 181 | { 182 | "name": "OMOST_CONVERSATION", 183 | "type": "OMOST_CONVERSATION", 184 | "links": null, 185 | "shape": 3 186 | }, 187 | { 188 | "name": "OMOST_CANVAS_CONDITIONING", 189 | "type": "OMOST_CANVAS_CONDITIONING", 190 | "links": [ 191 | 30 192 | ], 193 | "shape": 3 194 | } 195 | ], 196 | "properties": { 197 | "Node name for S&R": "OmostLLMChatNode" 198 | }, 199 | "widgets_values": [ 200 | "change the dragon to a dinosaur", 201 | 4096, 202 | 0.9, 203 | 0.6, 204 | 911366815263218, 205 | "randomize" 206 | ] 207 | } 208 | ], 209 | "links": [ 210 | [ 211 | 26, 212 | 10, 213 | 0, 214 | 25, 215 | 0, 216 | "OMOST_LLM" 217 | ], 218 | [ 219 | 27, 220 | 25, 221 | 0, 222 | 26, 223 | 1, 224 | "OMOST_CONVERSATION" 225 | ], 226 | [ 227 | 28, 228 | 10, 229 | 0, 230 | 26, 231 | 0, 232 | "OMOST_LLM" 233 | ], 234 | [ 235 | 29, 236 | 25, 237 | 1, 238 | 23, 239 | 0, 240 | "*" 241 | ], 242 | [ 243 | 30, 244 | 26, 245 | 1, 246 | 19, 247 | 0, 248 | "*" 249 | ] 250 | ], 251 | "groups": [], 252 | "config": {}, 253 | "extra": { 254 | "ds": { 255 | "scale": 1.464100000000001, 256 | "offset": [ 257 | 74.65755379746918, 258 | 157.3509957359641 259 | ] 260 | }, 261 | "info": { 262 | "name": "workflow", 263 | "author": "", 264 | "description": "", 265 | "version": "1", 266 | "created": "2024-06-03T15:41:46.655Z", 267 | "modified": "2024-06-05T14:17:07.712Z", 268 | "software": "ComfyUI" 269 | } 270 | }, 271 | "version": 0.4 272 | } -------------------------------------------------------------------------------- /js/omost_canvas_editor_index.js: -------------------------------------------------------------------------------- 1 | import { app } from "../../scripts/app.js"; 2 | import { ComfyDialog, $el } from "../../scripts/ui.js"; 3 | import { ComfyApp } from "../../scripts/app.js"; 4 | 5 | 6 | function addMenuHandler(nodeType, cb) { 7 | const getOpts = nodeType.prototype.getExtraMenuOptions; 8 | nodeType.prototype.getExtraMenuOptions = function () { 9 | const r = getOpts.apply(this, arguments); 10 | cb.apply(this, arguments); 11 | return r; 12 | }; 13 | } 14 | 15 | class OmostCanvasDialog extends ComfyDialog { 16 | static timeout = 5000; 17 | static instance = null; 18 | 19 | static getInstance() { 20 | if (!OmostCanvasDialog.instance) { 21 | OmostCanvasDialog.instance = new OmostCanvasDialog(); 22 | } 23 | 24 | return OmostCanvasDialog.instance; 25 | } 26 | 27 | constructor() { 28 | super(); 29 | this.element = $el("div.comfy-modal", { 30 | parent: document.body, 31 | style: { 32 | width: "80vw", 33 | height: "80vh", 34 | }, 35 | }, [ 36 | $el("div.comfy-modal-content", { 37 | style: { 38 | width: "100%", 39 | height: "100%", 40 | }, 41 | }, this.createButtons()), 42 | ]); 43 | this.is_layout_created = false; 44 | } 45 | 46 | createButtons() { 47 | const closeBtn = $el("button", { 48 | type: "button", 49 | textContent: "Close", 50 | onclick: () => this.close(), 51 | }); 52 | return [ 53 | closeBtn, 54 | ]; 55 | } 56 | 57 | async close() { 58 | const targetNode = ComfyApp.clipspace_return_node; 59 | const textAreaElement = targetNode.widgets[0].element; 60 | textAreaElement.value = await this.getCanvasJSONString(); 61 | super.close(); 62 | } 63 | 64 | async show() { 65 | if (!this.is_layout_created) { 66 | this.createLayout(); 67 | this.is_layout_created = true; 68 | await this.waitIframeReady(); 69 | } 70 | 71 | const targetNode = ComfyApp.clipspace_return_node; 72 | const textAreaElement = targetNode.widgets[0].element; 73 | this.element.style.display = "flex"; 74 | this.setCanvasJSONString(textAreaElement.value); 75 | } 76 | 77 | createLayout() { 78 | this.iframeElement = $el("iframe", { 79 | // Change to http://localhost:5174 for local dev 80 | src: "https://huchenlei.github.io/omost_region_editor", 81 | style: { 82 | width: "100%", 83 | height: "100%", 84 | border: "none", 85 | }, 86 | }); 87 | const modalContent = this.element.querySelector(".comfy-modal-content"); 88 | while (modalContent.firstChild) { 89 | modalContent.removeChild(modalContent.firstChild); 90 | } 91 | modalContent.appendChild(this.iframeElement); 92 | modalContent.appendChild(...this.createButtons()); 93 | } 94 | 95 | waitIframeReady() { 96 | return new Promise((resolve, reject) => { 97 | window.addEventListener("message", (event) => { 98 | if (event.source !== this.iframeElement.contentWindow) { 99 | return; 100 | } 101 | if (event.data.type === "ready") { 102 | resolve(); 103 | } 104 | }); 105 | setTimeout(() => { 106 | reject(new Error("Timeout")); 107 | }, OmostCanvasDialog.timeout); 108 | }); 109 | } 110 | 111 | getCanvasJSONString() { 112 | return new Promise((resolve, reject) => { 113 | window.addEventListener("message", (event) => { 114 | if (event.source !== this.iframeElement.contentWindow) { 115 | return; 116 | } 117 | if (event.data.type === "save") { 118 | resolve(JSON.stringify(event.data.regions)); 119 | } 120 | }); 121 | 122 | this.iframeElement.contentWindow.postMessage({ type: "save" }, "*"); 123 | 124 | setTimeout(() => { 125 | reject(new Error("Timeout")); 126 | }, OmostCanvasDialog.timeout); 127 | }); 128 | } 129 | 130 | setCanvasJSONString(jsonString) { 131 | this.iframeElement.contentWindow.postMessage( 132 | { type: "update", regions: JSON.parse(jsonString) }, "*"); 133 | } 134 | } 135 | 136 | function isOmostLoadCanvasConditioningNode(nodeData) { 137 | return nodeData.name === "OmostLoadCanvasConditioningNode"; 138 | } 139 | 140 | app.registerExtension({ 141 | name: "huchenlei.EditOmostCanvas", 142 | 143 | async beforeRegisterNodeDef(nodeType, nodeData) { 144 | if (isOmostLoadCanvasConditioningNode(nodeData)) { 145 | addMenuHandler(nodeType, function (_, options) { 146 | options.unshift({ 147 | content: "Open in Omost Canvas Editor", 148 | callback: () => { 149 | // `this` is the node instance 150 | ComfyApp.copyToClipspace(this); 151 | ComfyApp.clipspace_return_node = this; 152 | 153 | const dlg = OmostCanvasDialog.getInstance(); 154 | dlg.show(); 155 | }, 156 | }); 157 | }); 158 | } 159 | } 160 | }); 161 | -------------------------------------------------------------------------------- /lib_omost/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huchenlei/ComfyUI_omost/914b06c7a563504a61fe21d3bead1b20c3d3be37/lib_omost/__init__.py -------------------------------------------------------------------------------- /lib_omost/canvas.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | import re 3 | import difflib 4 | import torch 5 | import numpy as np 6 | from typing import TypedDict 7 | 8 | 9 | system_prompt = r"""You are a helpful AI assistant to compose images using the below python class `Canvas`: 10 | 11 | ```python 12 | class Canvas: 13 | def set_global_description(self, description: str, detailed_descriptions: list[str], tags: str, HTML_web_color_name: str): 14 | pass 15 | 16 | def add_local_description(self, location: str, offset: str, area: str, distance_to_viewer: float, description: str, detailed_descriptions: list[str], tags: str, atmosphere: str, style: str, quality_meta: str, HTML_web_color_name: str): 17 | assert location in ["in the center", "on the left", "on the right", "on the top", "on the bottom", "on the top-left", "on the top-right", "on the bottom-left", "on the bottom-right"] 18 | assert offset in ["no offset", "slightly to the left", "slightly to the right", "slightly to the upper", "slightly to the lower", "slightly to the upper-left", "slightly to the upper-right", "slightly to the lower-left", "slightly to the lower-right"] 19 | assert area in ["a small square area", "a small vertical area", "a small horizontal area", "a medium-sized square area", "a medium-sized vertical area", "a medium-sized horizontal area", "a large square area", "a large vertical area", "a large horizontal area"] 20 | assert distance_to_viewer > 0 21 | pass 22 | ```""" 23 | 24 | valid_colors = { # r, g, b 25 | "aliceblue": (240, 248, 255), 26 | "antiquewhite": (250, 235, 215), 27 | "aqua": (0, 255, 255), 28 | "aquamarine": (127, 255, 212), 29 | "azure": (240, 255, 255), 30 | "beige": (245, 245, 220), 31 | "bisque": (255, 228, 196), 32 | "black": (0, 0, 0), 33 | "blanchedalmond": (255, 235, 205), 34 | "blue": (0, 0, 255), 35 | "blueviolet": (138, 43, 226), 36 | "brown": (165, 42, 42), 37 | "burlywood": (222, 184, 135), 38 | "cadetblue": (95, 158, 160), 39 | "chartreuse": (127, 255, 0), 40 | "chocolate": (210, 105, 30), 41 | "coral": (255, 127, 80), 42 | "cornflowerblue": (100, 149, 237), 43 | "cornsilk": (255, 248, 220), 44 | "crimson": (220, 20, 60), 45 | "cyan": (0, 255, 255), 46 | "darkblue": (0, 0, 139), 47 | "darkcyan": (0, 139, 139), 48 | "darkgoldenrod": (184, 134, 11), 49 | "darkgray": (169, 169, 169), 50 | "darkgrey": (169, 169, 169), 51 | "darkgreen": (0, 100, 0), 52 | "darkkhaki": (189, 183, 107), 53 | "darkmagenta": (139, 0, 139), 54 | "darkolivegreen": (85, 107, 47), 55 | "darkorange": (255, 140, 0), 56 | "darkorchid": (153, 50, 204), 57 | "darkred": (139, 0, 0), 58 | "darksalmon": (233, 150, 122), 59 | "darkseagreen": (143, 188, 143), 60 | "darkslateblue": (72, 61, 139), 61 | "darkslategray": (47, 79, 79), 62 | "darkslategrey": (47, 79, 79), 63 | "darkturquoise": (0, 206, 209), 64 | "darkviolet": (148, 0, 211), 65 | "deeppink": (255, 20, 147), 66 | "deepskyblue": (0, 191, 255), 67 | "dimgray": (105, 105, 105), 68 | "dimgrey": (105, 105, 105), 69 | "dodgerblue": (30, 144, 255), 70 | "firebrick": (178, 34, 34), 71 | "floralwhite": (255, 250, 240), 72 | "forestgreen": (34, 139, 34), 73 | "fuchsia": (255, 0, 255), 74 | "gainsboro": (220, 220, 220), 75 | "ghostwhite": (248, 248, 255), 76 | "gold": (255, 215, 0), 77 | "goldenrod": (218, 165, 32), 78 | "gray": (128, 128, 128), 79 | "grey": (128, 128, 128), 80 | "green": (0, 128, 0), 81 | "greenyellow": (173, 255, 47), 82 | "honeydew": (240, 255, 240), 83 | "hotpink": (255, 105, 180), 84 | "indianred": (205, 92, 92), 85 | "indigo": (75, 0, 130), 86 | "ivory": (255, 255, 240), 87 | "khaki": (240, 230, 140), 88 | "lavender": (230, 230, 250), 89 | "lavenderblush": (255, 240, 245), 90 | "lawngreen": (124, 252, 0), 91 | "lemonchiffon": (255, 250, 205), 92 | "lightblue": (173, 216, 230), 93 | "lightcoral": (240, 128, 128), 94 | "lightcyan": (224, 255, 255), 95 | "lightgoldenrodyellow": (250, 250, 210), 96 | "lightgray": (211, 211, 211), 97 | "lightgrey": (211, 211, 211), 98 | "lightgreen": (144, 238, 144), 99 | "lightpink": (255, 182, 193), 100 | "lightsalmon": (255, 160, 122), 101 | "lightseagreen": (32, 178, 170), 102 | "lightskyblue": (135, 206, 250), 103 | "lightslategray": (119, 136, 153), 104 | "lightslategrey": (119, 136, 153), 105 | "lightsteelblue": (176, 196, 222), 106 | "lightyellow": (255, 255, 224), 107 | "lime": (0, 255, 0), 108 | "limegreen": (50, 205, 50), 109 | "linen": (250, 240, 230), 110 | "magenta": (255, 0, 255), 111 | "maroon": (128, 0, 0), 112 | "mediumaquamarine": (102, 205, 170), 113 | "mediumblue": (0, 0, 205), 114 | "mediumorchid": (186, 85, 211), 115 | "mediumpurple": (147, 112, 219), 116 | "mediumseagreen": (60, 179, 113), 117 | "mediumslateblue": (123, 104, 238), 118 | "mediumspringgreen": (0, 250, 154), 119 | "mediumturquoise": (72, 209, 204), 120 | "mediumvioletred": (199, 21, 133), 121 | "midnightblue": (25, 25, 112), 122 | "mintcream": (245, 255, 250), 123 | "mistyrose": (255, 228, 225), 124 | "moccasin": (255, 228, 181), 125 | "navajowhite": (255, 222, 173), 126 | "navy": (0, 0, 128), 127 | "navyblue": (0, 0, 128), 128 | "oldlace": (253, 245, 230), 129 | "olive": (128, 128, 0), 130 | "olivedrab": (107, 142, 35), 131 | "orange": (255, 165, 0), 132 | "orangered": (255, 69, 0), 133 | "orchid": (218, 112, 214), 134 | "palegoldenrod": (238, 232, 170), 135 | "palegreen": (152, 251, 152), 136 | "paleturquoise": (175, 238, 238), 137 | "palevioletred": (219, 112, 147), 138 | "papayawhip": (255, 239, 213), 139 | "peachpuff": (255, 218, 185), 140 | "peru": (205, 133, 63), 141 | "pink": (255, 192, 203), 142 | "plum": (221, 160, 221), 143 | "powderblue": (176, 224, 230), 144 | "purple": (128, 0, 128), 145 | "rebeccapurple": (102, 51, 153), 146 | "red": (255, 0, 0), 147 | "rosybrown": (188, 143, 143), 148 | "royalblue": (65, 105, 225), 149 | "saddlebrown": (139, 69, 19), 150 | "salmon": (250, 128, 114), 151 | "sandybrown": (244, 164, 96), 152 | "seagreen": (46, 139, 87), 153 | "seashell": (255, 245, 238), 154 | "sienna": (160, 82, 45), 155 | "silver": (192, 192, 192), 156 | "skyblue": (135, 206, 235), 157 | "slateblue": (106, 90, 205), 158 | "slategray": (112, 128, 144), 159 | "slategrey": (112, 128, 144), 160 | "snow": (255, 250, 250), 161 | "springgreen": (0, 255, 127), 162 | "steelblue": (70, 130, 180), 163 | "tan": (210, 180, 140), 164 | "teal": (0, 128, 128), 165 | "thistle": (216, 191, 216), 166 | "tomato": (255, 99, 71), 167 | "turquoise": (64, 224, 208), 168 | "violet": (238, 130, 238), 169 | "wheat": (245, 222, 179), 170 | "white": (255, 255, 255), 171 | "whitesmoke": (245, 245, 245), 172 | "yellow": (255, 255, 0), 173 | "yellowgreen": (154, 205, 50), 174 | } 175 | 176 | valid_locations = { # x, y in 90*90 177 | "in the center": (45, 45), 178 | "on the left": (15, 45), 179 | "on the right": (75, 45), 180 | "on the top": (45, 15), 181 | "on the bottom": (45, 75), 182 | "on the top-left": (15, 15), 183 | "on the top-right": (75, 15), 184 | "on the bottom-left": (15, 75), 185 | "on the bottom-right": (75, 75), 186 | } 187 | 188 | valid_offsets = { # x, y in 90*90 189 | "no offset": (0, 0), 190 | "slightly to the left": (-10, 0), 191 | "slightly to the right": (10, 0), 192 | "slightly to the upper": (0, -10), 193 | "slightly to the lower": (0, 10), 194 | "slightly to the upper-left": (-10, -10), 195 | "slightly to the upper-right": (10, -10), 196 | "slightly to the lower-left": (-10, 10), 197 | "slightly to the lower-right": (10, 10), 198 | } 199 | 200 | valid_areas = { # w, h in 90*90 201 | "a small square area": (50, 50), 202 | "a small vertical area": (40, 60), 203 | "a small horizontal area": (60, 40), 204 | "a medium-sized square area": (60, 60), 205 | "a medium-sized vertical area": (50, 80), 206 | "a medium-sized horizontal area": (80, 50), 207 | "a large square area": (70, 70), 208 | "a large vertical area": (60, 90), 209 | "a large horizontal area": (90, 60), 210 | } 211 | 212 | 213 | def closest_name(input_str, options): 214 | input_str = input_str.lower() 215 | 216 | closest_match = difflib.get_close_matches( 217 | input_str, list(options.keys()), n=1, cutoff=0.5 218 | ) 219 | assert ( 220 | isinstance(closest_match, list) and len(closest_match) > 0 221 | ), f"The value [{input_str}] is not valid!" 222 | result = closest_match[0] 223 | 224 | if result != input_str: 225 | print(f"Automatically corrected [{input_str}] -> [{result}].") 226 | 227 | return result 228 | 229 | 230 | def safe_str(x): 231 | return x.strip(",. ") + "." 232 | 233 | 234 | def binary_nonzero_positions(n, offset=0): 235 | binary_str = bin(n)[2:] 236 | positions = [i + offset for i, bit in enumerate(reversed(binary_str)) if bit == "1"] 237 | return positions 238 | 239 | 240 | class OmostCanvasCondition(TypedDict): 241 | prefixes: list[str] 242 | suffixes: list[str] 243 | rect: tuple[int, int, int, int] 244 | color: tuple[int, int, int] 245 | 246 | 247 | class Canvas: 248 | @staticmethod 249 | def from_bot_response(response: str) -> Canvas: 250 | matched = re.search(r"```python\n(.*?)\n```", response, re.DOTALL) 251 | assert matched, f"Response does not contain codes!\n{response}" 252 | code_content = matched.group(1) 253 | assert ( 254 | "canvas = Canvas()" in code_content 255 | ), f"Code block must include valid canvas var!\n{response}" 256 | return Canvas.from_python_code(code_content) 257 | 258 | @staticmethod 259 | def from_python_code(code: str) -> Canvas: 260 | local_vars = {"Canvas": Canvas} 261 | exec(code, {}, local_vars) 262 | canvas = local_vars.get("canvas", None) 263 | assert isinstance(canvas, Canvas), "Code must produce valid canvas var!" 264 | return canvas 265 | 266 | def __init__(self): 267 | self.components = [] 268 | self.color = None 269 | self.record_tags = True 270 | self.prefixes = [] 271 | self.suffixes = [] 272 | return 273 | 274 | def set_global_description( 275 | self, 276 | description: str, 277 | detailed_descriptions: list[str], 278 | tags: str, 279 | HTML_web_color_name: str, 280 | ): 281 | assert isinstance(description, str), "Global description is not valid!" 282 | assert isinstance(detailed_descriptions, list) and all( 283 | isinstance(item, str) for item in detailed_descriptions 284 | ), "Global detailed_descriptions is not valid!" 285 | assert isinstance(tags, str), "Global tags is not valid!" 286 | 287 | HTML_web_color_name = closest_name(HTML_web_color_name, valid_colors) 288 | self.color = valid_colors[HTML_web_color_name] 289 | 290 | self.prefixes = [description] 291 | self.suffixes = detailed_descriptions 292 | 293 | if self.record_tags: 294 | self.suffixes = self.suffixes + [tags] 295 | 296 | self.prefixes = [safe_str(x) for x in self.prefixes] 297 | self.suffixes = [safe_str(x) for x in self.suffixes] 298 | 299 | return 300 | 301 | def add_local_description( 302 | self, 303 | location: str, 304 | offset: str, 305 | area: str, 306 | distance_to_viewer: float, 307 | description: str, 308 | detailed_descriptions: list[str], 309 | tags: str, 310 | atmosphere: str, 311 | style: str, 312 | quality_meta: str, 313 | HTML_web_color_name: str, 314 | ): 315 | assert isinstance(description, str), "Local description is wrong!" 316 | assert ( 317 | isinstance(distance_to_viewer, (int, float)) and distance_to_viewer > 0 318 | ), f"The distance_to_viewer for [{description}] is not positive float number!" 319 | assert isinstance(detailed_descriptions, list) and all( 320 | isinstance(item, str) for item in detailed_descriptions 321 | ), f"The detailed_descriptions for [{description}] is not valid!" 322 | assert isinstance(tags, str), f"The tags for [{description}] is not valid!" 323 | assert isinstance( 324 | atmosphere, str 325 | ), f"The atmosphere for [{description}] is not valid!" 326 | assert isinstance(style, str), f"The style for [{description}] is not valid!" 327 | assert isinstance( 328 | quality_meta, str 329 | ), f"The quality_meta for [{description}] is not valid!" 330 | 331 | location = closest_name(location, valid_locations) 332 | offset = closest_name(offset, valid_offsets) 333 | area = closest_name(area, valid_areas) 334 | HTML_web_color_name = closest_name(HTML_web_color_name, valid_colors) 335 | 336 | xb, yb = valid_locations[location] 337 | xo, yo = valid_offsets[offset] 338 | w, h = valid_areas[area] 339 | rect = (yb + yo - h // 2, yb + yo + h // 2, xb + xo - w // 2, xb + xo + w // 2) 340 | rect = [max(0, min(90, i)) for i in rect] 341 | color = valid_colors[HTML_web_color_name] 342 | 343 | prefixes = self.prefixes + [description] 344 | suffixes = detailed_descriptions 345 | 346 | if self.record_tags: 347 | suffixes = suffixes + [tags, atmosphere, style, quality_meta] 348 | 349 | prefixes = [safe_str(x) for x in prefixes] 350 | suffixes = [safe_str(x) for x in suffixes] 351 | 352 | self.components.append( 353 | dict( 354 | rect=rect, 355 | distance_to_viewer=distance_to_viewer, 356 | color=color, 357 | prefixes=prefixes, 358 | suffixes=suffixes, 359 | ) 360 | ) 361 | 362 | return 363 | 364 | @staticmethod 365 | def render_initial_latent(conds: list[OmostCanvasCondition]) -> np.ndarray: 366 | def np_color(rgb: tuple[int, int, int]) -> np.ndarray: 367 | return np.array([[rgb]], dtype=np.uint8) 368 | 369 | initial_latent = np.zeros(shape=(90, 90, 3), dtype=np.float32) + np_color( 370 | conds[0]["color"] 371 | ) 372 | 373 | for cond in conds[1:]: 374 | a, b, c, d = cond["rect"] 375 | initial_latent[a:b, c:d] = ( 376 | 0.7 * np_color(cond["color"]) + 0.3 * initial_latent[a:b, c:d] 377 | ) 378 | 379 | initial_latent = initial_latent.clip(0, 255).astype(np.uint8) 380 | 381 | return initial_latent 382 | 383 | def render_mask(cond: OmostCanvasCondition) -> torch.Tensor: 384 | """Returns mask of shape [H, W]""" 385 | mask = torch.zeros([90, 90], dtype=torch.float32) 386 | a, b, c, d = cond["rect"] 387 | mask[a:b, c:d] = 1.0 388 | return mask 389 | 390 | def process(self) -> list[OmostCanvasCondition]: 391 | # sort components 392 | self.components = sorted( 393 | self.components, key=lambda x: x["distance_to_viewer"], reverse=True 394 | ) 395 | 396 | # compute conditions 397 | bag_of_conditions = [ 398 | dict( 399 | rect=(0, 90, 0, 90), 400 | prefixes=self.prefixes, 401 | suffixes=self.suffixes, 402 | color=self.color, 403 | ) 404 | ] 405 | 406 | for component in self.components: 407 | bag_of_conditions.append( 408 | dict( 409 | color=component["color"], 410 | rect=component["rect"], 411 | prefixes=component["prefixes"], 412 | suffixes=component["suffixes"], 413 | ) 414 | ) 415 | 416 | return bag_of_conditions 417 | -------------------------------------------------------------------------------- /lib_omost/greedy_encode.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | import logging 3 | import torch 4 | from typing import Callable, NamedTuple, TypedDict 5 | 6 | 7 | class SpecialTokens(TypedDict): 8 | start: int 9 | end: int 10 | pad: int 11 | 12 | 13 | class CLIPTokens(NamedTuple): 14 | clip_l_tokens: list[int] 15 | clip_g_tokens: list[int] | None = None 16 | 17 | @classmethod 18 | def empty_tokens(cls) -> CLIPTokens: 19 | return CLIPTokens(clip_l_tokens=[], clip_g_tokens=[]) 20 | 21 | @property 22 | def length(self) -> int: 23 | return len(self.clip_l_tokens) 24 | 25 | def __repr__(self) -> str: 26 | return f"CLIPTokens(clip_l_tokens({len(self.clip_l_tokens)}), clip_g_tokens={len(self.clip_g_tokens) if self.clip_g_tokens else None})" 27 | 28 | def __add__(self, other: CLIPTokens) -> CLIPTokens: 29 | if self.clip_g_tokens is None or other.clip_g_tokens is None: 30 | clip_g_tokens = None 31 | else: 32 | clip_g_tokens = self.clip_g_tokens + other.clip_g_tokens 33 | 34 | return CLIPTokens( 35 | clip_l_tokens=self.clip_l_tokens + other.clip_l_tokens, 36 | clip_g_tokens=clip_g_tokens, 37 | ) 38 | 39 | @staticmethod 40 | def _get_77_tokens(subprompt_inds: list[int]) -> list[int]: 41 | # Note that all subprompt are theoretically less than 75 tokens (without bos/eos) 42 | result = ( 43 | [SPECIAL_TOKENS["start"]] 44 | + subprompt_inds[:75] 45 | + [SPECIAL_TOKENS["end"]] 46 | + [SPECIAL_TOKENS["pad"]] * 75 47 | ) 48 | return result[:77] 49 | 50 | def clamp_to_77_tokens(self) -> CLIPTokens: 51 | return CLIPTokens( 52 | clip_l_tokens=self._get_77_tokens(self.clip_l_tokens), 53 | clip_g_tokens=( 54 | self._get_77_tokens(self.clip_g_tokens) 55 | if self.clip_g_tokens 56 | else None 57 | ), 58 | ) 59 | 60 | 61 | class EncoderOutput(NamedTuple): 62 | cond: torch.Tensor 63 | pooler: torch.Tensor 64 | 65 | 66 | TokenizeFunc = Callable[[str], CLIPTokens] 67 | EncodeFunc = Callable[[CLIPTokens], EncoderOutput] 68 | 69 | 70 | # ComfyUI protocol. See sd1_clip.py/sdxl_clip.py for the actual implementation. 71 | SPECIAL_TOKENS: SpecialTokens = {"start": 49406, "end": 49407, "pad": 49407} 72 | 73 | 74 | def greedy_partition(items: list[CLIPTokens], max_sum: int) -> list[list[CLIPTokens]]: 75 | bags: list[list[CLIPTokens]] = [] 76 | current_bag: list[CLIPTokens] = [] 77 | current_sum: int = 0 78 | 79 | for item in items: 80 | num = item.length 81 | if current_sum + num > max_sum: 82 | if current_bag: 83 | bags.append(current_bag) 84 | current_bag = [item] 85 | current_sum = num 86 | else: 87 | current_bag.append(item) 88 | current_sum += num 89 | 90 | if current_bag: 91 | bags.append(current_bag) 92 | 93 | return bags 94 | 95 | 96 | def encode_bag_of_subprompts_greedy( 97 | prefixes: list[str], 98 | suffixes: list[str], 99 | tokenize_func: TokenizeFunc, 100 | encode_func: EncodeFunc, 101 | logger: logging.Logger | None = None, 102 | ) -> EncoderOutput: 103 | """ 104 | Note: tokenize_func is expected to clamp the tokens to 75 tokens. 105 | """ 106 | if logger is None: 107 | logger = logging.getLogger(__name__) 108 | 109 | # Begin with tokenizing prefixes 110 | prefix_tokens: CLIPTokens = sum( 111 | [tokenize_func(prefix) for prefix in prefixes], CLIPTokens.empty_tokens() 112 | ) 113 | logger.debug(f"Prefix tokens: {prefix_tokens}") 114 | 115 | # Then tokenizing suffixes 116 | allowed_suffix_length = 75 - prefix_tokens.length 117 | logger.debug(f"Allowed suffix length: {allowed_suffix_length}") 118 | suffix_targets: list[CLIPTokens] = [ 119 | tokenize_func(subprompt) for subprompt in suffixes 120 | ] 121 | logger.debug(f"Suffix targets: {suffix_targets}") 122 | 123 | # Then merge prefix and suffix tokens 124 | suffix_targets = greedy_partition(suffix_targets, max_sum=allowed_suffix_length) 125 | targets = [ 126 | sum([prefix_tokens, *b], CLIPTokens.empty_tokens()).clamp_to_77_tokens() 127 | for b in suffix_targets 128 | ] 129 | 130 | # Encode! 131 | encoded_embeds = [encode_func(target) for target in targets] 132 | conds_merged = torch.concat([embed.cond for embed in encoded_embeds], dim=1) 133 | poolers_merged = encoded_embeds[0].pooler 134 | logger.debug(f"merged conds: {conds_merged.shape}, pooler: {poolers_merged.shape}") 135 | 136 | return EncoderOutput(cond=conds_merged, pooler=poolers_merged) 137 | -------------------------------------------------------------------------------- /lib_omost/utils.py: -------------------------------------------------------------------------------- 1 | from contextlib import contextmanager 2 | 3 | import torch 4 | import numpy as np 5 | 6 | 7 | @torch.inference_mode() 8 | def numpy2pytorch(imgs: list[np.ndarray]): 9 | """Convert a list of numpy images to a pytorch tensor. 10 | Input: images in list[[H, W, C]] format. 11 | Output: images in [B, H, W, C] format. 12 | 13 | Note: ComfyUI expects [B, H, W, C] format instead of [B, C, H, W] format. 14 | """ 15 | assert len(imgs) > 0 16 | assert all(img.ndim == 3 for img in imgs) 17 | h = torch.from_numpy(np.stack(imgs, axis=0)).float() / 255.0 18 | return h 19 | 20 | 21 | @contextmanager 22 | def scoped_numpy_random(seed: int): 23 | state = np.random.get_state() # Save the current state 24 | np.random.seed(seed) # Set the seed 25 | try: 26 | yield 27 | finally: 28 | np.random.set_state(state) # Restore the original state 29 | 30 | 31 | @contextmanager 32 | def scoped_torch_random(seed: int): 33 | cpu_state = torch.random.get_rng_state() 34 | gpu_states = [] 35 | if torch.cuda.is_available(): 36 | gpu_states = [ 37 | torch.cuda.get_rng_state(device) 38 | for device in range(torch.cuda.device_count()) 39 | ] 40 | 41 | try: 42 | torch.manual_seed(seed) 43 | if torch.cuda.is_available(): 44 | torch.cuda.manual_seed_all(seed) 45 | yield 46 | finally: 47 | torch.random.set_rng_state(cpu_state) 48 | if torch.cuda.is_available(): 49 | for idx, state in enumerate(gpu_states): 50 | torch.cuda.set_rng_state(state, device=idx) 51 | -------------------------------------------------------------------------------- /omost_nodes.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | from enum import Enum 3 | import json 4 | from typing import Literal, Tuple, TypedDict, NamedTuple 5 | import sys 6 | import os 7 | import logging 8 | from typing_extensions import NotRequired 9 | 10 | import requests 11 | from openai import OpenAI 12 | import torch 13 | from transformers import AutoModelForCausalLM, AutoTokenizer 14 | 15 | import comfy.model_management 16 | from comfy.model_patcher import ModelPatcher 17 | from comfy.sd import CLIP 18 | from nodes import CLIPTextEncode, ConditioningSetMask 19 | from .lib_omost.canvas import ( 20 | Canvas as OmostCanvas, 21 | OmostCanvasCondition, 22 | system_prompt, 23 | ) 24 | from .lib_omost.utils import numpy2pytorch, scoped_numpy_random, scoped_torch_random 25 | from .lib_omost.greedy_encode import ( 26 | encode_bag_of_subprompts_greedy, 27 | CLIPTokens, 28 | EncoderOutput, 29 | SPECIAL_TOKENS, 30 | ) 31 | 32 | 33 | def create_logger(level=logging.INFO): 34 | logger = logging.getLogger(__name__) 35 | logger.setLevel(level) 36 | if not logger.handlers: 37 | handler = logging.StreamHandler(sys.stdout) 38 | handler.setFormatter( 39 | logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") 40 | ) 41 | logger.addHandler(handler) 42 | return logger 43 | 44 | 45 | logger = create_logger(level=logging.INFO) 46 | 47 | # Canvas size used in original Omost repo. 48 | CANVAS_SIZE = 90 49 | 50 | 51 | # Type definitions. 52 | class OmostConversationItem(TypedDict): 53 | role: Literal["system", "user", "assistant"] 54 | content: str 55 | 56 | 57 | OmostConversation = list[OmostConversationItem] 58 | 59 | 60 | class OmostLLM(NamedTuple): 61 | model: AutoModelForCausalLM 62 | tokenizer: AutoTokenizer 63 | 64 | 65 | class OmostLLMServer(NamedTuple): 66 | client: OpenAI 67 | model_id: str 68 | 69 | 70 | ComfyUIConditioning = list # Dummy type definitions for ComfyUI 71 | ComfyCLIPTokensWithWeight = list[Tuple[int, float]] 72 | 73 | 74 | class ComfyCLIPTokens(TypedDict): 75 | l: list[ComfyCLIPTokensWithWeight] 76 | g: NotRequired[list[ComfyCLIPTokensWithWeight]] 77 | 78 | 79 | # End of type definitions. 80 | 81 | 82 | class OmostLLMLoaderNode: 83 | @classmethod 84 | def INPUT_TYPES(s): 85 | return { 86 | "required": { 87 | "llm_name": ( 88 | [ 89 | "lllyasviel/omost-phi-3-mini-128k-8bits", 90 | "lllyasviel/omost-llama-3-8b-4bits", 91 | "lllyasviel/omost-dolphin-2.9-llama3-8b-4bits", 92 | ], 93 | { 94 | "default": "lllyasviel/omost-llama-3-8b-4bits", 95 | }, 96 | ), 97 | } 98 | } 99 | 100 | RETURN_TYPES = ("OMOST_LLM",) 101 | FUNCTION = "load_llm" 102 | CATEGORY = "omost" 103 | 104 | def load_llm(self, llm_name: str) -> Tuple[OmostLLM]: 105 | """Load LLM model""" 106 | HF_TOKEN = None 107 | dtype = ( 108 | torch.float16 if comfy.model_management.should_use_fp16() else torch.float32 109 | ) 110 | 111 | llm_model = AutoModelForCausalLM.from_pretrained( 112 | llm_name, 113 | torch_dtype=dtype, # This is computation type, not load/memory type. The loading quant type is baked in config. 114 | token=HF_TOKEN, 115 | device_map="auto", # This will load model to gpu with an offload system 116 | trust_remote_code=True, 117 | ) 118 | llm_tokenizer = AutoTokenizer.from_pretrained(llm_name, token=HF_TOKEN) 119 | 120 | return (OmostLLM(llm_model, llm_tokenizer),) 121 | 122 | 123 | class OmostLLMHTTPServerNode: 124 | @classmethod 125 | def INPUT_TYPES(s): 126 | return { 127 | "required": { 128 | "address": ("STRING", {"multiline": True}), 129 | "api_type":( 130 | [ 131 | "OpenAI", 132 | "TGI" 133 | ], 134 | { 135 | "default": "OpenAI" 136 | } 137 | ) 138 | } 139 | } 140 | 141 | RETURN_TYPES = ("OMOST_LLM",) 142 | FUNCTION = "init_client" 143 | CATEGORY = "omost" 144 | 145 | def init_client(self, address: str, api_type: str) -> Tuple[OmostLLMServer]: 146 | """Initialize LLM client with HTTP server address.""" 147 | 148 | if api_type == "OpenAI": 149 | if address.endswith("v1"): 150 | server_address = address 151 | else: 152 | server_address = os.path.join(address, "v1") 153 | 154 | model_id = "" 155 | 156 | elif api_type == "TGI": 157 | if address.endswith("v1"): 158 | server_address = address 159 | server_info_url = address.replace("v1", "info") 160 | else: 161 | server_address = os.path.join(address, "v1") 162 | server_info_url = os.path.join(address, "info") 163 | #Get model_id from server info 164 | server_info = requests.get(server_info_url, timeout=5).json() 165 | model_id = server_info["model_id"] 166 | 167 | client = OpenAI(base_url=server_address, api_key="_") 168 | 169 | return (OmostLLMServer(client, model_id),) 170 | 171 | 172 | class OmostLLMChatNode: 173 | @classmethod 174 | def INPUT_TYPES(s): 175 | return { 176 | "required": { 177 | "llm": ("OMOST_LLM",), 178 | "text": ("STRING", {"multiline": True}), 179 | "max_new_tokens": ( 180 | "INT", 181 | {"min": 128, "max": 4096, "step": 1, "default": 4096}, 182 | ), 183 | "top_p": ( 184 | "FLOAT", 185 | {"min": 0.0, "max": 1.0, "step": 0.01, "default": 0.9}, 186 | ), 187 | "temperature": ( 188 | "FLOAT", 189 | {"min": 0.0, "max": 2.0, "step": 0.01, "default": 0.6}, 190 | ), 191 | # Note: ComfyUI's front-end code randomizes the seed to 64-bit int. 192 | "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), 193 | }, 194 | "optional": { 195 | "conversation": ("OMOST_CONVERSATION",), 196 | }, 197 | } 198 | 199 | RETURN_TYPES = ( 200 | "OMOST_CONVERSATION", 201 | "OMOST_CANVAS_CONDITIONING", 202 | ) 203 | FUNCTION = "run_llm" 204 | CATEGORY = "omost" 205 | 206 | def prepare_conversation( 207 | self, text: str, conversation: OmostConversation | None = None 208 | ) -> Tuple[OmostConversation, OmostConversation, OmostConversationItem]: 209 | conversation = conversation or [] # Default to empty list 210 | system_conversation_item: OmostConversationItem = { 211 | "role": "system", 212 | "content": system_prompt, 213 | } 214 | user_conversation_item: OmostConversationItem = { 215 | "role": "user", 216 | "content": text, 217 | } 218 | input_conversation: list[OmostConversationItem] = [ 219 | system_conversation_item, 220 | *conversation, 221 | user_conversation_item, 222 | ] 223 | return conversation, input_conversation, user_conversation_item 224 | 225 | def run_local_llm( 226 | self, 227 | llm: OmostLLM, 228 | input_conversation: list[OmostConversationItem], 229 | max_new_tokens: int, 230 | top_p: float, 231 | temperature: float, 232 | seed: int, 233 | ) -> str: 234 | with scoped_torch_random(seed), scoped_numpy_random(seed): 235 | llm_tokenizer: AutoTokenizer = llm.tokenizer 236 | llm_model: AutoModelForCausalLM = llm.model 237 | 238 | input_ids: torch.Tensor = llm_tokenizer.apply_chat_template( 239 | input_conversation, return_tensors="pt", add_generation_prompt=True 240 | ).to(llm_model.device) 241 | input_length = input_ids.shape[1] 242 | 243 | output_ids: torch.Tensor = llm_model.generate( 244 | input_ids=input_ids, 245 | max_new_tokens=max_new_tokens, 246 | temperature=temperature, 247 | top_p=top_p, 248 | do_sample=temperature != 0, 249 | ) 250 | generated_ids = output_ids[:, input_length:] 251 | generated_text: str = llm_tokenizer.decode( 252 | generated_ids[0], 253 | skip_special_tokens=True, 254 | skip_prompt=True, 255 | timeout=10, 256 | ) 257 | return generated_text 258 | 259 | def run_llm( 260 | self, 261 | llm: OmostLLM | OmostLLMServer, 262 | text: str, 263 | max_new_tokens: int, 264 | top_p: float, 265 | temperature: float, 266 | seed: int, 267 | conversation: OmostConversation | None = None, 268 | ) -> Tuple[OmostConversation, OmostCanvas]: 269 | """Run LLM on text""" 270 | if seed > 0xFFFFFFFF: 271 | seed = seed & 0xFFFFFFFF 272 | logger.warning("Seed is too large. Truncating to 32-bit: %d", seed) 273 | 274 | conversation, input_conversation, user_conversation_item = ( 275 | self.prepare_conversation(text, conversation) 276 | ) 277 | 278 | if isinstance(llm, OmostLLM): 279 | generated_text = self.run_local_llm( 280 | llm, input_conversation, max_new_tokens, top_p, temperature, seed 281 | ) 282 | else: 283 | generated_text = ( 284 | llm.client.chat.completions.create( 285 | model=llm.model_id, 286 | messages=input_conversation, 287 | top_p=top_p, 288 | temperature=temperature, 289 | max_tokens=max_new_tokens, 290 | seed=seed, 291 | ) 292 | .choices[0] 293 | .message.content 294 | ) 295 | 296 | output_conversation = [ 297 | *conversation, 298 | user_conversation_item, 299 | {"role": "assistant", "content": generated_text}, 300 | ] 301 | return ( 302 | output_conversation, 303 | OmostCanvas.from_bot_response(generated_text).process(), 304 | ) 305 | 306 | 307 | class OmostRenderCanvasConditioningNode: 308 | @classmethod 309 | def INPUT_TYPES(s): 310 | return { 311 | "required": { 312 | "canvas_conds": ("OMOST_CANVAS_CONDITIONING",), 313 | } 314 | } 315 | 316 | RETURN_TYPES = ("IMAGE", "MASK") 317 | FUNCTION = "render_canvas" 318 | CATEGORY = "omost" 319 | 320 | def render_canvas( 321 | self, canvas_conds: list[OmostCanvasCondition] 322 | ) -> Tuple[torch.Tensor, torch.Tensor]: 323 | """Render canvas conditioning to image""" 324 | return ( 325 | numpy2pytorch(imgs=[OmostCanvas.render_initial_latent(canvas_conds)]), 326 | torch.cat( 327 | [OmostCanvas.render_mask(cond).unsqueeze(0) for cond in canvas_conds], 328 | dim=0, 329 | ), 330 | ) 331 | 332 | 333 | class PromptEncoding: 334 | """Namespace for different prompt encoding methods""" 335 | 336 | ENCODE_NODE = CLIPTextEncode() 337 | 338 | @staticmethod 339 | def encode_bag_of_subprompts( 340 | clip: CLIP, prefixes: list[str], suffixes: list[str] 341 | ) -> ComfyUIConditioning: 342 | """@Deprecated 343 | Simplified way to encode bag of subprompts without omost's greedy approach. 344 | """ 345 | conds: ComfyUIConditioning = [] 346 | 347 | logger.debug("Start encoding bag of subprompts") 348 | for target in suffixes: 349 | complete_prompt = "".join(prefixes + [target]) 350 | logger.debug(f"Encoding prompt: {complete_prompt}") 351 | cond: ComfyUIConditioning = PromptEncoding.ENCODE_NODE.encode( 352 | clip, complete_prompt 353 | )[0] 354 | assert len(cond) == 1 355 | conds.extend(cond) 356 | 357 | logger.debug("End encoding bag of subprompts. Total conditions: %d", len(conds)) 358 | 359 | # Concat all conditions 360 | return [ 361 | [ 362 | # cond 363 | torch.cat([cond for cond, _ in conds], dim=1), 364 | # extra_dict 365 | {"pooled_output": conds[0][1]["pooled_output"]}, 366 | ] 367 | ] 368 | 369 | @staticmethod 370 | def encode_subprompts( 371 | clip: CLIP, prefixes: list[str], suffixes: list[str] 372 | ) -> ComfyUIConditioning: 373 | """@Deprecated 374 | Simplified way to encode subprompts by joining them together. This is 375 | more direct without re-organizing the prompts into optimal batches like 376 | with the greedy approach. 377 | Note: This function has the issue of semantic truncation. 378 | """ 379 | complete_prompt = ",".join( 380 | ["".join(prefixes + [target]) for target in suffixes] 381 | ) 382 | logger.debug("Encoding prompt: %s", complete_prompt) 383 | return PromptEncoding.ENCODE_NODE.encode(clip, complete_prompt)[0] 384 | 385 | @staticmethod 386 | def encode_bag_of_subprompts_greedy( 387 | clip: CLIP, prefixes: list[str], suffixes: list[str] 388 | ) -> ComfyUIConditioning: 389 | """Encode bag of subprompts with greedy approach. This approach is used 390 | by the original Omost repo.""" 391 | 392 | def convert_comfy_tokens( 393 | comfy_tokens: list[ComfyCLIPTokensWithWeight], 394 | ) -> list[int]: 395 | assert len(comfy_tokens) >= 1 396 | tokens: list[int] = [token for token, _ in comfy_tokens[0]] 397 | # Strip the first token which is the CLIP prefix. 398 | # Strip padding tokens. 399 | return tokens[1 : tokens.index(SPECIAL_TOKENS["end"])] 400 | 401 | def convert_to_comfy_tokens(tokens: CLIPTokens) -> ComfyCLIPTokens: 402 | return { 403 | "l": [[(token, 1.0) for token in tokens.clip_l_tokens]], 404 | "g": ( 405 | [[(token, 1.0) for token in tokens.clip_g_tokens]] 406 | if tokens.clip_g_tokens is not None 407 | else None 408 | ), 409 | } 410 | 411 | def tokenize(text: str) -> CLIPTokens: 412 | tokens: ComfyCLIPTokens = clip.tokenize(text) 413 | return CLIPTokens( 414 | clip_l_tokens=convert_comfy_tokens(tokens["l"]), 415 | clip_g_tokens=( 416 | convert_comfy_tokens(tokens.get("g")) if "g" in tokens else None 417 | ), 418 | ) 419 | 420 | def encode(tokens: CLIPTokens) -> EncoderOutput: 421 | cond, pooled = clip.encode_from_tokens( 422 | convert_to_comfy_tokens(tokens), return_pooled=True 423 | ) 424 | return EncoderOutput(cond=cond, pooler=pooled) 425 | 426 | encoder_output = encode_bag_of_subprompts_greedy( 427 | prefixes, 428 | suffixes, 429 | tokenize_func=tokenize, 430 | encode_func=encode, 431 | logger=logger, 432 | ) 433 | 434 | return [ 435 | [ 436 | encoder_output.cond, 437 | {"pooled_output": encoder_output.pooler}, 438 | ] 439 | ] 440 | 441 | 442 | class OmostDenseDiffusionLayoutNode: 443 | """Apply Omost layout with Omost's area condition system. This is the regional 444 | prompt system implemented in the original Omost repo. 445 | 446 | You need to install https://github.com/huchenlei/ComfyUI_densediffusion to use this node. 447 | """ 448 | 449 | @classmethod 450 | def INPUT_TYPES(s): 451 | return { 452 | "required": { 453 | "model": ("MODEL",), 454 | "canvas_conds": ("OMOST_CANVAS_CONDITIONING",), 455 | "clip": ("CLIP",), 456 | }, 457 | } 458 | 459 | RETURN_TYPES = ("MODEL", "CONDITIONING") 460 | FUNCTION = "layout_cond" 461 | CATEGORY = "omost" 462 | 463 | def __init__(self): 464 | try: 465 | from custom_nodes.ComfyUI_densediffusion.densediffusion_node import ( 466 | DenseDiffusionApplyNode, 467 | DenseDiffusionAddCondNode, 468 | ) 469 | except Exception as e: 470 | logger.error( 471 | "Failed to import ComfyUI_densediffusion. Make sure it's installed." 472 | "https://github.com/huchenlei/ComfyUI_densediffusion" 473 | ) 474 | raise e 475 | 476 | self.dense_diffusion_apply_node = DenseDiffusionApplyNode() 477 | self.dense_diffusion_add_cond_node = DenseDiffusionAddCondNode() 478 | 479 | def layout_cond( 480 | self, 481 | model: ModelPatcher, 482 | canvas_conds: list[OmostCanvasCondition], 483 | clip: CLIP, 484 | ) -> tuple[ModelPatcher, ComfyUIConditioning]: 485 | """Layout conditioning""" 486 | work_model: ModelPatcher = model.clone() 487 | 488 | for canvas_cond in canvas_conds: 489 | cond: ComfyUIConditioning = PromptEncoding.encode_bag_of_subprompts_greedy( 490 | clip, canvas_cond["prefixes"], canvas_cond["suffixes"] 491 | ) 492 | # Set area cond 493 | work_model = self.dense_diffusion_add_cond_node.append( 494 | work_model, 495 | conditioning=cond, 496 | mask=OmostCanvas.render_mask(canvas_cond), 497 | strength=1.0, 498 | )[0] 499 | 500 | return self.dense_diffusion_apply_node.apply(work_model) 501 | 502 | 503 | class OmostGreedyBagsTextEmbeddingNode: 504 | """Just encode the omost canvas conditions with greedy bags approach. 505 | Ignoring region conditions.""" 506 | 507 | @classmethod 508 | def INPUT_TYPES(s): 509 | return { 510 | "required": { 511 | "canvas_conds": ("OMOST_CANVAS_CONDITIONING",), 512 | "clip": ("CLIP",), 513 | }, 514 | } 515 | 516 | RETURN_TYPES = ("CONDITIONING",) 517 | FUNCTION = "layout_cond" 518 | CATEGORY = "omost" 519 | 520 | def layout_cond( 521 | self, 522 | canvas_conds: list[OmostCanvasCondition], 523 | clip: CLIP, 524 | ) -> tuple[ComfyUIConditioning]: 525 | conds: ComfyUIConditioning = [ 526 | PromptEncoding.encode_bag_of_subprompts_greedy( 527 | clip, canvas_cond["prefixes"], canvas_cond["suffixes"] 528 | )[0] 529 | for canvas_cond in canvas_conds 530 | ] 531 | assert len(conds) > 0 532 | 533 | return ([ 534 | [ 535 | # cond 536 | torch.cat([cond[0] for cond in conds], dim=1), 537 | # pooled_output 538 | {"pooled_output": conds[0][1]["pooled_output"]}, 539 | ] 540 | ],) 541 | 542 | 543 | class OmostComfyLayoutNode: 544 | """Apply Omost layout with ComfyUI's area condition system.""" 545 | 546 | @classmethod 547 | def INPUT_TYPES(s): 548 | return { 549 | "required": { 550 | "canvas_conds": ("OMOST_CANVAS_CONDITIONING",), 551 | "clip": ("CLIP",), 552 | "global_strength": ( 553 | "FLOAT", 554 | {"min": 0.0, "max": 1.0, "step": 0.01, "default": 0.2}, 555 | ), 556 | "region_strength": ( 557 | "FLOAT", 558 | {"min": 0.0, "max": 1.0, "step": 0.01, "default": 0.8}, 559 | ), 560 | "overlap_method": ( 561 | [e.value for e in OmostComfyLayoutNode.AreaOverlapMethod], 562 | {"default": OmostComfyLayoutNode.AreaOverlapMethod.AVERAGE.value}, 563 | ), 564 | }, 565 | "optional": { 566 | "positive": ("CONDITIONING",), 567 | }, 568 | } 569 | 570 | RETURN_TYPES = ("CONDITIONING", "MASK") 571 | FUNCTION = "layout_cond" 572 | CATEGORY = "omost" 573 | 574 | class AreaOverlapMethod(Enum): 575 | """Methods to handle overlapping areas.""" 576 | 577 | # The top layer overwrites the bottom layer. 578 | OVERLAY = "overlay" 579 | # Take the average of the two layers. 580 | AVERAGE = "average" 581 | 582 | def __init__(self): 583 | self.cond_set_mask_node = ConditioningSetMask() 584 | 585 | @staticmethod 586 | def calc_cond_mask( 587 | canvas_conds: list[OmostCanvasCondition], 588 | method: AreaOverlapMethod = AreaOverlapMethod.OVERLAY, 589 | ) -> list[OmostCanvasCondition]: 590 | """Calculate canvas cond mask.""" 591 | assert len(canvas_conds) > 0 592 | canvas_conds = canvas_conds.copy() 593 | 594 | global_cond = canvas_conds[0] 595 | global_cond["mask"] = torch.ones( 596 | [CANVAS_SIZE, CANVAS_SIZE], dtype=torch.float32 597 | ) 598 | region_conds = canvas_conds[1:] 599 | 600 | canvas_state = torch.zeros([CANVAS_SIZE, CANVAS_SIZE], dtype=torch.float32) 601 | if method == OmostComfyLayoutNode.AreaOverlapMethod.OVERLAY: 602 | for canvas_cond in region_conds[::-1]: 603 | a, b, c, d = canvas_cond["rect"] 604 | mask = torch.zeros([CANVAS_SIZE, CANVAS_SIZE], dtype=torch.float32) 605 | mask[a:b, c:d] = 1.0 606 | mask = mask * (1 - canvas_state) 607 | canvas_state += mask 608 | canvas_cond["mask"] = mask 609 | elif method == OmostComfyLayoutNode.AreaOverlapMethod.AVERAGE: 610 | canvas_state += 1e-6 # Avoid division by zero 611 | for canvas_cond in region_conds: 612 | a, b, c, d = canvas_cond["rect"] 613 | canvas_state[a:b, c:d] += 1.0 614 | 615 | for canvas_cond in region_conds: 616 | a, b, c, d = canvas_cond["rect"] 617 | mask = torch.zeros([CANVAS_SIZE, CANVAS_SIZE], dtype=torch.float32) 618 | mask[a:b, c:d] = 1.0 619 | mask = mask / canvas_state 620 | canvas_cond["mask"] = mask 621 | 622 | return canvas_conds 623 | 624 | def layout_cond( 625 | self, 626 | canvas_conds: list[OmostCanvasCondition], 627 | clip: CLIP, 628 | global_strength: float, 629 | region_strength: float, 630 | overlap_method: str, 631 | positive: ComfyUIConditioning | None = None, 632 | ): 633 | """Layout conditioning""" 634 | overlap_method = OmostComfyLayoutNode.AreaOverlapMethod(overlap_method) 635 | positive: ComfyUIConditioning = positive or [] 636 | positive = positive.copy() 637 | masks: list[torch.Tensor] = [] 638 | canvas_conds = OmostComfyLayoutNode.calc_cond_mask( 639 | canvas_conds, method=overlap_method 640 | ) 641 | 642 | for i, canvas_cond in enumerate(canvas_conds): 643 | is_global = i == 0 644 | 645 | prefixes = canvas_cond["prefixes"] 646 | # Skip the global prefix for region prompts. 647 | if not is_global: 648 | prefixes = prefixes[1:] 649 | 650 | cond: ComfyUIConditioning = PromptEncoding.encode_bag_of_subprompts_greedy( 651 | clip, prefixes, canvas_cond["suffixes"] 652 | ) 653 | # Set area cond 654 | cond: ComfyUIConditioning = self.cond_set_mask_node.append( 655 | cond, 656 | mask=canvas_cond["mask"], 657 | set_cond_area="default", 658 | strength=global_strength if is_global else region_strength, 659 | )[0] 660 | assert len(cond) == 1 661 | positive.extend(cond) 662 | masks.append(canvas_cond["mask"].unsqueeze(0)) 663 | 664 | return ( 665 | positive, 666 | # Output masks in case it's needed for debugging or the user might 667 | # want to apply extra condition such as ControlNet/IPAdapter to 668 | # specified region. 669 | torch.cat(masks, dim=0), 670 | ) 671 | 672 | 673 | class OmostLoadCanvasConditioningNode: 674 | @classmethod 675 | def INPUT_TYPES(s): 676 | return { 677 | "required": { 678 | "json_str": ("STRING", {"multiline": True}), 679 | } 680 | } 681 | 682 | RETURN_TYPES = ("OMOST_CANVAS_CONDITIONING",) 683 | FUNCTION = "load_canvas" 684 | CATEGORY = "omost" 685 | 686 | def load_canvas(self, json_str: str) -> Tuple[list[OmostCanvasCondition]]: 687 | """Load canvas from file""" 688 | return (json.loads(json_str),) 689 | 690 | 691 | class OmostLoadCanvasPythonCodeNode: 692 | """Load python code generated by Omost demo app.""" 693 | @classmethod 694 | def INPUT_TYPES(s): 695 | return { 696 | "required": { 697 | "python_str": ("STRING", {"multiline": True}), 698 | } 699 | } 700 | 701 | RETURN_TYPES = ("OMOST_CANVAS_CONDITIONING",) 702 | FUNCTION = "load_canvas" 703 | CATEGORY = "omost" 704 | 705 | def load_canvas(self, python_str: str) -> Tuple[list[OmostCanvasCondition]]: 706 | """Load canvas from file""" 707 | canvas = OmostCanvas.from_python_code(python_str) 708 | return (canvas.process(),) 709 | 710 | 711 | NODE_CLASS_MAPPINGS = { 712 | "OmostLLMLoaderNode": OmostLLMLoaderNode, 713 | "OmostLLMHTTPServerNode": OmostLLMHTTPServerNode, 714 | "OmostLLMChatNode": OmostLLMChatNode, 715 | "OmostGreedyBagsTextEmbeddingNode": OmostGreedyBagsTextEmbeddingNode, 716 | "OmostLayoutCondNode": OmostComfyLayoutNode, 717 | "OmostDenseDiffusionLayoutNode": OmostDenseDiffusionLayoutNode, 718 | "OmostLoadCanvasConditioningNode": OmostLoadCanvasConditioningNode, 719 | "OmostLoadCanvasPythonCodeNode": OmostLoadCanvasPythonCodeNode, 720 | "OmostRenderCanvasConditioningNode": OmostRenderCanvasConditioningNode, 721 | } 722 | 723 | NODE_DISPLAY_NAME_MAPPINGS = { 724 | "OmostLLMLoaderNode": "Omost LLM Loader", 725 | "OmostLLMHTTPServerNode": "Omost LLM HTTP Server", 726 | "OmostLLMChatNode": "Omost LLM Chat", 727 | "OmostGreedyBagsTextEmbeddingNode": "Omost Greedy Bags Text Embedding", 728 | "OmostLayoutCondNode": "Omost Layout Cond (ComfyUI-Area)", 729 | "OmostDenseDiffusionLayoutNode": "Omost Layout Cond (OmostDenseDiffusion)", 730 | "OmostLoadCanvasConditioningNode": "Omost Load Canvas Conditioning", 731 | "OmostLoadCanvasPythonCodeNode": "Omost Load Canvas Python Code", 732 | "OmostRenderCanvasConditioningNode": "Omost Render Canvas Conditioning", 733 | } 734 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "comfyui_omost" 3 | description = "Your image is almost there!" 4 | version = "1.0.3" 5 | license = { file = "LICENSE" } 6 | dependencies = ["transformers>=4.41.1", "bitsandbytes>=0.43.1", "protobuf>=3.20", "torch", "openai", "requests"] 7 | 8 | [project.urls] 9 | Repository = "https://github.com/huchenlei/ComfyUI_omost" 10 | # Used by Comfy Registry https://comfyregistry.org 11 | 12 | [tool.comfy] 13 | PublisherId = "huchenlei" 14 | DisplayName = "ComfyUI_omost" 15 | Icon = "" 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | transformers>=4.41.1 2 | bitsandbytes>=0.43.1 3 | protobuf>=3.20 4 | torch 5 | openai 6 | requests -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huchenlei/ComfyUI_omost/914b06c7a563504a61fe21d3bead1b20c3d3be37/tests/__init__.py -------------------------------------------------------------------------------- /tests/greedy_encode_test.py: -------------------------------------------------------------------------------- 1 | from ..lib_omost.greedy_encode import greedy_partition, CLIPTokens 2 | 3 | 4 | def test_greedy_partition(): 5 | """Test with Omost repo example.""" 6 | items = [ 7 | CLIPTokens(clip_l_tokens=[i] * length) 8 | for i, length in enumerate([25, 35, 5, 60, 15, 25]) 9 | ] 10 | bags = greedy_partition(items, max_sum=70) 11 | assert bags == [ 12 | [items[0], items[1], items[2]], 13 | [items[3]], 14 | [items[4], items[5]], 15 | ] 16 | --------------------------------------------------------------------------------