Spaces:
Running
on
Zero
Running
on
Zero
Upload 836 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +4 -35
- .gitignore +23 -0
- .gradio/certificate.pem +31 -0
- CODEOWNERS +24 -0
- CONTRIBUTING.md +41 -0
- LICENSE +674 -0
- README.md +381 -13
- __pycache__/comfyui_version.cpython-312.pyc +0 -0
- __pycache__/cuda_malloc.cpython-312.pyc +0 -0
- __pycache__/execution.cpython-312.pyc +0 -0
- __pycache__/folder_paths.cpython-312.pyc +0 -0
- __pycache__/latent_preview.cpython-312.pyc +0 -0
- __pycache__/main.cpython-312.pyc +0 -0
- __pycache__/node_helpers.cpython-312.pyc +0 -0
- __pycache__/nodes.cpython-312.pyc +3 -0
- __pycache__/server.cpython-312.pyc +0 -0
- api_server/__init__.py +0 -0
- api_server/__pycache__/__init__.cpython-312.pyc +0 -0
- api_server/routes/__init__.py +0 -0
- api_server/routes/__pycache__/__init__.cpython-312.pyc +0 -0
- api_server/routes/internal/README.md +3 -0
- api_server/routes/internal/__init__.py +0 -0
- api_server/routes/internal/__pycache__/__init__.cpython-312.pyc +0 -0
- api_server/routes/internal/__pycache__/internal_routes.cpython-312.pyc +0 -0
- api_server/routes/internal/internal_routes.py +73 -0
- api_server/services/__init__.py +0 -0
- api_server/services/__pycache__/__init__.cpython-312.pyc +0 -0
- api_server/services/__pycache__/terminal_service.cpython-312.pyc +0 -0
- api_server/services/terminal_service.py +60 -0
- api_server/utils/file_operations.py +42 -0
- app.py +201 -0
- app/__init__.py +0 -0
- app/__pycache__/__init__.cpython-312.pyc +0 -0
- app/__pycache__/app_settings.cpython-312.pyc +0 -0
- app/__pycache__/custom_node_manager.cpython-312.pyc +0 -0
- app/__pycache__/frontend_management.cpython-312.pyc +0 -0
- app/__pycache__/logger.cpython-312.pyc +0 -0
- app/__pycache__/model_manager.cpython-312.pyc +0 -0
- app/__pycache__/user_manager.cpython-312.pyc +0 -0
- app/app_settings.py +65 -0
- app/custom_node_manager.py +134 -0
- app/frontend_management.py +309 -0
- app/logger.py +98 -0
- app/model_manager.py +184 -0
- app/user_manager.py +330 -0
- comfy/__pycache__/checkpoint_pickle.cpython-312.pyc +0 -0
- comfy/__pycache__/cli_args.cpython-312.pyc +0 -0
- comfy/__pycache__/clip_model.cpython-312.pyc +0 -0
- comfy/__pycache__/clip_vision.cpython-312.pyc +0 -0
- comfy/__pycache__/conds.cpython-312.pyc +0 -0
.gitattributes
CHANGED
@@ -1,35 +1,4 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
1 |
+
/web/assets/** linguist-generated
|
2 |
+
/web/** linguist-vendored
|
3 |
+
__pycache__/nodes.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
4 |
+
comfy/text_encoders/t5_pile_tokenizer/tokenizer.model filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
*.py[cod]
|
3 |
+
/output/
|
4 |
+
/input/
|
5 |
+
!/input/example.png
|
6 |
+
/models/
|
7 |
+
/temp/
|
8 |
+
/custom_nodes/
|
9 |
+
!custom_nodes/example_node.py.example
|
10 |
+
extra_model_paths.yaml
|
11 |
+
/.vs
|
12 |
+
.vscode/
|
13 |
+
.idea/
|
14 |
+
venv/
|
15 |
+
.venv/
|
16 |
+
/web/extensions/*
|
17 |
+
!/web/extensions/logging.js.example
|
18 |
+
!/web/extensions/core/
|
19 |
+
/tests-ui/data/object_info.json
|
20 |
+
/user/
|
21 |
+
*.log
|
22 |
+
web_custom_versions/
|
23 |
+
.DS_Store
|
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
|
12 |
+
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
|
13 |
+
B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
|
14 |
+
KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
|
15 |
+
OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
|
16 |
+
jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
|
17 |
+
qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
|
18 |
+
rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
|
19 |
+
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
|
20 |
+
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
|
21 |
+
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
|
22 |
+
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
|
23 |
+
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
24 |
+
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
25 |
+
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
CODEOWNERS
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Admins
|
2 |
+
* @comfyanonymous
|
3 |
+
|
4 |
+
# Note: Github teams syntax cannot be used here as the repo is not owned by Comfy-Org.
|
5 |
+
# Inlined the team members for now.
|
6 |
+
|
7 |
+
# Maintainers
|
8 |
+
*.md @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
9 |
+
/tests/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
10 |
+
/tests-unit/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
11 |
+
/notebooks/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
12 |
+
/script_examples/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
13 |
+
/.github/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
14 |
+
/requirements.txt @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
15 |
+
/pyproject.toml @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @Kosinkadink @christian-byrne
|
16 |
+
|
17 |
+
# Python web server
|
18 |
+
/api_server/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @christian-byrne
|
19 |
+
/app/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @christian-byrne
|
20 |
+
/utils/ @yoland68 @robinjhuang @huchenlei @webfiltered @pythongosssss @ltdrdata @christian-byrne
|
21 |
+
|
22 |
+
# Node developers
|
23 |
+
/comfy_extras/ @yoland68 @robinjhuang @huchenlei @pythongosssss @ltdrdata @Kosinkadink @webfiltered @christian-byrne
|
24 |
+
/comfy/comfy_types/ @yoland68 @robinjhuang @huchenlei @pythongosssss @ltdrdata @Kosinkadink @webfiltered @christian-byrne
|
CONTRIBUTING.md
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Contributing to ComfyUI
|
2 |
+
|
3 |
+
Welcome, and thank you for your interest in contributing to ComfyUI!
|
4 |
+
|
5 |
+
There are several ways in which you can contribute, beyond writing code. The goal of this document is to provide a high-level overview of how you can get involved.
|
6 |
+
|
7 |
+
## Asking Questions
|
8 |
+
|
9 |
+
Have a question? Instead of opening an issue, please ask on [Discord](https://comfy.org/discord) or [Matrix](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) channels. Our team and the community will help you.
|
10 |
+
|
11 |
+
## Providing Feedback
|
12 |
+
|
13 |
+
Your comments and feedback are welcome, and the development team is available via a handful of different channels.
|
14 |
+
|
15 |
+
See the `#bug-report`, `#feature-request` and `#feedback` channels on Discord.
|
16 |
+
|
17 |
+
## Reporting Issues
|
18 |
+
|
19 |
+
Have you identified a reproducible problem in ComfyUI? Do you have a feature request? We want to hear about it! Here's how you can report your issue as effectively as possible.
|
20 |
+
|
21 |
+
|
22 |
+
### Look For an Existing Issue
|
23 |
+
|
24 |
+
Before you create a new issue, please do a search in [open issues](https://github.com/comfyanonymous/ComfyUI/issues) to see if the issue or feature request has already been filed.
|
25 |
+
|
26 |
+
If you find your issue already exists, make relevant comments and add your [reaction](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments). Use a reaction in place of a "+1" comment:
|
27 |
+
|
28 |
+
* 👍 - upvote
|
29 |
+
* 👎 - downvote
|
30 |
+
|
31 |
+
If you cannot find an existing issue that describes your bug or feature, create a new issue. We have an issue template in place to organize new issues.
|
32 |
+
|
33 |
+
|
34 |
+
### Creating Pull Requests
|
35 |
+
|
36 |
+
* Please refer to the article on [creating pull requests](https://github.com/comfyanonymous/ComfyUI/wiki/How-to-Contribute-Code) and contributing to this project.
|
37 |
+
|
38 |
+
|
39 |
+
## Thank You
|
40 |
+
|
41 |
+
Your contributions to open source, large or small, make great projects like this possible. Thank you for taking the time to contribute.
|
LICENSE
ADDED
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 29 June 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works.
|
12 |
+
|
13 |
+
The licenses for most software and other practical works are designed
|
14 |
+
to take away your freedom to share and change the works. By contrast,
|
15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
16 |
+
share and change all versions of a program--to make sure it remains free
|
17 |
+
software for all its users. We, the Free Software Foundation, use the
|
18 |
+
GNU General Public License for most of our software; it applies also to
|
19 |
+
any other work released this way by its authors. You can apply it to
|
20 |
+
your programs, too.
|
21 |
+
|
22 |
+
When we speak of free software, we are referring to freedom, not
|
23 |
+
price. Our General Public Licenses are designed to make sure that you
|
24 |
+
have the freedom to distribute copies of free software (and charge for
|
25 |
+
them if you wish), that you receive source code or can get it if you
|
26 |
+
want it, that you can change the software or use pieces of it in new
|
27 |
+
free programs, and that you know you can do these things.
|
28 |
+
|
29 |
+
To protect your rights, we need to prevent others from denying you
|
30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
31 |
+
certain responsibilities if you distribute copies of the software, or if
|
32 |
+
you modify it: responsibilities to respect the freedom of others.
|
33 |
+
|
34 |
+
For example, if you distribute copies of such a program, whether
|
35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
36 |
+
freedoms that you received. You must make sure that they, too, receive
|
37 |
+
or can get the source code. And you must show them these terms so they
|
38 |
+
know their rights.
|
39 |
+
|
40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
43 |
+
|
44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
45 |
+
that there is no warranty for this free software. For both users' and
|
46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
47 |
+
changed, so that their problems will not be attributed erroneously to
|
48 |
+
authors of previous versions.
|
49 |
+
|
50 |
+
Some devices are designed to deny users access to install or run
|
51 |
+
modified versions of the software inside them, although the manufacturer
|
52 |
+
can do so. This is fundamentally incompatible with the aim of
|
53 |
+
protecting users' freedom to change the software. The systematic
|
54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
56 |
+
have designed this version of the GPL to prohibit the practice for those
|
57 |
+
products. If such problems arise substantially in other domains, we
|
58 |
+
stand ready to extend this provision to those domains in future versions
|
59 |
+
of the GPL, as needed to protect the freedom of users.
|
60 |
+
|
61 |
+
Finally, every program is threatened constantly by software patents.
|
62 |
+
States should not allow patents to restrict development and use of
|
63 |
+
software on general-purpose computers, but in those that do, we wish to
|
64 |
+
avoid the special danger that patents applied to a free program could
|
65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
66 |
+
patents cannot be used to render the program non-free.
|
67 |
+
|
68 |
+
The precise terms and conditions for copying, distribution and
|
69 |
+
modification follow.
|
70 |
+
|
71 |
+
TERMS AND CONDITIONS
|
72 |
+
|
73 |
+
0. Definitions.
|
74 |
+
|
75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
76 |
+
|
77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
78 |
+
works, such as semiconductor masks.
|
79 |
+
|
80 |
+
"The Program" refers to any copyrightable work licensed under this
|
81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
82 |
+
"recipients" may be individuals or organizations.
|
83 |
+
|
84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
85 |
+
in a fashion requiring copyright permission, other than the making of an
|
86 |
+
exact copy. The resulting work is called a "modified version" of the
|
87 |
+
earlier work or a work "based on" the earlier work.
|
88 |
+
|
89 |
+
A "covered work" means either the unmodified Program or a work based
|
90 |
+
on the Program.
|
91 |
+
|
92 |
+
To "propagate" a work means to do anything with it that, without
|
93 |
+
permission, would make you directly or secondarily liable for
|
94 |
+
infringement under applicable copyright law, except executing it on a
|
95 |
+
computer or modifying a private copy. Propagation includes copying,
|
96 |
+
distribution (with or without modification), making available to the
|
97 |
+
public, and in some countries other activities as well.
|
98 |
+
|
99 |
+
To "convey" a work means any kind of propagation that enables other
|
100 |
+
parties to make or receive copies. Mere interaction with a user through
|
101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
102 |
+
|
103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
104 |
+
to the extent that it includes a convenient and prominently visible
|
105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
106 |
+
tells the user that there is no warranty for the work (except to the
|
107 |
+
extent that warranties are provided), that licensees may convey the
|
108 |
+
work under this License, and how to view a copy of this License. If
|
109 |
+
the interface presents a list of user commands or options, such as a
|
110 |
+
menu, a prominent item in the list meets this criterion.
|
111 |
+
|
112 |
+
1. Source Code.
|
113 |
+
|
114 |
+
The "source code" for a work means the preferred form of the work
|
115 |
+
for making modifications to it. "Object code" means any non-source
|
116 |
+
form of a work.
|
117 |
+
|
118 |
+
A "Standard Interface" means an interface that either is an official
|
119 |
+
standard defined by a recognized standards body, or, in the case of
|
120 |
+
interfaces specified for a particular programming language, one that
|
121 |
+
is widely used among developers working in that language.
|
122 |
+
|
123 |
+
The "System Libraries" of an executable work include anything, other
|
124 |
+
than the work as a whole, that (a) is included in the normal form of
|
125 |
+
packaging a Major Component, but which is not part of that Major
|
126 |
+
Component, and (b) serves only to enable use of the work with that
|
127 |
+
Major Component, or to implement a Standard Interface for which an
|
128 |
+
implementation is available to the public in source code form. A
|
129 |
+
"Major Component", in this context, means a major essential component
|
130 |
+
(kernel, window system, and so on) of the specific operating system
|
131 |
+
(if any) on which the executable work runs, or a compiler used to
|
132 |
+
produce the work, or an object code interpreter used to run it.
|
133 |
+
|
134 |
+
The "Corresponding Source" for a work in object code form means all
|
135 |
+
the source code needed to generate, install, and (for an executable
|
136 |
+
work) run the object code and to modify the work, including scripts to
|
137 |
+
control those activities. However, it does not include the work's
|
138 |
+
System Libraries, or general-purpose tools or generally available free
|
139 |
+
programs which are used unmodified in performing those activities but
|
140 |
+
which are not part of the work. For example, Corresponding Source
|
141 |
+
includes interface definition files associated with source files for
|
142 |
+
the work, and the source code for shared libraries and dynamically
|
143 |
+
linked subprograms that the work is specifically designed to require,
|
144 |
+
such as by intimate data communication or control flow between those
|
145 |
+
subprograms and other parts of the work.
|
146 |
+
|
147 |
+
The Corresponding Source need not include anything that users
|
148 |
+
can regenerate automatically from other parts of the Corresponding
|
149 |
+
Source.
|
150 |
+
|
151 |
+
The Corresponding Source for a work in source code form is that
|
152 |
+
same work.
|
153 |
+
|
154 |
+
2. Basic Permissions.
|
155 |
+
|
156 |
+
All rights granted under this License are granted for the term of
|
157 |
+
copyright on the Program, and are irrevocable provided the stated
|
158 |
+
conditions are met. This License explicitly affirms your unlimited
|
159 |
+
permission to run the unmodified Program. The output from running a
|
160 |
+
covered work is covered by this License only if the output, given its
|
161 |
+
content, constitutes a covered work. This License acknowledges your
|
162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
163 |
+
|
164 |
+
You may make, run and propagate covered works that you do not
|
165 |
+
convey, without conditions so long as your license otherwise remains
|
166 |
+
in force. You may convey covered works to others for the sole purpose
|
167 |
+
of having them make modifications exclusively for you, or provide you
|
168 |
+
with facilities for running those works, provided that you comply with
|
169 |
+
the terms of this License in conveying all material for which you do
|
170 |
+
not control copyright. Those thus making or running the covered works
|
171 |
+
for you must do so exclusively on your behalf, under your direction
|
172 |
+
and control, on terms that prohibit them from making any copies of
|
173 |
+
your copyrighted material outside their relationship with you.
|
174 |
+
|
175 |
+
Conveying under any other circumstances is permitted solely under
|
176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
177 |
+
makes it unnecessary.
|
178 |
+
|
179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
180 |
+
|
181 |
+
No covered work shall be deemed part of an effective technological
|
182 |
+
measure under any applicable law fulfilling obligations under article
|
183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
184 |
+
similar laws prohibiting or restricting circumvention of such
|
185 |
+
measures.
|
186 |
+
|
187 |
+
When you convey a covered work, you waive any legal power to forbid
|
188 |
+
circumvention of technological measures to the extent such circumvention
|
189 |
+
is effected by exercising rights under this License with respect to
|
190 |
+
the covered work, and you disclaim any intention to limit operation or
|
191 |
+
modification of the work as a means of enforcing, against the work's
|
192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
193 |
+
technological measures.
|
194 |
+
|
195 |
+
4. Conveying Verbatim Copies.
|
196 |
+
|
197 |
+
You may convey verbatim copies of the Program's source code as you
|
198 |
+
receive it, in any medium, provided that you conspicuously and
|
199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
200 |
+
keep intact all notices stating that this License and any
|
201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
202 |
+
keep intact all notices of the absence of any warranty; and give all
|
203 |
+
recipients a copy of this License along with the Program.
|
204 |
+
|
205 |
+
You may charge any price or no price for each copy that you convey,
|
206 |
+
and you may offer support or warranty protection for a fee.
|
207 |
+
|
208 |
+
5. Conveying Modified Source Versions.
|
209 |
+
|
210 |
+
You may convey a work based on the Program, or the modifications to
|
211 |
+
produce it from the Program, in the form of source code under the
|
212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
213 |
+
|
214 |
+
a) The work must carry prominent notices stating that you modified
|
215 |
+
it, and giving a relevant date.
|
216 |
+
|
217 |
+
b) The work must carry prominent notices stating that it is
|
218 |
+
released under this License and any conditions added under section
|
219 |
+
7. This requirement modifies the requirement in section 4 to
|
220 |
+
"keep intact all notices".
|
221 |
+
|
222 |
+
c) You must license the entire work, as a whole, under this
|
223 |
+
License to anyone who comes into possession of a copy. This
|
224 |
+
License will therefore apply, along with any applicable section 7
|
225 |
+
additional terms, to the whole of the work, and all its parts,
|
226 |
+
regardless of how they are packaged. This License gives no
|
227 |
+
permission to license the work in any other way, but it does not
|
228 |
+
invalidate such permission if you have separately received it.
|
229 |
+
|
230 |
+
d) If the work has interactive user interfaces, each must display
|
231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
233 |
+
work need not make them do so.
|
234 |
+
|
235 |
+
A compilation of a covered work with other separate and independent
|
236 |
+
works, which are not by their nature extensions of the covered work,
|
237 |
+
and which are not combined with it such as to form a larger program,
|
238 |
+
in or on a volume of a storage or distribution medium, is called an
|
239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
240 |
+
used to limit the access or legal rights of the compilation's users
|
241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
242 |
+
in an aggregate does not cause this License to apply to the other
|
243 |
+
parts of the aggregate.
|
244 |
+
|
245 |
+
6. Conveying Non-Source Forms.
|
246 |
+
|
247 |
+
You may convey a covered work in object code form under the terms
|
248 |
+
of sections 4 and 5, provided that you also convey the
|
249 |
+
machine-readable Corresponding Source under the terms of this License,
|
250 |
+
in one of these ways:
|
251 |
+
|
252 |
+
a) Convey the object code in, or embodied in, a physical product
|
253 |
+
(including a physical distribution medium), accompanied by the
|
254 |
+
Corresponding Source fixed on a durable physical medium
|
255 |
+
customarily used for software interchange.
|
256 |
+
|
257 |
+
b) Convey the object code in, or embodied in, a physical product
|
258 |
+
(including a physical distribution medium), accompanied by a
|
259 |
+
written offer, valid for at least three years and valid for as
|
260 |
+
long as you offer spare parts or customer support for that product
|
261 |
+
model, to give anyone who possesses the object code either (1) a
|
262 |
+
copy of the Corresponding Source for all the software in the
|
263 |
+
product that is covered by this License, on a durable physical
|
264 |
+
medium customarily used for software interchange, for a price no
|
265 |
+
more than your reasonable cost of physically performing this
|
266 |
+
conveying of source, or (2) access to copy the
|
267 |
+
Corresponding Source from a network server at no charge.
|
268 |
+
|
269 |
+
c) Convey individual copies of the object code with a copy of the
|
270 |
+
written offer to provide the Corresponding Source. This
|
271 |
+
alternative is allowed only occasionally and noncommercially, and
|
272 |
+
only if you received the object code with such an offer, in accord
|
273 |
+
with subsection 6b.
|
274 |
+
|
275 |
+
d) Convey the object code by offering access from a designated
|
276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
277 |
+
Corresponding Source in the same way through the same place at no
|
278 |
+
further charge. You need not require recipients to copy the
|
279 |
+
Corresponding Source along with the object code. If the place to
|
280 |
+
copy the object code is a network server, the Corresponding Source
|
281 |
+
may be on a different server (operated by you or a third party)
|
282 |
+
that supports equivalent copying facilities, provided you maintain
|
283 |
+
clear directions next to the object code saying where to find the
|
284 |
+
Corresponding Source. Regardless of what server hosts the
|
285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
286 |
+
available for as long as needed to satisfy these requirements.
|
287 |
+
|
288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
289 |
+
you inform other peers where the object code and Corresponding
|
290 |
+
Source of the work are being offered to the general public at no
|
291 |
+
charge under subsection 6d.
|
292 |
+
|
293 |
+
A separable portion of the object code, whose source code is excluded
|
294 |
+
from the Corresponding Source as a System Library, need not be
|
295 |
+
included in conveying the object code work.
|
296 |
+
|
297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
298 |
+
tangible personal property which is normally used for personal, family,
|
299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
302 |
+
product received by a particular user, "normally used" refers to a
|
303 |
+
typical or common use of that class of product, regardless of the status
|
304 |
+
of the particular user or of the way in which the particular user
|
305 |
+
actually uses, or expects or is expected to use, the product. A product
|
306 |
+
is a consumer product regardless of whether the product has substantial
|
307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
308 |
+
the only significant mode of use of the product.
|
309 |
+
|
310 |
+
"Installation Information" for a User Product means any methods,
|
311 |
+
procedures, authorization keys, or other information required to install
|
312 |
+
and execute modified versions of a covered work in that User Product from
|
313 |
+
a modified version of its Corresponding Source. The information must
|
314 |
+
suffice to ensure that the continued functioning of the modified object
|
315 |
+
code is in no case prevented or interfered with solely because
|
316 |
+
modification has been made.
|
317 |
+
|
318 |
+
If you convey an object code work under this section in, or with, or
|
319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
320 |
+
part of a transaction in which the right of possession and use of the
|
321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
322 |
+
fixed term (regardless of how the transaction is characterized), the
|
323 |
+
Corresponding Source conveyed under this section must be accompanied
|
324 |
+
by the Installation Information. But this requirement does not apply
|
325 |
+
if neither you nor any third party retains the ability to install
|
326 |
+
modified object code on the User Product (for example, the work has
|
327 |
+
been installed in ROM).
|
328 |
+
|
329 |
+
The requirement to provide Installation Information does not include a
|
330 |
+
requirement to continue to provide support service, warranty, or updates
|
331 |
+
for a work that has been modified or installed by the recipient, or for
|
332 |
+
the User Product in which it has been modified or installed. Access to a
|
333 |
+
network may be denied when the modification itself materially and
|
334 |
+
adversely affects the operation of the network or violates the rules and
|
335 |
+
protocols for communication across the network.
|
336 |
+
|
337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
338 |
+
in accord with this section must be in a format that is publicly
|
339 |
+
documented (and with an implementation available to the public in
|
340 |
+
source code form), and must require no special password or key for
|
341 |
+
unpacking, reading or copying.
|
342 |
+
|
343 |
+
7. Additional Terms.
|
344 |
+
|
345 |
+
"Additional permissions" are terms that supplement the terms of this
|
346 |
+
License by making exceptions from one or more of its conditions.
|
347 |
+
Additional permissions that are applicable to the entire Program shall
|
348 |
+
be treated as though they were included in this License, to the extent
|
349 |
+
that they are valid under applicable law. If additional permissions
|
350 |
+
apply only to part of the Program, that part may be used separately
|
351 |
+
under those permissions, but the entire Program remains governed by
|
352 |
+
this License without regard to the additional permissions.
|
353 |
+
|
354 |
+
When you convey a copy of a covered work, you may at your option
|
355 |
+
remove any additional permissions from that copy, or from any part of
|
356 |
+
it. (Additional permissions may be written to require their own
|
357 |
+
removal in certain cases when you modify the work.) You may place
|
358 |
+
additional permissions on material, added by you to a covered work,
|
359 |
+
for which you have or can give appropriate copyright permission.
|
360 |
+
|
361 |
+
Notwithstanding any other provision of this License, for material you
|
362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
363 |
+
that material) supplement the terms of this License with terms:
|
364 |
+
|
365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
366 |
+
terms of sections 15 and 16 of this License; or
|
367 |
+
|
368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
369 |
+
author attributions in that material or in the Appropriate Legal
|
370 |
+
Notices displayed by works containing it; or
|
371 |
+
|
372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
373 |
+
requiring that modified versions of such material be marked in
|
374 |
+
reasonable ways as different from the original version; or
|
375 |
+
|
376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
377 |
+
authors of the material; or
|
378 |
+
|
379 |
+
e) Declining to grant rights under trademark law for use of some
|
380 |
+
trade names, trademarks, or service marks; or
|
381 |
+
|
382 |
+
f) Requiring indemnification of licensors and authors of that
|
383 |
+
material by anyone who conveys the material (or modified versions of
|
384 |
+
it) with contractual assumptions of liability to the recipient, for
|
385 |
+
any liability that these contractual assumptions directly impose on
|
386 |
+
those licensors and authors.
|
387 |
+
|
388 |
+
All other non-permissive additional terms are considered "further
|
389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
390 |
+
received it, or any part of it, contains a notice stating that it is
|
391 |
+
governed by this License along with a term that is a further
|
392 |
+
restriction, you may remove that term. If a license document contains
|
393 |
+
a further restriction but permits relicensing or conveying under this
|
394 |
+
License, you may add to a covered work material governed by the terms
|
395 |
+
of that license document, provided that the further restriction does
|
396 |
+
not survive such relicensing or conveying.
|
397 |
+
|
398 |
+
If you add terms to a covered work in accord with this section, you
|
399 |
+
must place, in the relevant source files, a statement of the
|
400 |
+
additional terms that apply to those files, or a notice indicating
|
401 |
+
where to find the applicable terms.
|
402 |
+
|
403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
404 |
+
form of a separately written license, or stated as exceptions;
|
405 |
+
the above requirements apply either way.
|
406 |
+
|
407 |
+
8. Termination.
|
408 |
+
|
409 |
+
You may not propagate or modify a covered work except as expressly
|
410 |
+
provided under this License. Any attempt otherwise to propagate or
|
411 |
+
modify it is void, and will automatically terminate your rights under
|
412 |
+
this License (including any patent licenses granted under the third
|
413 |
+
paragraph of section 11).
|
414 |
+
|
415 |
+
However, if you cease all violation of this License, then your
|
416 |
+
license from a particular copyright holder is reinstated (a)
|
417 |
+
provisionally, unless and until the copyright holder explicitly and
|
418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
419 |
+
holder fails to notify you of the violation by some reasonable means
|
420 |
+
prior to 60 days after the cessation.
|
421 |
+
|
422 |
+
Moreover, your license from a particular copyright holder is
|
423 |
+
reinstated permanently if the copyright holder notifies you of the
|
424 |
+
violation by some reasonable means, this is the first time you have
|
425 |
+
received notice of violation of this License (for any work) from that
|
426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
427 |
+
your receipt of the notice.
|
428 |
+
|
429 |
+
Termination of your rights under this section does not terminate the
|
430 |
+
licenses of parties who have received copies or rights from you under
|
431 |
+
this License. If your rights have been terminated and not permanently
|
432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
433 |
+
material under section 10.
|
434 |
+
|
435 |
+
9. Acceptance Not Required for Having Copies.
|
436 |
+
|
437 |
+
You are not required to accept this License in order to receive or
|
438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
440 |
+
to receive a copy likewise does not require acceptance. However,
|
441 |
+
nothing other than this License grants you permission to propagate or
|
442 |
+
modify any covered work. These actions infringe copyright if you do
|
443 |
+
not accept this License. Therefore, by modifying or propagating a
|
444 |
+
covered work, you indicate your acceptance of this License to do so.
|
445 |
+
|
446 |
+
10. Automatic Licensing of Downstream Recipients.
|
447 |
+
|
448 |
+
Each time you convey a covered work, the recipient automatically
|
449 |
+
receives a license from the original licensors, to run, modify and
|
450 |
+
propagate that work, subject to this License. You are not responsible
|
451 |
+
for enforcing compliance by third parties with this License.
|
452 |
+
|
453 |
+
An "entity transaction" is a transaction transferring control of an
|
454 |
+
organization, or substantially all assets of one, or subdividing an
|
455 |
+
organization, or merging organizations. If propagation of a covered
|
456 |
+
work results from an entity transaction, each party to that
|
457 |
+
transaction who receives a copy of the work also receives whatever
|
458 |
+
licenses to the work the party's predecessor in interest had or could
|
459 |
+
give under the previous paragraph, plus a right to possession of the
|
460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
461 |
+
the predecessor has it or can get it with reasonable efforts.
|
462 |
+
|
463 |
+
You may not impose any further restrictions on the exercise of the
|
464 |
+
rights granted or affirmed under this License. For example, you may
|
465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
466 |
+
rights granted under this License, and you may not initiate litigation
|
467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
468 |
+
any patent claim is infringed by making, using, selling, offering for
|
469 |
+
sale, or importing the Program or any portion of it.
|
470 |
+
|
471 |
+
11. Patents.
|
472 |
+
|
473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
474 |
+
License of the Program or a work on which the Program is based. The
|
475 |
+
work thus licensed is called the contributor's "contributor version".
|
476 |
+
|
477 |
+
A contributor's "essential patent claims" are all patent claims
|
478 |
+
owned or controlled by the contributor, whether already acquired or
|
479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
480 |
+
by this License, of making, using, or selling its contributor version,
|
481 |
+
but do not include claims that would be infringed only as a
|
482 |
+
consequence of further modification of the contributor version. For
|
483 |
+
purposes of this definition, "control" includes the right to grant
|
484 |
+
patent sublicenses in a manner consistent with the requirements of
|
485 |
+
this License.
|
486 |
+
|
487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
488 |
+
patent license under the contributor's essential patent claims, to
|
489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
490 |
+
propagate the contents of its contributor version.
|
491 |
+
|
492 |
+
In the following three paragraphs, a "patent license" is any express
|
493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
494 |
+
(such as an express permission to practice a patent or covenant not to
|
495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
496 |
+
party means to make such an agreement or commitment not to enforce a
|
497 |
+
patent against the party.
|
498 |
+
|
499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
500 |
+
and the Corresponding Source of the work is not available for anyone
|
501 |
+
to copy, free of charge and under the terms of this License, through a
|
502 |
+
publicly available network server or other readily accessible means,
|
503 |
+
then you must either (1) cause the Corresponding Source to be so
|
504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
506 |
+
consistent with the requirements of this License, to extend the patent
|
507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
508 |
+
actual knowledge that, but for the patent license, your conveying the
|
509 |
+
covered work in a country, or your recipient's use of the covered work
|
510 |
+
in a country, would infringe one or more identifiable patents in that
|
511 |
+
country that you have reason to believe are valid.
|
512 |
+
|
513 |
+
If, pursuant to or in connection with a single transaction or
|
514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
515 |
+
covered work, and grant a patent license to some of the parties
|
516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
517 |
+
or convey a specific copy of the covered work, then the patent license
|
518 |
+
you grant is automatically extended to all recipients of the covered
|
519 |
+
work and works based on it.
|
520 |
+
|
521 |
+
A patent license is "discriminatory" if it does not include within
|
522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
524 |
+
specifically granted under this License. You may not convey a covered
|
525 |
+
work if you are a party to an arrangement with a third party that is
|
526 |
+
in the business of distributing software, under which you make payment
|
527 |
+
to the third party based on the extent of your activity of conveying
|
528 |
+
the work, and under which the third party grants, to any of the
|
529 |
+
parties who would receive the covered work from you, a discriminatory
|
530 |
+
patent license (a) in connection with copies of the covered work
|
531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
532 |
+
for and in connection with specific products or compilations that
|
533 |
+
contain the covered work, unless you entered into that arrangement,
|
534 |
+
or that patent license was granted, prior to 28 March 2007.
|
535 |
+
|
536 |
+
Nothing in this License shall be construed as excluding or limiting
|
537 |
+
any implied license or other defenses to infringement that may
|
538 |
+
otherwise be available to you under applicable patent law.
|
539 |
+
|
540 |
+
12. No Surrender of Others' Freedom.
|
541 |
+
|
542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
543 |
+
otherwise) that contradict the conditions of this License, they do not
|
544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
546 |
+
License and any other pertinent obligations, then as a consequence you may
|
547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
548 |
+
to collect a royalty for further conveying from those to whom you convey
|
549 |
+
the Program, the only way you could satisfy both those terms and this
|
550 |
+
License would be to refrain entirely from conveying the Program.
|
551 |
+
|
552 |
+
13. Use with the GNU Affero General Public License.
|
553 |
+
|
554 |
+
Notwithstanding any other provision of this License, you have
|
555 |
+
permission to link or combine any covered work with a work licensed
|
556 |
+
under version 3 of the GNU Affero General Public License into a single
|
557 |
+
combined work, and to convey the resulting work. The terms of this
|
558 |
+
License will continue to apply to the part which is the covered work,
|
559 |
+
but the special requirements of the GNU Affero General Public License,
|
560 |
+
section 13, concerning interaction through a network will apply to the
|
561 |
+
combination as such.
|
562 |
+
|
563 |
+
14. Revised Versions of this License.
|
564 |
+
|
565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
566 |
+
the GNU General Public License from time to time. Such new versions will
|
567 |
+
be similar in spirit to the present version, but may differ in detail to
|
568 |
+
address new problems or concerns.
|
569 |
+
|
570 |
+
Each version is given a distinguishing version number. If the
|
571 |
+
Program specifies that a certain numbered version of the GNU General
|
572 |
+
Public License "or any later version" applies to it, you have the
|
573 |
+
option of following the terms and conditions either of that numbered
|
574 |
+
version or of any later version published by the Free Software
|
575 |
+
Foundation. If the Program does not specify a version number of the
|
576 |
+
GNU General Public License, you may choose any version ever published
|
577 |
+
by the Free Software Foundation.
|
578 |
+
|
579 |
+
If the Program specifies that a proxy can decide which future
|
580 |
+
versions of the GNU General Public License can be used, that proxy's
|
581 |
+
public statement of acceptance of a version permanently authorizes you
|
582 |
+
to choose that version for the Program.
|
583 |
+
|
584 |
+
Later license versions may give you additional or different
|
585 |
+
permissions. However, no additional obligations are imposed on any
|
586 |
+
author or copyright holder as a result of your choosing to follow a
|
587 |
+
later version.
|
588 |
+
|
589 |
+
15. Disclaimer of Warranty.
|
590 |
+
|
591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
599 |
+
|
600 |
+
16. Limitation of Liability.
|
601 |
+
|
602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
610 |
+
SUCH DAMAGES.
|
611 |
+
|
612 |
+
17. Interpretation of Sections 15 and 16.
|
613 |
+
|
614 |
+
If the disclaimer of warranty and limitation of liability provided
|
615 |
+
above cannot be given local legal effect according to their terms,
|
616 |
+
reviewing courts shall apply local law that most closely approximates
|
617 |
+
an absolute waiver of all civil liability in connection with the
|
618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
619 |
+
copy of the Program in return for a fee.
|
620 |
+
|
621 |
+
END OF TERMS AND CONDITIONS
|
622 |
+
|
623 |
+
How to Apply These Terms to Your New Programs
|
624 |
+
|
625 |
+
If you develop a new program, and you want it to be of the greatest
|
626 |
+
possible use to the public, the best way to achieve this is to make it
|
627 |
+
free software which everyone can redistribute and change under these terms.
|
628 |
+
|
629 |
+
To do so, attach the following notices to the program. It is safest
|
630 |
+
to attach them to the start of each source file to most effectively
|
631 |
+
state the exclusion of warranty; and each file should have at least
|
632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
633 |
+
|
634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
635 |
+
Copyright (C) <year> <name of author>
|
636 |
+
|
637 |
+
This program is free software: you can redistribute it and/or modify
|
638 |
+
it under the terms of the GNU General Public License as published by
|
639 |
+
the Free Software Foundation, either version 3 of the License, or
|
640 |
+
(at your option) any later version.
|
641 |
+
|
642 |
+
This program is distributed in the hope that it will be useful,
|
643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
645 |
+
GNU General Public License for more details.
|
646 |
+
|
647 |
+
You should have received a copy of the GNU General Public License
|
648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
649 |
+
|
650 |
+
Also add information on how to contact you by electronic and paper mail.
|
651 |
+
|
652 |
+
If the program does terminal interaction, make it output a short
|
653 |
+
notice like this when it starts in an interactive mode:
|
654 |
+
|
655 |
+
<program> Copyright (C) <year> <name of author>
|
656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657 |
+
This is free software, and you are welcome to redistribute it
|
658 |
+
under certain conditions; type `show c' for details.
|
659 |
+
|
660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
661 |
+
parts of the General Public License. Of course, your program's commands
|
662 |
+
might be different; for a GUI interface, you would use an "about box".
|
663 |
+
|
664 |
+
You should also get your employer (if you work as a programmer) or school,
|
665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
667 |
+
<https://www.gnu.org/licenses/>.
|
668 |
+
|
669 |
+
The GNU General Public License does not permit incorporating your program
|
670 |
+
into proprietary programs. If your program is a subroutine library, you
|
671 |
+
may consider it more useful to permit linking proprietary applications with
|
672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
673 |
+
Public License instead of this License. But first, please read
|
674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
README.md
CHANGED
@@ -1,13 +1,381 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div align="center">
|
2 |
+
|
3 |
+
# ComfyUI
|
4 |
+
**The most powerful and modular visual AI engine and application.**
|
5 |
+
|
6 |
+
|
7 |
+
[![Website][website-shield]][website-url]
|
8 |
+
[![Dynamic JSON Badge][discord-shield]][discord-url]
|
9 |
+
[![Matrix][matrix-shield]][matrix-url]
|
10 |
+
<br>
|
11 |
+
[![][github-release-shield]][github-release-link]
|
12 |
+
[![][github-release-date-shield]][github-release-link]
|
13 |
+
[![][github-downloads-shield]][github-downloads-link]
|
14 |
+
[![][github-downloads-latest-shield]][github-downloads-link]
|
15 |
+
|
16 |
+
[matrix-shield]: https://img.shields.io/badge/Matrix-000000?style=flat&logo=matrix&logoColor=white
|
17 |
+
[matrix-url]: https://app.element.io/#/room/%23comfyui_space%3Amatrix.org
|
18 |
+
[website-shield]: https://img.shields.io/badge/ComfyOrg-4285F4?style=flat
|
19 |
+
[website-url]: https://www.comfy.org/
|
20 |
+
<!-- Workaround to display total user from https://github.com/badges/shields/issues/4500#issuecomment-2060079995 -->
|
21 |
+
[discord-shield]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fdiscord.com%2Fapi%2Finvites%2Fcomfyorg%3Fwith_counts%3Dtrue&query=%24.approximate_member_count&logo=discord&logoColor=white&label=Discord&color=green&suffix=%20total
|
22 |
+
[discord-url]: https://www.comfy.org/discord
|
23 |
+
|
24 |
+
[github-release-shield]: https://img.shields.io/github/v/release/comfyanonymous/ComfyUI?style=flat&sort=semver
|
25 |
+
[github-release-link]: https://github.com/comfyanonymous/ComfyUI/releases
|
26 |
+
[github-release-date-shield]: https://img.shields.io/github/release-date/comfyanonymous/ComfyUI?style=flat
|
27 |
+
[github-downloads-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/total?style=flat
|
28 |
+
[github-downloads-latest-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/latest/total?style=flat&label=downloads%40latest
|
29 |
+
[github-downloads-link]: https://github.com/comfyanonymous/ComfyUI/releases
|
30 |
+
|
31 |
+

|
32 |
+
</div>
|
33 |
+
|
34 |
+
ComfyUI lets you design and execute advanced stable diffusion pipelines using a graph/nodes/flowchart based interface. Available on Windows, Linux, and macOS.
|
35 |
+
|
36 |
+
## Get Started
|
37 |
+
|
38 |
+
#### [Desktop Application](https://www.comfy.org/download)
|
39 |
+
- The easiest way to get started.
|
40 |
+
- Available on Windows & macOS.
|
41 |
+
|
42 |
+
#### [Windows Portable Package](#installing)
|
43 |
+
- Get the latest commits and completely portable.
|
44 |
+
- Available on Windows.
|
45 |
+
|
46 |
+
#### [Manual Install](#manual-install-windows-linux)
|
47 |
+
Supports all operating systems and GPU types (NVIDIA, AMD, Intel, Apple Silicon, Ascend).
|
48 |
+
|
49 |
+
## [Examples](https://comfyanonymous.github.io/ComfyUI_examples/)
|
50 |
+
See what ComfyUI can do with the [example workflows](https://comfyanonymous.github.io/ComfyUI_examples/).
|
51 |
+
|
52 |
+
|
53 |
+
## Features
|
54 |
+
- Nodes/graph/flowchart interface to experiment and create complex Stable Diffusion workflows without needing to code anything.
|
55 |
+
- Image Models
|
56 |
+
- SD1.x, SD2.x,
|
57 |
+
- [SDXL](https://comfyanonymous.github.io/ComfyUI_examples/sdxl/), [SDXL Turbo](https://comfyanonymous.github.io/ComfyUI_examples/sdturbo/)
|
58 |
+
- [Stable Cascade](https://comfyanonymous.github.io/ComfyUI_examples/stable_cascade/)
|
59 |
+
- [SD3 and SD3.5](https://comfyanonymous.github.io/ComfyUI_examples/sd3/)
|
60 |
+
- Pixart Alpha and Sigma
|
61 |
+
- [AuraFlow](https://comfyanonymous.github.io/ComfyUI_examples/aura_flow/)
|
62 |
+
- [HunyuanDiT](https://comfyanonymous.github.io/ComfyUI_examples/hunyuan_dit/)
|
63 |
+
- [Flux](https://comfyanonymous.github.io/ComfyUI_examples/flux/)
|
64 |
+
- [Lumina Image 2.0](https://comfyanonymous.github.io/ComfyUI_examples/lumina2/)
|
65 |
+
- [HiDream](https://comfyanonymous.github.io/ComfyUI_examples/hidream/)
|
66 |
+
- Video Models
|
67 |
+
- [Stable Video Diffusion](https://comfyanonymous.github.io/ComfyUI_examples/video/)
|
68 |
+
- [Mochi](https://comfyanonymous.github.io/ComfyUI_examples/mochi/)
|
69 |
+
- [LTX-Video](https://comfyanonymous.github.io/ComfyUI_examples/ltxv/)
|
70 |
+
- [Hunyuan Video](https://comfyanonymous.github.io/ComfyUI_examples/hunyuan_video/)
|
71 |
+
- [Nvidia Cosmos](https://comfyanonymous.github.io/ComfyUI_examples/cosmos/)
|
72 |
+
- [Wan 2.1](https://comfyanonymous.github.io/ComfyUI_examples/wan/)
|
73 |
+
- 3D Models
|
74 |
+
- [Hunyuan3D 2.0](https://docs.comfy.org/tutorials/3d/hunyuan3D-2)
|
75 |
+
- [Stable Audio](https://comfyanonymous.github.io/ComfyUI_examples/audio/)
|
76 |
+
- Asynchronous Queue system
|
77 |
+
- Many optimizations: Only re-executes the parts of the workflow that changes between executions.
|
78 |
+
- Smart memory management: can automatically run models on GPUs with as low as 1GB vram.
|
79 |
+
- Works even if you don't have a GPU with: ```--cpu``` (slow)
|
80 |
+
- Can load ckpt, safetensors and diffusers models/checkpoints. Standalone VAEs and CLIP models.
|
81 |
+
- Embeddings/Textual inversion
|
82 |
+
- [Loras (regular, locon and loha)](https://comfyanonymous.github.io/ComfyUI_examples/lora/)
|
83 |
+
- [Hypernetworks](https://comfyanonymous.github.io/ComfyUI_examples/hypernetworks/)
|
84 |
+
- Loading full workflows (with seeds) from generated PNG, WebP and FLAC files.
|
85 |
+
- Saving/Loading workflows as Json files.
|
86 |
+
- Nodes interface can be used to create complex workflows like one for [Hires fix](https://comfyanonymous.github.io/ComfyUI_examples/2_pass_txt2img/) or much more advanced ones.
|
87 |
+
- [Area Composition](https://comfyanonymous.github.io/ComfyUI_examples/area_composition/)
|
88 |
+
- [Inpainting](https://comfyanonymous.github.io/ComfyUI_examples/inpaint/) with both regular and inpainting models.
|
89 |
+
- [ControlNet and T2I-Adapter](https://comfyanonymous.github.io/ComfyUI_examples/controlnet/)
|
90 |
+
- [Upscale Models (ESRGAN, ESRGAN variants, SwinIR, Swin2SR, etc...)](https://comfyanonymous.github.io/ComfyUI_examples/upscale_models/)
|
91 |
+
- [unCLIP Models](https://comfyanonymous.github.io/ComfyUI_examples/unclip/)
|
92 |
+
- [GLIGEN](https://comfyanonymous.github.io/ComfyUI_examples/gligen/)
|
93 |
+
- [Model Merging](https://comfyanonymous.github.io/ComfyUI_examples/model_merging/)
|
94 |
+
- [LCM models and Loras](https://comfyanonymous.github.io/ComfyUI_examples/lcm/)
|
95 |
+
- Latent previews with [TAESD](#how-to-show-high-quality-previews)
|
96 |
+
- Starts up very fast.
|
97 |
+
- Works fully offline: will never download anything.
|
98 |
+
- [Config file](extra_model_paths.yaml.example) to set the search paths for models.
|
99 |
+
|
100 |
+
Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/)
|
101 |
+
|
102 |
+
## Shortcuts
|
103 |
+
|
104 |
+
| Keybind | Explanation |
|
105 |
+
|------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
106 |
+
| `Ctrl` + `Enter` | Queue up current graph for generation |
|
107 |
+
| `Ctrl` + `Shift` + `Enter` | Queue up current graph as first for generation |
|
108 |
+
| `Ctrl` + `Alt` + `Enter` | Cancel current generation |
|
109 |
+
| `Ctrl` + `Z`/`Ctrl` + `Y` | Undo/Redo |
|
110 |
+
| `Ctrl` + `S` | Save workflow |
|
111 |
+
| `Ctrl` + `O` | Load workflow |
|
112 |
+
| `Ctrl` + `A` | Select all nodes |
|
113 |
+
| `Alt `+ `C` | Collapse/uncollapse selected nodes |
|
114 |
+
| `Ctrl` + `M` | Mute/unmute selected nodes |
|
115 |
+
| `Ctrl` + `B` | Bypass selected nodes (acts like the node was removed from the graph and the wires reconnected through) |
|
116 |
+
| `Delete`/`Backspace` | Delete selected nodes |
|
117 |
+
| `Ctrl` + `Backspace` | Delete the current graph |
|
118 |
+
| `Space` | Move the canvas around when held and moving the cursor |
|
119 |
+
| `Ctrl`/`Shift` + `Click` | Add clicked node to selection |
|
120 |
+
| `Ctrl` + `C`/`Ctrl` + `V` | Copy and paste selected nodes (without maintaining connections to outputs of unselected nodes) |
|
121 |
+
| `Ctrl` + `C`/`Ctrl` + `Shift` + `V` | Copy and paste selected nodes (maintaining connections from outputs of unselected nodes to inputs of pasted nodes) |
|
122 |
+
| `Shift` + `Drag` | Move multiple selected nodes at the same time |
|
123 |
+
| `Ctrl` + `D` | Load default graph |
|
124 |
+
| `Alt` + `+` | Canvas Zoom in |
|
125 |
+
| `Alt` + `-` | Canvas Zoom out |
|
126 |
+
| `Ctrl` + `Shift` + LMB + Vertical drag | Canvas Zoom in/out |
|
127 |
+
| `P` | Pin/Unpin selected nodes |
|
128 |
+
| `Ctrl` + `G` | Group selected nodes |
|
129 |
+
| `Q` | Toggle visibility of the queue |
|
130 |
+
| `H` | Toggle visibility of history |
|
131 |
+
| `R` | Refresh graph |
|
132 |
+
| `F` | Show/Hide menu |
|
133 |
+
| `.` | Fit view to selection (Whole graph when nothing is selected) |
|
134 |
+
| Double-Click LMB | Open node quick search palette |
|
135 |
+
| `Shift` + Drag | Move multiple wires at once |
|
136 |
+
| `Ctrl` + `Alt` + LMB | Disconnect all wires from clicked slot |
|
137 |
+
|
138 |
+
`Ctrl` can also be replaced with `Cmd` instead for macOS users
|
139 |
+
|
140 |
+
# Installing
|
141 |
+
|
142 |
+
## Windows Portable
|
143 |
+
|
144 |
+
There is a portable standalone build for Windows that should work for running on Nvidia GPUs or for running on your CPU only on the [releases page](https://github.com/comfyanonymous/ComfyUI/releases).
|
145 |
+
|
146 |
+
### [Direct link to download](https://github.com/comfyanonymous/ComfyUI/releases/latest/download/ComfyUI_windows_portable_nvidia.7z)
|
147 |
+
|
148 |
+
Simply download, extract with [7-Zip](https://7-zip.org) and run. Make sure you put your Stable Diffusion checkpoints/models (the huge ckpt/safetensors files) in: ComfyUI\models\checkpoints
|
149 |
+
|
150 |
+
If you have trouble extracting it, right click the file -> properties -> unblock
|
151 |
+
|
152 |
+
If you have a 50 series Blackwell card like a 5090 or 5080 see [this discussion thread](https://github.com/comfyanonymous/ComfyUI/discussions/6643)
|
153 |
+
|
154 |
+
#### How do I share models between another UI and ComfyUI?
|
155 |
+
|
156 |
+
See the [Config file](extra_model_paths.yaml.example) to set the search paths for models. In the standalone windows build you can find this file in the ComfyUI directory. Rename this file to extra_model_paths.yaml and edit it with your favorite text editor.
|
157 |
+
|
158 |
+
## Jupyter Notebook
|
159 |
+
|
160 |
+
To run it on services like paperspace, kaggle or colab you can use my [Jupyter Notebook](notebooks/comfyui_colab.ipynb)
|
161 |
+
|
162 |
+
|
163 |
+
## [comfy-cli](https://docs.comfy.org/comfy-cli/getting-started)
|
164 |
+
|
165 |
+
You can install and start ComfyUI using comfy-cli:
|
166 |
+
```bash
|
167 |
+
pip install comfy-cli
|
168 |
+
comfy install
|
169 |
+
```
|
170 |
+
|
171 |
+
## Manual Install (Windows, Linux)
|
172 |
+
|
173 |
+
python 3.13 is supported but using 3.12 is recommended because some custom nodes and their dependencies might not support it yet.
|
174 |
+
|
175 |
+
Git clone this repo.
|
176 |
+
|
177 |
+
Put your SD checkpoints (the huge ckpt/safetensors files) in: models/checkpoints
|
178 |
+
|
179 |
+
Put your VAE in: models/vae
|
180 |
+
|
181 |
+
|
182 |
+
### AMD GPUs (Linux only)
|
183 |
+
AMD users can install rocm and pytorch with pip if you don't have it already installed, this is the command to install the stable version:
|
184 |
+
|
185 |
+
```pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4```
|
186 |
+
|
187 |
+
This is the command to install the nightly with ROCm 6.3 which might have some performance improvements:
|
188 |
+
|
189 |
+
```pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3```
|
190 |
+
|
191 |
+
### Intel GPUs (Windows and Linux)
|
192 |
+
|
193 |
+
(Option 1) Intel Arc GPU users can install native PyTorch with torch.xpu support using pip (currently available in PyTorch nightly builds). More information can be found [here](https://pytorch.org/docs/main/notes/get_start_xpu.html)
|
194 |
+
|
195 |
+
1. To install PyTorch nightly, use the following command:
|
196 |
+
|
197 |
+
```pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/xpu```
|
198 |
+
|
199 |
+
2. Launch ComfyUI by running `python main.py`
|
200 |
+
|
201 |
+
|
202 |
+
(Option 2) Alternatively, Intel GPUs supported by Intel Extension for PyTorch (IPEX) can leverage IPEX for improved performance.
|
203 |
+
|
204 |
+
1. For Intel® Arc™ A-Series Graphics utilizing IPEX, create a conda environment and use the commands below:
|
205 |
+
|
206 |
+
```
|
207 |
+
conda install libuv
|
208 |
+
pip install torch==2.3.1.post0+cxx11.abi torchvision==0.18.1.post0+cxx11.abi torchaudio==2.3.1.post0+cxx11.abi intel-extension-for-pytorch==2.3.110.post0+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/
|
209 |
+
```
|
210 |
+
|
211 |
+
For other supported Intel GPUs with IPEX, visit [Installation](https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu) for more information.
|
212 |
+
|
213 |
+
Additional discussion and help can be found [here](https://github.com/comfyanonymous/ComfyUI/discussions/476).
|
214 |
+
|
215 |
+
### NVIDIA
|
216 |
+
|
217 |
+
Nvidia users should install stable pytorch using this command:
|
218 |
+
|
219 |
+
```pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126```
|
220 |
+
|
221 |
+
This is the command to install pytorch nightly instead which supports the new blackwell 50xx series GPUs and might have performance improvements.
|
222 |
+
|
223 |
+
```pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128```
|
224 |
+
|
225 |
+
#### Troubleshooting
|
226 |
+
|
227 |
+
If you get the "Torch not compiled with CUDA enabled" error, uninstall torch with:
|
228 |
+
|
229 |
+
```pip uninstall torch```
|
230 |
+
|
231 |
+
And install it again with the command above.
|
232 |
+
|
233 |
+
### Dependencies
|
234 |
+
|
235 |
+
Install the dependencies by opening your terminal inside the ComfyUI folder and:
|
236 |
+
|
237 |
+
```pip install -r requirements.txt```
|
238 |
+
|
239 |
+
After this you should have everything installed and can proceed to running ComfyUI.
|
240 |
+
|
241 |
+
### Others:
|
242 |
+
|
243 |
+
#### Apple Mac silicon
|
244 |
+
|
245 |
+
You can install ComfyUI in Apple Mac silicon (M1 or M2) with any recent macOS version.
|
246 |
+
|
247 |
+
1. Install pytorch nightly. For instructions, read the [Accelerated PyTorch training on Mac](https://developer.apple.com/metal/pytorch/) Apple Developer guide (make sure to install the latest pytorch nightly).
|
248 |
+
1. Follow the [ComfyUI manual installation](#manual-install-windows-linux) instructions for Windows and Linux.
|
249 |
+
1. Install the ComfyUI [dependencies](#dependencies). If you have another Stable Diffusion UI [you might be able to reuse the dependencies](#i-already-have-another-ui-for-stable-diffusion-installed-do-i-really-have-to-install-all-of-these-dependencies).
|
250 |
+
1. Launch ComfyUI by running `python main.py`
|
251 |
+
|
252 |
+
> **Note**: Remember to add your models, VAE, LoRAs etc. to the corresponding Comfy folders, as discussed in [ComfyUI manual installation](#manual-install-windows-linux).
|
253 |
+
|
254 |
+
#### DirectML (AMD Cards on Windows)
|
255 |
+
|
256 |
+
```pip install torch-directml``` Then you can launch ComfyUI with: ```python main.py --directml```
|
257 |
+
|
258 |
+
#### Ascend NPUs
|
259 |
+
|
260 |
+
For models compatible with Ascend Extension for PyTorch (torch_npu). To get started, ensure your environment meets the prerequisites outlined on the [installation](https://ascend.github.io/docs/sources/ascend/quick_install.html) page. Here's a step-by-step guide tailored to your platform and installation method:
|
261 |
+
|
262 |
+
1. Begin by installing the recommended or newer kernel version for Linux as specified in the Installation page of torch-npu, if necessary.
|
263 |
+
2. Proceed with the installation of Ascend Basekit, which includes the driver, firmware, and CANN, following the instructions provided for your specific platform.
|
264 |
+
3. Next, install the necessary packages for torch-npu by adhering to the platform-specific instructions on the [Installation](https://ascend.github.io/docs/sources/pytorch/install.html#pytorch) page.
|
265 |
+
4. Finally, adhere to the [ComfyUI manual installation](#manual-install-windows-linux) guide for Linux. Once all components are installed, you can run ComfyUI as described earlier.
|
266 |
+
|
267 |
+
#### Cambricon MLUs
|
268 |
+
|
269 |
+
For models compatible with Cambricon Extension for PyTorch (torch_mlu). Here's a step-by-step guide tailored to your platform and installation method:
|
270 |
+
|
271 |
+
1. Install the Cambricon CNToolkit by adhering to the platform-specific instructions on the [Installation](https://www.cambricon.com/docs/sdk_1.15.0/cntoolkit_3.7.2/cntoolkit_install_3.7.2/index.html)
|
272 |
+
2. Next, install the PyTorch(torch_mlu) following the instructions on the [Installation](https://www.cambricon.com/docs/sdk_1.15.0/cambricon_pytorch_1.17.0/user_guide_1.9/index.html)
|
273 |
+
3. Launch ComfyUI by running `python main.py`
|
274 |
+
|
275 |
+
# Running
|
276 |
+
|
277 |
+
```python main.py```
|
278 |
+
|
279 |
+
### For AMD cards not officially supported by ROCm
|
280 |
+
|
281 |
+
Try running it with this command if you have issues:
|
282 |
+
|
283 |
+
For 6700, 6600 and maybe other RDNA2 or older: ```HSA_OVERRIDE_GFX_VERSION=10.3.0 python main.py```
|
284 |
+
|
285 |
+
For AMD 7600 and maybe other RDNA3 cards: ```HSA_OVERRIDE_GFX_VERSION=11.0.0 python main.py```
|
286 |
+
|
287 |
+
### AMD ROCm Tips
|
288 |
+
|
289 |
+
You can enable experimental memory efficient attention on pytorch 2.5 in ComfyUI on RDNA3 and potentially other AMD GPUs using this command:
|
290 |
+
|
291 |
+
```TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 python main.py --use-pytorch-cross-attention```
|
292 |
+
|
293 |
+
You can also try setting this env variable `PYTORCH_TUNABLEOP_ENABLED=1` which might speed things up at the cost of a very slow initial run.
|
294 |
+
|
295 |
+
# Notes
|
296 |
+
|
297 |
+
Only parts of the graph that have an output with all the correct inputs will be executed.
|
298 |
+
|
299 |
+
Only parts of the graph that change from each execution to the next will be executed, if you submit the same graph twice only the first will be executed. If you change the last part of the graph only the part you changed and the part that depends on it will be executed.
|
300 |
+
|
301 |
+
Dragging a generated png on the webpage or loading one will give you the full workflow including seeds that were used to create it.
|
302 |
+
|
303 |
+
You can use () to change emphasis of a word or phrase like: (good code:1.2) or (bad code:0.8). The default emphasis for () is 1.1. To use () characters in your actual prompt escape them like \\( or \\).
|
304 |
+
|
305 |
+
You can use {day|night}, for wildcard/dynamic prompts. With this syntax "{wild|card|test}" will be randomly replaced by either "wild", "card" or "test" by the frontend every time you queue the prompt. To use {} characters in your actual prompt escape them like: \\{ or \\}.
|
306 |
+
|
307 |
+
Dynamic prompts also support C-style comments, like `// comment` or `/* comment */`.
|
308 |
+
|
309 |
+
To use a textual inversion concepts/embeddings in a text prompt put them in the models/embeddings directory and use them in the CLIPTextEncode node like this (you can omit the .pt extension):
|
310 |
+
|
311 |
+
```embedding:embedding_filename.pt```
|
312 |
+
|
313 |
+
|
314 |
+
## How to show high-quality previews?
|
315 |
+
|
316 |
+
Use ```--preview-method auto``` to enable previews.
|
317 |
+
|
318 |
+
The default installation includes a fast latent preview method that's low-resolution. To enable higher-quality previews with [TAESD](https://github.com/madebyollin/taesd), download the [taesd_decoder.pth, taesdxl_decoder.pth, taesd3_decoder.pth and taef1_decoder.pth](https://github.com/madebyollin/taesd/) and place them in the `models/vae_approx` folder. Once they're installed, restart ComfyUI and launch it with `--preview-method taesd` to enable high-quality previews.
|
319 |
+
|
320 |
+
## How to use TLS/SSL?
|
321 |
+
Generate a self-signed certificate (not appropriate for shared/production use) and key by running the command: `openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"`
|
322 |
+
|
323 |
+
Use `--tls-keyfile key.pem --tls-certfile cert.pem` to enable TLS/SSL, the app will now be accessible with `https://...` instead of `http://...`.
|
324 |
+
|
325 |
+
> Note: Windows users can use [alexisrolland/docker-openssl](https://github.com/alexisrolland/docker-openssl) or one of the [3rd party binary distributions](https://wiki.openssl.org/index.php/Binaries) to run the command example above.
|
326 |
+
<br/><br/>If you use a container, note that the volume mount `-v` can be a relative path so `... -v ".\:/openssl-certs" ...` would create the key & cert files in the current directory of your command prompt or powershell terminal.
|
327 |
+
|
328 |
+
## Support and dev channel
|
329 |
+
|
330 |
+
[Discord](https://comfy.org/discord): Try the #help or #feedback channels.
|
331 |
+
|
332 |
+
[Matrix space: #comfyui_space:matrix.org](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) (it's like discord but open source).
|
333 |
+
|
334 |
+
See also: [https://www.comfy.org/](https://www.comfy.org/)
|
335 |
+
|
336 |
+
## Frontend Development
|
337 |
+
|
338 |
+
As of August 15, 2024, we have transitioned to a new frontend, which is now hosted in a separate repository: [ComfyUI Frontend](https://github.com/Comfy-Org/ComfyUI_frontend). This repository now hosts the compiled JS (from TS/Vue) under the `web/` directory.
|
339 |
+
|
340 |
+
### Reporting Issues and Requesting Features
|
341 |
+
|
342 |
+
For any bugs, issues, or feature requests related to the frontend, please use the [ComfyUI Frontend repository](https://github.com/Comfy-Org/ComfyUI_frontend). This will help us manage and address frontend-specific concerns more efficiently.
|
343 |
+
|
344 |
+
### Using the Latest Frontend
|
345 |
+
|
346 |
+
The new frontend is now the default for ComfyUI. However, please note:
|
347 |
+
|
348 |
+
1. The frontend in the main ComfyUI repository is updated fortnightly.
|
349 |
+
2. Daily releases are available in the separate frontend repository.
|
350 |
+
|
351 |
+
To use the most up-to-date frontend version:
|
352 |
+
|
353 |
+
1. For the latest daily release, launch ComfyUI with this command line argument:
|
354 |
+
|
355 |
+
```
|
356 |
+
--front-end-version Comfy-Org/ComfyUI_frontend@latest
|
357 |
+
```
|
358 |
+
|
359 |
+
2. For a specific version, replace `latest` with the desired version number:
|
360 |
+
|
361 |
+
```
|
362 |
+
--front-end-version Comfy-Org/[email protected]
|
363 |
+
```
|
364 |
+
|
365 |
+
This approach allows you to easily switch between the stable fortnightly release and the cutting-edge daily updates, or even specific versions for testing purposes.
|
366 |
+
|
367 |
+
### Accessing the Legacy Frontend
|
368 |
+
|
369 |
+
If you need to use the legacy frontend for any reason, you can access it using the following command line argument:
|
370 |
+
|
371 |
+
```
|
372 |
+
--front-end-version Comfy-Org/ComfyUI_legacy_frontend@latest
|
373 |
+
```
|
374 |
+
|
375 |
+
This will use a snapshot of the legacy frontend preserved in the [ComfyUI Legacy Frontend repository](https://github.com/Comfy-Org/ComfyUI_legacy_frontend).
|
376 |
+
|
377 |
+
# QA
|
378 |
+
|
379 |
+
### Which GPU should I buy for this?
|
380 |
+
|
381 |
+
[See this page for some recommendations](https://github.com/comfyanonymous/ComfyUI/wiki/Which-GPU-should-I-buy-for-ComfyUI)
|
__pycache__/comfyui_version.cpython-312.pyc
ADDED
Binary file (155 Bytes). View file
|
|
__pycache__/cuda_malloc.cpython-312.pyc
ADDED
Binary file (4.72 kB). View file
|
|
__pycache__/execution.cpython-312.pyc
ADDED
Binary file (44.2 kB). View file
|
|
__pycache__/folder_paths.cpython-312.pyc
ADDED
Binary file (21.4 kB). View file
|
|
__pycache__/latent_preview.cpython-312.pyc
ADDED
Binary file (6.83 kB). View file
|
|
__pycache__/main.cpython-312.pyc
ADDED
Binary file (17.6 kB). View file
|
|
__pycache__/node_helpers.cpython-312.pyc
ADDED
Binary file (2.59 kB). View file
|
|
__pycache__/nodes.cpython-312.pyc
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5d83dd9221049e6cea8c5995e292951305dc286cc079606415e985436b29b271
|
3 |
+
size 117219
|
__pycache__/server.cpython-312.pyc
ADDED
Binary file (52.2 kB). View file
|
|
api_server/__init__.py
ADDED
File without changes
|
api_server/__pycache__/__init__.cpython-312.pyc
ADDED
Binary file (130 Bytes). View file
|
|
api_server/routes/__init__.py
ADDED
File without changes
|
api_server/routes/__pycache__/__init__.cpython-312.pyc
ADDED
Binary file (137 Bytes). View file
|
|
api_server/routes/internal/README.md
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# ComfyUI Internal Routes
|
2 |
+
|
3 |
+
All routes under the `/internal` path are designated for **internal use by ComfyUI only**. These routes are not intended for use by external applications may change at any time without notice.
|
api_server/routes/internal/__init__.py
ADDED
File without changes
|
api_server/routes/internal/__pycache__/__init__.cpython-312.pyc
ADDED
Binary file (146 Bytes). View file
|
|
api_server/routes/internal/__pycache__/internal_routes.cpython-312.pyc
ADDED
Binary file (5.82 kB). View file
|
|
api_server/routes/internal/internal_routes.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from aiohttp import web
|
2 |
+
from typing import Optional
|
3 |
+
from folder_paths import folder_names_and_paths, get_directory_by_type
|
4 |
+
from api_server.services.terminal_service import TerminalService
|
5 |
+
import app.logger
|
6 |
+
import os
|
7 |
+
|
8 |
+
class InternalRoutes:
|
9 |
+
'''
|
10 |
+
The top level web router for internal routes: /internal/*
|
11 |
+
The endpoints here should NOT be depended upon. It is for ComfyUI frontend use only.
|
12 |
+
Check README.md for more information.
|
13 |
+
'''
|
14 |
+
|
15 |
+
def __init__(self, prompt_server):
|
16 |
+
self.routes: web.RouteTableDef = web.RouteTableDef()
|
17 |
+
self._app: Optional[web.Application] = None
|
18 |
+
self.prompt_server = prompt_server
|
19 |
+
self.terminal_service = TerminalService(prompt_server)
|
20 |
+
|
21 |
+
def setup_routes(self):
|
22 |
+
@self.routes.get('/logs')
|
23 |
+
async def get_logs(request):
|
24 |
+
return web.json_response("".join([(l["t"] + " - " + l["m"]) for l in app.logger.get_logs()]))
|
25 |
+
|
26 |
+
@self.routes.get('/logs/raw')
|
27 |
+
async def get_raw_logs(request):
|
28 |
+
self.terminal_service.update_size()
|
29 |
+
return web.json_response({
|
30 |
+
"entries": list(app.logger.get_logs()),
|
31 |
+
"size": {"cols": self.terminal_service.cols, "rows": self.terminal_service.rows}
|
32 |
+
})
|
33 |
+
|
34 |
+
@self.routes.patch('/logs/subscribe')
|
35 |
+
async def subscribe_logs(request):
|
36 |
+
json_data = await request.json()
|
37 |
+
client_id = json_data["clientId"]
|
38 |
+
enabled = json_data["enabled"]
|
39 |
+
if enabled:
|
40 |
+
self.terminal_service.subscribe(client_id)
|
41 |
+
else:
|
42 |
+
self.terminal_service.unsubscribe(client_id)
|
43 |
+
|
44 |
+
return web.Response(status=200)
|
45 |
+
|
46 |
+
|
47 |
+
@self.routes.get('/folder_paths')
|
48 |
+
async def get_folder_paths(request):
|
49 |
+
response = {}
|
50 |
+
for key in folder_names_and_paths:
|
51 |
+
response[key] = folder_names_and_paths[key][0]
|
52 |
+
return web.json_response(response)
|
53 |
+
|
54 |
+
@self.routes.get('/files/{directory_type}')
|
55 |
+
async def get_files(request: web.Request) -> web.Response:
|
56 |
+
directory_type = request.match_info['directory_type']
|
57 |
+
if directory_type not in ("output", "input", "temp"):
|
58 |
+
return web.json_response({"error": "Invalid directory type"}, status=400)
|
59 |
+
|
60 |
+
directory = get_directory_by_type(directory_type)
|
61 |
+
sorted_files = sorted(
|
62 |
+
(entry for entry in os.scandir(directory) if entry.is_file()),
|
63 |
+
key=lambda entry: -entry.stat().st_mtime
|
64 |
+
)
|
65 |
+
return web.json_response([entry.name for entry in sorted_files], status=200)
|
66 |
+
|
67 |
+
|
68 |
+
def get_app(self):
|
69 |
+
if self._app is None:
|
70 |
+
self._app = web.Application()
|
71 |
+
self.setup_routes()
|
72 |
+
self._app.add_routes(self.routes)
|
73 |
+
return self._app
|
api_server/services/__init__.py
ADDED
File without changes
|
api_server/services/__pycache__/__init__.cpython-312.pyc
ADDED
Binary file (139 Bytes). View file
|
|
api_server/services/__pycache__/terminal_service.cpython-312.pyc
ADDED
Binary file (2.9 kB). View file
|
|
api_server/services/terminal_service.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from app.logger import on_flush
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
|
5 |
+
|
6 |
+
class TerminalService:
|
7 |
+
def __init__(self, server):
|
8 |
+
self.server = server
|
9 |
+
self.cols = None
|
10 |
+
self.rows = None
|
11 |
+
self.subscriptions = set()
|
12 |
+
on_flush(self.send_messages)
|
13 |
+
|
14 |
+
def get_terminal_size(self):
|
15 |
+
try:
|
16 |
+
size = os.get_terminal_size()
|
17 |
+
return (size.columns, size.lines)
|
18 |
+
except OSError:
|
19 |
+
try:
|
20 |
+
size = shutil.get_terminal_size()
|
21 |
+
return (size.columns, size.lines)
|
22 |
+
except OSError:
|
23 |
+
return (80, 24) # fallback to 80x24
|
24 |
+
|
25 |
+
def update_size(self):
|
26 |
+
columns, lines = self.get_terminal_size()
|
27 |
+
changed = False
|
28 |
+
|
29 |
+
if columns != self.cols:
|
30 |
+
self.cols = columns
|
31 |
+
changed = True
|
32 |
+
|
33 |
+
if lines != self.rows:
|
34 |
+
self.rows = lines
|
35 |
+
changed = True
|
36 |
+
|
37 |
+
if changed:
|
38 |
+
return {"cols": self.cols, "rows": self.rows}
|
39 |
+
|
40 |
+
return None
|
41 |
+
|
42 |
+
def subscribe(self, client_id):
|
43 |
+
self.subscriptions.add(client_id)
|
44 |
+
|
45 |
+
def unsubscribe(self, client_id):
|
46 |
+
self.subscriptions.discard(client_id)
|
47 |
+
|
48 |
+
def send_messages(self, entries):
|
49 |
+
if not len(entries) or not len(self.subscriptions):
|
50 |
+
return
|
51 |
+
|
52 |
+
new_size = self.update_size()
|
53 |
+
|
54 |
+
for client_id in self.subscriptions.copy(): # prevent: Set changed size during iteration
|
55 |
+
if client_id not in self.server.sockets:
|
56 |
+
# Automatically unsub if the socket has disconnected
|
57 |
+
self.unsubscribe(client_id)
|
58 |
+
continue
|
59 |
+
|
60 |
+
self.server.send_sync("logs", {"entries": entries, "size": new_size}, client_id)
|
api_server/utils/file_operations.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from typing import List, Union, TypedDict, Literal
|
3 |
+
from typing_extensions import TypeGuard
|
4 |
+
class FileInfo(TypedDict):
|
5 |
+
name: str
|
6 |
+
path: str
|
7 |
+
type: Literal["file"]
|
8 |
+
size: int
|
9 |
+
|
10 |
+
class DirectoryInfo(TypedDict):
|
11 |
+
name: str
|
12 |
+
path: str
|
13 |
+
type: Literal["directory"]
|
14 |
+
|
15 |
+
FileSystemItem = Union[FileInfo, DirectoryInfo]
|
16 |
+
|
17 |
+
def is_file_info(item: FileSystemItem) -> TypeGuard[FileInfo]:
|
18 |
+
return item["type"] == "file"
|
19 |
+
|
20 |
+
class FileSystemOperations:
|
21 |
+
@staticmethod
|
22 |
+
def walk_directory(directory: str) -> List[FileSystemItem]:
|
23 |
+
file_list: List[FileSystemItem] = []
|
24 |
+
for root, dirs, files in os.walk(directory):
|
25 |
+
for name in files:
|
26 |
+
file_path = os.path.join(root, name)
|
27 |
+
relative_path = os.path.relpath(file_path, directory)
|
28 |
+
file_list.append({
|
29 |
+
"name": name,
|
30 |
+
"path": relative_path,
|
31 |
+
"type": "file",
|
32 |
+
"size": os.path.getsize(file_path)
|
33 |
+
})
|
34 |
+
for name in dirs:
|
35 |
+
dir_path = os.path.join(root, name)
|
36 |
+
relative_path = os.path.relpath(dir_path, directory)
|
37 |
+
file_list.append({
|
38 |
+
"name": name,
|
39 |
+
"path": relative_path,
|
40 |
+
"type": "directory"
|
41 |
+
})
|
42 |
+
return file_list
|
app.py
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import sys
|
4 |
+
from typing import Sequence, Mapping, Any, Union
|
5 |
+
import torch
|
6 |
+
import gradio as gr
|
7 |
+
from PIL import Image
|
8 |
+
from huggingface_hub import hf_hub_download
|
9 |
+
import spaces
|
10 |
+
|
11 |
+
hf_hub_download(repo_id="ezioruan/inswapper_128.onnx", filename="inswapper_128.onnx", local_dir="models/insightface")
|
12 |
+
hf_hub_download(repo_id="martintomov/comfy", filename="GPEN-BFR-512.onnx", local_dir="models/facerestore_models")
|
13 |
+
hf_hub_download(repo_id="darkeril/collection", filename="detection_Resnet50_Final.pth", local_dir="models/facedetection")
|
14 |
+
hf_hub_download(repo_id="MonsterMMORPG/tools", filename="1k3d68.onnx", local_dir="insightface/models/buffalo_l")
|
15 |
+
hf_hub_download(repo_id="MonsterMMORPG/tools", filename="2d106det.onnx", local_dir="insightface/models/buffalo_l")
|
16 |
+
hf_hub_download(repo_id="maze/faceX", filename="det_10g.onnx", local_dir="insightface/models/buffalo_l")
|
17 |
+
hf_hub_download(repo_id="typhoon01/aux_models", filename="genderage.onnx", local_dir="insightface/models/buffalo_l")
|
18 |
+
hf_hub_download(repo_id="maze/faceX", filename="w600k_r50.onnx", local_dir="insightface/models/buffalo_l")
|
19 |
+
|
20 |
+
|
21 |
+
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
22 |
+
"""Returns the value at the given index of a sequence or mapping.
|
23 |
+
|
24 |
+
If the object is a sequence (like list or string), returns the value at the given index.
|
25 |
+
If the object is a mapping (like a dictionary), returns the value at the index-th key.
|
26 |
+
|
27 |
+
Some return a dictionary, in these cases, we look for the "results" key
|
28 |
+
|
29 |
+
Args:
|
30 |
+
obj (Union[Sequence, Mapping]): The object to retrieve the value from.
|
31 |
+
index (int): The index of the value to retrieve.
|
32 |
+
|
33 |
+
Returns:
|
34 |
+
Any: The value at the given index.
|
35 |
+
|
36 |
+
Raises:
|
37 |
+
IndexError: If the index is out of bounds for the object and the object is not a mapping.
|
38 |
+
"""
|
39 |
+
try:
|
40 |
+
return obj[index]
|
41 |
+
except KeyError:
|
42 |
+
return obj["result"][index]
|
43 |
+
|
44 |
+
|
45 |
+
def find_path(name: str, path: str = None) -> str:
|
46 |
+
"""
|
47 |
+
Recursively looks at parent folders starting from the given path until it finds the given name.
|
48 |
+
Returns the path as a Path object if found, or None otherwise.
|
49 |
+
"""
|
50 |
+
# If no path is given, use the current working directory
|
51 |
+
if path is None:
|
52 |
+
path = os.getcwd()
|
53 |
+
|
54 |
+
# Check if the current directory contains the name
|
55 |
+
if name in os.listdir(path):
|
56 |
+
path_name = os.path.join(path, name)
|
57 |
+
print(f"{name} found: {path_name}")
|
58 |
+
return path_name
|
59 |
+
|
60 |
+
# Get the parent directory
|
61 |
+
parent_directory = os.path.dirname(path)
|
62 |
+
|
63 |
+
# If the parent directory is the same as the current directory, we've reached the root and stop the search
|
64 |
+
if parent_directory == path:
|
65 |
+
return None
|
66 |
+
|
67 |
+
# Recursively call the function with the parent directory
|
68 |
+
return find_path(name, parent_directory)
|
69 |
+
|
70 |
+
|
71 |
+
def add_comfyui_directory_to_sys_path() -> None:
|
72 |
+
"""
|
73 |
+
Add 'ComfyUI' to the sys.path
|
74 |
+
"""
|
75 |
+
comfyui_path = find_path("ComfyUI")
|
76 |
+
if comfyui_path is not None and os.path.isdir(comfyui_path):
|
77 |
+
sys.path.append(comfyui_path)
|
78 |
+
print(f"'{comfyui_path}' added to sys.path")
|
79 |
+
|
80 |
+
|
81 |
+
def add_extra_model_paths() -> None:
|
82 |
+
"""
|
83 |
+
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
|
84 |
+
"""
|
85 |
+
try:
|
86 |
+
from main import load_extra_path_config
|
87 |
+
except ImportError:
|
88 |
+
print(
|
89 |
+
"Could not import load_extra_path_config from main.py. Looking in utils.extra_config instead."
|
90 |
+
)
|
91 |
+
from utils.extra_config import load_extra_path_config
|
92 |
+
|
93 |
+
extra_model_paths = find_path("extra_model_paths.yaml")
|
94 |
+
|
95 |
+
if extra_model_paths is not None:
|
96 |
+
load_extra_path_config(extra_model_paths)
|
97 |
+
else:
|
98 |
+
print("Could not find the extra_model_paths config file.")
|
99 |
+
|
100 |
+
|
101 |
+
add_comfyui_directory_to_sys_path()
|
102 |
+
add_extra_model_paths()
|
103 |
+
|
104 |
+
|
105 |
+
def import_custom_nodes() -> None:
|
106 |
+
"""Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
|
107 |
+
|
108 |
+
This function sets up a new asyncio event loop, initializes the PromptServer,
|
109 |
+
creates a PromptQueue, and initializes the custom nodes.
|
110 |
+
"""
|
111 |
+
import asyncio
|
112 |
+
import execution
|
113 |
+
from nodes import init_extra_nodes
|
114 |
+
import server
|
115 |
+
|
116 |
+
# Creating a new event loop and setting it as the default loop
|
117 |
+
loop = asyncio.new_event_loop()
|
118 |
+
asyncio.set_event_loop(loop)
|
119 |
+
|
120 |
+
# Creating an instance of PromptServer with the loop
|
121 |
+
server_instance = server.PromptServer(loop)
|
122 |
+
execution.PromptQueue(server_instance)
|
123 |
+
|
124 |
+
# Initializing custom nodes
|
125 |
+
init_extra_nodes()
|
126 |
+
|
127 |
+
import_custom_nodes()
|
128 |
+
from nodes import NODE_CLASS_MAPPINGS
|
129 |
+
|
130 |
+
@spaces.GPU(duration=20)
|
131 |
+
def generate_image(source_image, target_image, restore_strength, target_index):
|
132 |
+
with torch.inference_mode():
|
133 |
+
loadimage = NODE_CLASS_MAPPINGS["LoadImage"]()
|
134 |
+
loadimage_1 = loadimage.load_image(image=target_image)
|
135 |
+
|
136 |
+
loadimage_3 = loadimage.load_image(image=source_image)
|
137 |
+
|
138 |
+
reactorfaceswap = NODE_CLASS_MAPPINGS["ReActorFaceSwap"]()
|
139 |
+
saveimage = NODE_CLASS_MAPPINGS["SaveImage"]()
|
140 |
+
|
141 |
+
reactorfaceswap_2 = reactorfaceswap.execute(
|
142 |
+
enabled=True,
|
143 |
+
swap_model="inswapper_128.onnx",
|
144 |
+
facedetection="retinaface_resnet50",
|
145 |
+
face_restore_model="GPEN-BFR-512.onnx",
|
146 |
+
face_restore_visibility=restore_strength,
|
147 |
+
codeformer_weight=0.5,
|
148 |
+
detect_gender_input="no",
|
149 |
+
detect_gender_source="no",
|
150 |
+
input_faces_index=str(target_index), # Преобразуем в строку
|
151 |
+
source_faces_index="0",
|
152 |
+
console_log_level=1,
|
153 |
+
input_image=get_value_at_index(loadimage_1, 0),
|
154 |
+
source_image=get_value_at_index(loadimage_3, 0),
|
155 |
+
)
|
156 |
+
|
157 |
+
saveimage_4 = saveimage.save_images(
|
158 |
+
filename_prefix="ComfyUI",
|
159 |
+
images=get_value_at_index(reactorfaceswap_2, 0),
|
160 |
+
)
|
161 |
+
|
162 |
+
saved_path = f"output/{saveimage_4['ui']['images'][0]['filename']}"
|
163 |
+
return saved_path
|
164 |
+
|
165 |
+
if __name__ == "__main__":
|
166 |
+
with gr.Blocks() as app:
|
167 |
+
# Add a title
|
168 |
+
gr.Markdown("# ComfyUI Reactor Fast Face Swap")
|
169 |
+
gr.Markdown("ComfyUI Reactor Fast Face Swap running directly on Gradio. - [How to convert your any ComfyUI workflow to Gradio](https://huggingface.co/blog/run-comfyui-workflows-on-spaces)")
|
170 |
+
with gr.Row():
|
171 |
+
with gr.Column():
|
172 |
+
# Add an input
|
173 |
+
# prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
174 |
+
# Add a `Row` to include the groups side by side
|
175 |
+
with gr.Row():
|
176 |
+
# First group includes structure image and depth strength
|
177 |
+
with gr.Group():
|
178 |
+
source_image = gr.Image(label="Source Image", type="filepath")
|
179 |
+
# depth_strength = gr.Slider(minimum=0, maximum=50, value=15, label="Depth Strength")
|
180 |
+
# Second group includes style image and style strength
|
181 |
+
with gr.Group():
|
182 |
+
target_image = gr.Image(label="Target Image", type="filepath")
|
183 |
+
restore_strength = gr.Slider(minimum=0, maximum=1, step=0.05, value=0.7, label="Face Restore Strength")
|
184 |
+
target_index = gr.Dropdown(choices=[0, 1, 2, 3, 4], value=0, label="Target Face Index")
|
185 |
+
gr.Markdown("Index_0 = Largest Face. To switch for another target face - switch to Index_1, e.t.c")
|
186 |
+
|
187 |
+
# The generate button
|
188 |
+
generate_btn = gr.Button("Generate")
|
189 |
+
|
190 |
+
with gr.Column():
|
191 |
+
# The output image
|
192 |
+
output_image = gr.Image(label="Generated Image")
|
193 |
+
|
194 |
+
# When clicking the button, it will trigger the `generate_image` function, with the respective inputs
|
195 |
+
# and the output an image
|
196 |
+
generate_btn.click(
|
197 |
+
fn=generate_image,
|
198 |
+
inputs=[source_image, target_image, restore_strength, target_index],
|
199 |
+
outputs=[output_image]
|
200 |
+
)
|
201 |
+
app.launch(share=True)
|
app/__init__.py
ADDED
File without changes
|
app/__pycache__/__init__.cpython-312.pyc
ADDED
Binary file (123 Bytes). View file
|
|
app/__pycache__/app_settings.cpython-312.pyc
ADDED
Binary file (4.39 kB). View file
|
|
app/__pycache__/custom_node_manager.cpython-312.pyc
ADDED
Binary file (6.36 kB). View file
|
|
app/__pycache__/frontend_management.cpython-312.pyc
ADDED
Binary file (14.4 kB). View file
|
|
app/__pycache__/logger.cpython-312.pyc
ADDED
Binary file (5.18 kB). View file
|
|
app/__pycache__/model_manager.cpython-312.pyc
ADDED
Binary file (11.2 kB). View file
|
|
app/__pycache__/user_manager.cpython-312.pyc
ADDED
Binary file (18 kB). View file
|
|
app/app_settings.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from aiohttp import web
|
4 |
+
import logging
|
5 |
+
|
6 |
+
|
7 |
+
class AppSettings():
|
8 |
+
def __init__(self, user_manager):
|
9 |
+
self.user_manager = user_manager
|
10 |
+
|
11 |
+
def get_settings(self, request):
|
12 |
+
try:
|
13 |
+
file = self.user_manager.get_request_user_filepath(
|
14 |
+
request,
|
15 |
+
"comfy.settings.json"
|
16 |
+
)
|
17 |
+
except KeyError as e:
|
18 |
+
logging.error("User settings not found.")
|
19 |
+
raise web.HTTPUnauthorized() from e
|
20 |
+
if os.path.isfile(file):
|
21 |
+
try:
|
22 |
+
with open(file) as f:
|
23 |
+
return json.load(f)
|
24 |
+
except:
|
25 |
+
logging.error(f"The user settings file is corrupted: {file}")
|
26 |
+
return {}
|
27 |
+
else:
|
28 |
+
return {}
|
29 |
+
|
30 |
+
def save_settings(self, request, settings):
|
31 |
+
file = self.user_manager.get_request_user_filepath(
|
32 |
+
request, "comfy.settings.json")
|
33 |
+
with open(file, "w") as f:
|
34 |
+
f.write(json.dumps(settings, indent=4))
|
35 |
+
|
36 |
+
def add_routes(self, routes):
|
37 |
+
@routes.get("/settings")
|
38 |
+
async def get_settings(request):
|
39 |
+
return web.json_response(self.get_settings(request))
|
40 |
+
|
41 |
+
@routes.get("/settings/{id}")
|
42 |
+
async def get_setting(request):
|
43 |
+
value = None
|
44 |
+
settings = self.get_settings(request)
|
45 |
+
setting_id = request.match_info.get("id", None)
|
46 |
+
if setting_id and setting_id in settings:
|
47 |
+
value = settings[setting_id]
|
48 |
+
return web.json_response(value)
|
49 |
+
|
50 |
+
@routes.post("/settings")
|
51 |
+
async def post_settings(request):
|
52 |
+
settings = self.get_settings(request)
|
53 |
+
new_settings = await request.json()
|
54 |
+
self.save_settings(request, {**settings, **new_settings})
|
55 |
+
return web.Response(status=200)
|
56 |
+
|
57 |
+
@routes.post("/settings/{id}")
|
58 |
+
async def post_setting(request):
|
59 |
+
setting_id = request.match_info.get("id", None)
|
60 |
+
if not setting_id:
|
61 |
+
return web.Response(status=400)
|
62 |
+
settings = self.get_settings(request)
|
63 |
+
settings[setting_id] = await request.json()
|
64 |
+
self.save_settings(request, settings)
|
65 |
+
return web.Response(status=200)
|
app/custom_node_manager.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import folder_paths
|
5 |
+
import glob
|
6 |
+
from aiohttp import web
|
7 |
+
import json
|
8 |
+
import logging
|
9 |
+
from functools import lru_cache
|
10 |
+
|
11 |
+
from utils.json_util import merge_json_recursive
|
12 |
+
|
13 |
+
|
14 |
+
# Extra locale files to load into main.json
|
15 |
+
EXTRA_LOCALE_FILES = [
|
16 |
+
"nodeDefs.json",
|
17 |
+
"commands.json",
|
18 |
+
"settings.json",
|
19 |
+
]
|
20 |
+
|
21 |
+
|
22 |
+
def safe_load_json_file(file_path: str) -> dict:
|
23 |
+
if not os.path.exists(file_path):
|
24 |
+
return {}
|
25 |
+
|
26 |
+
try:
|
27 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
28 |
+
return json.load(f)
|
29 |
+
except json.JSONDecodeError:
|
30 |
+
logging.error(f"Error loading {file_path}")
|
31 |
+
return {}
|
32 |
+
|
33 |
+
|
34 |
+
class CustomNodeManager:
|
35 |
+
@lru_cache(maxsize=1)
|
36 |
+
def build_translations(self):
|
37 |
+
"""Load all custom nodes translations during initialization. Translations are
|
38 |
+
expected to be loaded from `locales/` folder.
|
39 |
+
|
40 |
+
The folder structure is expected to be the following:
|
41 |
+
- custom_nodes/
|
42 |
+
- custom_node_1/
|
43 |
+
- locales/
|
44 |
+
- en/
|
45 |
+
- main.json
|
46 |
+
- commands.json
|
47 |
+
- settings.json
|
48 |
+
|
49 |
+
returned translations are expected to be in the following format:
|
50 |
+
{
|
51 |
+
"en": {
|
52 |
+
"nodeDefs": {...},
|
53 |
+
"commands": {...},
|
54 |
+
"settings": {...},
|
55 |
+
...{other main.json keys}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
"""
|
59 |
+
|
60 |
+
translations = {}
|
61 |
+
|
62 |
+
for folder in folder_paths.get_folder_paths("custom_nodes"):
|
63 |
+
# Sort glob results for deterministic ordering
|
64 |
+
for custom_node_dir in sorted(glob.glob(os.path.join(folder, "*/"))):
|
65 |
+
locales_dir = os.path.join(custom_node_dir, "locales")
|
66 |
+
if not os.path.exists(locales_dir):
|
67 |
+
continue
|
68 |
+
|
69 |
+
for lang_dir in glob.glob(os.path.join(locales_dir, "*/")):
|
70 |
+
lang_code = os.path.basename(os.path.dirname(lang_dir))
|
71 |
+
|
72 |
+
if lang_code not in translations:
|
73 |
+
translations[lang_code] = {}
|
74 |
+
|
75 |
+
# Load main.json
|
76 |
+
main_file = os.path.join(lang_dir, "main.json")
|
77 |
+
node_translations = safe_load_json_file(main_file)
|
78 |
+
|
79 |
+
# Load extra locale files
|
80 |
+
for extra_file in EXTRA_LOCALE_FILES:
|
81 |
+
extra_file_path = os.path.join(lang_dir, extra_file)
|
82 |
+
key = extra_file.split(".")[0]
|
83 |
+
json_data = safe_load_json_file(extra_file_path)
|
84 |
+
if json_data:
|
85 |
+
node_translations[key] = json_data
|
86 |
+
|
87 |
+
if node_translations:
|
88 |
+
translations[lang_code] = merge_json_recursive(
|
89 |
+
translations[lang_code], node_translations
|
90 |
+
)
|
91 |
+
|
92 |
+
return translations
|
93 |
+
|
94 |
+
def add_routes(self, routes, webapp, loadedModules):
|
95 |
+
|
96 |
+
@routes.get("/workflow_templates")
|
97 |
+
async def get_workflow_templates(request):
|
98 |
+
"""Returns a web response that contains the map of custom_nodes names and their associated workflow templates. The ones without templates are omitted."""
|
99 |
+
files = [
|
100 |
+
file
|
101 |
+
for folder in folder_paths.get_folder_paths("custom_nodes")
|
102 |
+
for file in glob.glob(
|
103 |
+
os.path.join(folder, "*/example_workflows/*.json")
|
104 |
+
)
|
105 |
+
]
|
106 |
+
workflow_templates_dict = (
|
107 |
+
{}
|
108 |
+
) # custom_nodes folder name -> example workflow names
|
109 |
+
for file in files:
|
110 |
+
custom_nodes_name = os.path.basename(
|
111 |
+
os.path.dirname(os.path.dirname(file))
|
112 |
+
)
|
113 |
+
workflow_name = os.path.splitext(os.path.basename(file))[0]
|
114 |
+
workflow_templates_dict.setdefault(custom_nodes_name, []).append(
|
115 |
+
workflow_name
|
116 |
+
)
|
117 |
+
return web.json_response(workflow_templates_dict)
|
118 |
+
|
119 |
+
# Serve workflow templates from custom nodes.
|
120 |
+
for module_name, module_dir in loadedModules:
|
121 |
+
workflows_dir = os.path.join(module_dir, "example_workflows")
|
122 |
+
if os.path.exists(workflows_dir):
|
123 |
+
webapp.add_routes(
|
124 |
+
[
|
125 |
+
web.static(
|
126 |
+
"/api/workflow_templates/" + module_name, workflows_dir
|
127 |
+
)
|
128 |
+
]
|
129 |
+
)
|
130 |
+
|
131 |
+
@routes.get("/i18n")
|
132 |
+
async def get_i18n(request):
|
133 |
+
"""Returns translations from all custom nodes' locales folders."""
|
134 |
+
return web.json_response(self.build_translations())
|
app/frontend_management.py
ADDED
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
import argparse
|
3 |
+
import logging
|
4 |
+
import os
|
5 |
+
import re
|
6 |
+
import sys
|
7 |
+
import tempfile
|
8 |
+
import zipfile
|
9 |
+
import importlib
|
10 |
+
from dataclasses import dataclass
|
11 |
+
from functools import cached_property
|
12 |
+
from pathlib import Path
|
13 |
+
from typing import TypedDict, Optional
|
14 |
+
from importlib.metadata import version
|
15 |
+
|
16 |
+
import requests
|
17 |
+
from typing_extensions import NotRequired
|
18 |
+
|
19 |
+
from comfy.cli_args import DEFAULT_VERSION_STRING
|
20 |
+
import app.logger
|
21 |
+
|
22 |
+
# The path to the requirements.txt file
|
23 |
+
req_path = Path(__file__).parents[1] / "requirements.txt"
|
24 |
+
|
25 |
+
|
26 |
+
def frontend_install_warning_message():
|
27 |
+
"""The warning message to display when the frontend version is not up to date."""
|
28 |
+
|
29 |
+
extra = ""
|
30 |
+
if sys.flags.no_user_site:
|
31 |
+
extra = "-s "
|
32 |
+
return f"""
|
33 |
+
Please install the updated requirements.txt file by running:
|
34 |
+
{sys.executable} {extra}-m pip install -r {req_path}
|
35 |
+
|
36 |
+
This error is happening because the ComfyUI frontend is no longer shipped as part of the main repo but as a pip package instead.
|
37 |
+
|
38 |
+
If you are on the portable package you can run: update\\update_comfyui.bat to solve this problem
|
39 |
+
""".strip()
|
40 |
+
|
41 |
+
|
42 |
+
def check_frontend_version():
|
43 |
+
"""Check if the frontend version is up to date."""
|
44 |
+
|
45 |
+
def parse_version(version: str) -> tuple[int, int, int]:
|
46 |
+
return tuple(map(int, version.split(".")))
|
47 |
+
|
48 |
+
try:
|
49 |
+
frontend_version_str = version("comfyui-frontend-package")
|
50 |
+
frontend_version = parse_version(frontend_version_str)
|
51 |
+
with open(req_path, "r", encoding="utf-8") as f:
|
52 |
+
required_frontend = parse_version(f.readline().split("=")[-1])
|
53 |
+
if frontend_version < required_frontend:
|
54 |
+
app.logger.log_startup_warning(
|
55 |
+
f"""
|
56 |
+
________________________________________________________________________
|
57 |
+
WARNING WARNING WARNING WARNING WARNING
|
58 |
+
|
59 |
+
Installed frontend version {".".join(map(str, frontend_version))} is lower than the recommended version {".".join(map(str, required_frontend))}.
|
60 |
+
|
61 |
+
{frontend_install_warning_message()}
|
62 |
+
________________________________________________________________________
|
63 |
+
""".strip()
|
64 |
+
)
|
65 |
+
else:
|
66 |
+
logging.info("ComfyUI frontend version: {}".format(frontend_version_str))
|
67 |
+
except Exception as e:
|
68 |
+
logging.error(f"Failed to check frontend version: {e}")
|
69 |
+
|
70 |
+
|
71 |
+
REQUEST_TIMEOUT = 10 # seconds
|
72 |
+
|
73 |
+
|
74 |
+
class Asset(TypedDict):
|
75 |
+
url: str
|
76 |
+
|
77 |
+
|
78 |
+
class Release(TypedDict):
|
79 |
+
id: int
|
80 |
+
tag_name: str
|
81 |
+
name: str
|
82 |
+
prerelease: bool
|
83 |
+
created_at: str
|
84 |
+
published_at: str
|
85 |
+
body: str
|
86 |
+
assets: NotRequired[list[Asset]]
|
87 |
+
|
88 |
+
|
89 |
+
@dataclass
|
90 |
+
class FrontEndProvider:
|
91 |
+
owner: str
|
92 |
+
repo: str
|
93 |
+
|
94 |
+
@property
|
95 |
+
def folder_name(self) -> str:
|
96 |
+
return f"{self.owner}_{self.repo}"
|
97 |
+
|
98 |
+
@property
|
99 |
+
def release_url(self) -> str:
|
100 |
+
return f"https://api.github.com/repos/{self.owner}/{self.repo}/releases"
|
101 |
+
|
102 |
+
@cached_property
|
103 |
+
def all_releases(self) -> list[Release]:
|
104 |
+
releases = []
|
105 |
+
api_url = self.release_url
|
106 |
+
while api_url:
|
107 |
+
response = requests.get(api_url, timeout=REQUEST_TIMEOUT)
|
108 |
+
response.raise_for_status() # Raises an HTTPError if the response was an error
|
109 |
+
releases.extend(response.json())
|
110 |
+
# GitHub uses the Link header to provide pagination links. Check if it exists and update api_url accordingly.
|
111 |
+
if "next" in response.links:
|
112 |
+
api_url = response.links["next"]["url"]
|
113 |
+
else:
|
114 |
+
api_url = None
|
115 |
+
return releases
|
116 |
+
|
117 |
+
@cached_property
|
118 |
+
def latest_release(self) -> Release:
|
119 |
+
latest_release_url = f"{self.release_url}/latest"
|
120 |
+
response = requests.get(latest_release_url, timeout=REQUEST_TIMEOUT)
|
121 |
+
response.raise_for_status() # Raises an HTTPError if the response was an error
|
122 |
+
return response.json()
|
123 |
+
|
124 |
+
def get_release(self, version: str) -> Release:
|
125 |
+
if version == "latest":
|
126 |
+
return self.latest_release
|
127 |
+
else:
|
128 |
+
for release in self.all_releases:
|
129 |
+
if release["tag_name"] in [version, f"v{version}"]:
|
130 |
+
return release
|
131 |
+
raise ValueError(f"Version {version} not found in releases")
|
132 |
+
|
133 |
+
|
134 |
+
def download_release_asset_zip(release: Release, destination_path: str) -> None:
|
135 |
+
"""Download dist.zip from github release."""
|
136 |
+
asset_url = None
|
137 |
+
for asset in release.get("assets", []):
|
138 |
+
if asset["name"] == "dist.zip":
|
139 |
+
asset_url = asset["url"]
|
140 |
+
break
|
141 |
+
|
142 |
+
if not asset_url:
|
143 |
+
raise ValueError("dist.zip not found in the release assets")
|
144 |
+
|
145 |
+
# Use a temporary file to download the zip content
|
146 |
+
with tempfile.TemporaryFile() as tmp_file:
|
147 |
+
headers = {"Accept": "application/octet-stream"}
|
148 |
+
response = requests.get(
|
149 |
+
asset_url, headers=headers, allow_redirects=True, timeout=REQUEST_TIMEOUT
|
150 |
+
)
|
151 |
+
response.raise_for_status() # Ensure we got a successful response
|
152 |
+
|
153 |
+
# Write the content to the temporary file
|
154 |
+
tmp_file.write(response.content)
|
155 |
+
|
156 |
+
# Go back to the beginning of the temporary file
|
157 |
+
tmp_file.seek(0)
|
158 |
+
|
159 |
+
# Extract the zip file content to the destination path
|
160 |
+
with zipfile.ZipFile(tmp_file, "r") as zip_ref:
|
161 |
+
zip_ref.extractall(destination_path)
|
162 |
+
|
163 |
+
|
164 |
+
class FrontendManager:
|
165 |
+
CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions")
|
166 |
+
|
167 |
+
@classmethod
|
168 |
+
def default_frontend_path(cls) -> str:
|
169 |
+
try:
|
170 |
+
import comfyui_frontend_package
|
171 |
+
|
172 |
+
return str(importlib.resources.files(comfyui_frontend_package) / "static")
|
173 |
+
except ImportError:
|
174 |
+
logging.error(
|
175 |
+
f"""
|
176 |
+
********** ERROR ***********
|
177 |
+
|
178 |
+
comfyui-frontend-package is not installed.
|
179 |
+
|
180 |
+
{frontend_install_warning_message()}
|
181 |
+
|
182 |
+
********** ERROR ***********
|
183 |
+
""".strip()
|
184 |
+
)
|
185 |
+
sys.exit(-1)
|
186 |
+
|
187 |
+
@classmethod
|
188 |
+
def templates_path(cls) -> str:
|
189 |
+
try:
|
190 |
+
import comfyui_workflow_templates
|
191 |
+
|
192 |
+
return str(
|
193 |
+
importlib.resources.files(comfyui_workflow_templates) / "templates"
|
194 |
+
)
|
195 |
+
except ImportError:
|
196 |
+
logging.error(
|
197 |
+
f"""
|
198 |
+
********** ERROR ***********
|
199 |
+
|
200 |
+
comfyui-workflow-templates is not installed.
|
201 |
+
|
202 |
+
{frontend_install_warning_message()}
|
203 |
+
|
204 |
+
********** ERROR ***********
|
205 |
+
""".strip()
|
206 |
+
)
|
207 |
+
|
208 |
+
@classmethod
|
209 |
+
def parse_version_string(cls, value: str) -> tuple[str, str, str]:
|
210 |
+
"""
|
211 |
+
Args:
|
212 |
+
value (str): The version string to parse.
|
213 |
+
|
214 |
+
Returns:
|
215 |
+
tuple[str, str]: A tuple containing provider name and version.
|
216 |
+
|
217 |
+
Raises:
|
218 |
+
argparse.ArgumentTypeError: If the version string is invalid.
|
219 |
+
"""
|
220 |
+
VERSION_PATTERN = r"^([a-zA-Z0-9][a-zA-Z0-9-]{0,38})/([a-zA-Z0-9_.-]+)@(v?\d+\.\d+\.\d+|latest)$"
|
221 |
+
match_result = re.match(VERSION_PATTERN, value)
|
222 |
+
if match_result is None:
|
223 |
+
raise argparse.ArgumentTypeError(f"Invalid version string: {value}")
|
224 |
+
|
225 |
+
return match_result.group(1), match_result.group(2), match_result.group(3)
|
226 |
+
|
227 |
+
@classmethod
|
228 |
+
def init_frontend_unsafe(
|
229 |
+
cls, version_string: str, provider: Optional[FrontEndProvider] = None
|
230 |
+
) -> str:
|
231 |
+
"""
|
232 |
+
Initializes the frontend for the specified version.
|
233 |
+
|
234 |
+
Args:
|
235 |
+
version_string (str): The version string.
|
236 |
+
provider (FrontEndProvider, optional): The provider to use. Defaults to None.
|
237 |
+
|
238 |
+
Returns:
|
239 |
+
str: The path to the initialized frontend.
|
240 |
+
|
241 |
+
Raises:
|
242 |
+
Exception: If there is an error during the initialization process.
|
243 |
+
main error source might be request timeout or invalid URL.
|
244 |
+
"""
|
245 |
+
if version_string == DEFAULT_VERSION_STRING:
|
246 |
+
check_frontend_version()
|
247 |
+
return cls.default_frontend_path()
|
248 |
+
|
249 |
+
repo_owner, repo_name, version = cls.parse_version_string(version_string)
|
250 |
+
|
251 |
+
if version.startswith("v"):
|
252 |
+
expected_path = str(
|
253 |
+
Path(cls.CUSTOM_FRONTENDS_ROOT)
|
254 |
+
/ f"{repo_owner}_{repo_name}"
|
255 |
+
/ version.lstrip("v")
|
256 |
+
)
|
257 |
+
if os.path.exists(expected_path):
|
258 |
+
logging.info(
|
259 |
+
f"Using existing copy of specific frontend version tag: {repo_owner}/{repo_name}@{version}"
|
260 |
+
)
|
261 |
+
return expected_path
|
262 |
+
|
263 |
+
logging.info(
|
264 |
+
f"Initializing frontend: {repo_owner}/{repo_name}@{version}, requesting version details from GitHub..."
|
265 |
+
)
|
266 |
+
|
267 |
+
provider = provider or FrontEndProvider(repo_owner, repo_name)
|
268 |
+
release = provider.get_release(version)
|
269 |
+
|
270 |
+
semantic_version = release["tag_name"].lstrip("v")
|
271 |
+
web_root = str(
|
272 |
+
Path(cls.CUSTOM_FRONTENDS_ROOT) / provider.folder_name / semantic_version
|
273 |
+
)
|
274 |
+
if not os.path.exists(web_root):
|
275 |
+
try:
|
276 |
+
os.makedirs(web_root, exist_ok=True)
|
277 |
+
logging.info(
|
278 |
+
"Downloading frontend(%s) version(%s) to (%s)",
|
279 |
+
provider.folder_name,
|
280 |
+
semantic_version,
|
281 |
+
web_root,
|
282 |
+
)
|
283 |
+
logging.debug(release)
|
284 |
+
download_release_asset_zip(release, destination_path=web_root)
|
285 |
+
finally:
|
286 |
+
# Clean up the directory if it is empty, i.e. the download failed
|
287 |
+
if not os.listdir(web_root):
|
288 |
+
os.rmdir(web_root)
|
289 |
+
|
290 |
+
return web_root
|
291 |
+
|
292 |
+
@classmethod
|
293 |
+
def init_frontend(cls, version_string: str) -> str:
|
294 |
+
"""
|
295 |
+
Initializes the frontend with the specified version string.
|
296 |
+
|
297 |
+
Args:
|
298 |
+
version_string (str): The version string to initialize the frontend with.
|
299 |
+
|
300 |
+
Returns:
|
301 |
+
str: The path of the initialized frontend.
|
302 |
+
"""
|
303 |
+
try:
|
304 |
+
return cls.init_frontend_unsafe(version_string)
|
305 |
+
except Exception as e:
|
306 |
+
logging.error("Failed to initialize frontend: %s", e)
|
307 |
+
logging.info("Falling back to the default frontend.")
|
308 |
+
check_frontend_version()
|
309 |
+
return cls.default_frontend_path()
|
app/logger.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import deque
|
2 |
+
from datetime import datetime
|
3 |
+
import io
|
4 |
+
import logging
|
5 |
+
import sys
|
6 |
+
import threading
|
7 |
+
|
8 |
+
logs = None
|
9 |
+
stdout_interceptor = None
|
10 |
+
stderr_interceptor = None
|
11 |
+
|
12 |
+
|
13 |
+
class LogInterceptor(io.TextIOWrapper):
|
14 |
+
def __init__(self, stream, *args, **kwargs):
|
15 |
+
buffer = stream.buffer
|
16 |
+
encoding = stream.encoding
|
17 |
+
super().__init__(buffer, *args, **kwargs, encoding=encoding, line_buffering=stream.line_buffering)
|
18 |
+
self._lock = threading.Lock()
|
19 |
+
self._flush_callbacks = []
|
20 |
+
self._logs_since_flush = []
|
21 |
+
|
22 |
+
def write(self, data):
|
23 |
+
entry = {"t": datetime.now().isoformat(), "m": data}
|
24 |
+
with self._lock:
|
25 |
+
self._logs_since_flush.append(entry)
|
26 |
+
|
27 |
+
# Simple handling for cr to overwrite the last output if it isnt a full line
|
28 |
+
# else logs just get full of progress messages
|
29 |
+
if isinstance(data, str) and data.startswith("\r") and not logs[-1]["m"].endswith("\n"):
|
30 |
+
logs.pop()
|
31 |
+
logs.append(entry)
|
32 |
+
super().write(data)
|
33 |
+
|
34 |
+
def flush(self):
|
35 |
+
super().flush()
|
36 |
+
for cb in self._flush_callbacks:
|
37 |
+
cb(self._logs_since_flush)
|
38 |
+
self._logs_since_flush = []
|
39 |
+
|
40 |
+
def on_flush(self, callback):
|
41 |
+
self._flush_callbacks.append(callback)
|
42 |
+
|
43 |
+
|
44 |
+
def get_logs():
|
45 |
+
return logs
|
46 |
+
|
47 |
+
|
48 |
+
def on_flush(callback):
|
49 |
+
if stdout_interceptor is not None:
|
50 |
+
stdout_interceptor.on_flush(callback)
|
51 |
+
if stderr_interceptor is not None:
|
52 |
+
stderr_interceptor.on_flush(callback)
|
53 |
+
|
54 |
+
def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool = False):
|
55 |
+
global logs
|
56 |
+
if logs:
|
57 |
+
return
|
58 |
+
|
59 |
+
# Override output streams and log to buffer
|
60 |
+
logs = deque(maxlen=capacity)
|
61 |
+
|
62 |
+
global stdout_interceptor
|
63 |
+
global stderr_interceptor
|
64 |
+
stdout_interceptor = sys.stdout = LogInterceptor(sys.stdout)
|
65 |
+
stderr_interceptor = sys.stderr = LogInterceptor(sys.stderr)
|
66 |
+
|
67 |
+
# Setup default global logger
|
68 |
+
logger = logging.getLogger()
|
69 |
+
logger.setLevel(log_level)
|
70 |
+
|
71 |
+
stream_handler = logging.StreamHandler()
|
72 |
+
stream_handler.setFormatter(logging.Formatter("%(message)s"))
|
73 |
+
|
74 |
+
if use_stdout:
|
75 |
+
# Only errors and critical to stderr
|
76 |
+
stream_handler.addFilter(lambda record: not record.levelno < logging.ERROR)
|
77 |
+
|
78 |
+
# Lesser to stdout
|
79 |
+
stdout_handler = logging.StreamHandler(sys.stdout)
|
80 |
+
stdout_handler.setFormatter(logging.Formatter("%(message)s"))
|
81 |
+
stdout_handler.addFilter(lambda record: record.levelno < logging.ERROR)
|
82 |
+
logger.addHandler(stdout_handler)
|
83 |
+
|
84 |
+
logger.addHandler(stream_handler)
|
85 |
+
|
86 |
+
|
87 |
+
STARTUP_WARNINGS = []
|
88 |
+
|
89 |
+
|
90 |
+
def log_startup_warning(msg):
|
91 |
+
logging.warning(msg)
|
92 |
+
STARTUP_WARNINGS.append(msg)
|
93 |
+
|
94 |
+
|
95 |
+
def print_startup_warnings():
|
96 |
+
for s in STARTUP_WARNINGS:
|
97 |
+
logging.warning(s)
|
98 |
+
STARTUP_WARNINGS.clear()
|
app/model_manager.py
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import base64
|
5 |
+
import json
|
6 |
+
import time
|
7 |
+
import logging
|
8 |
+
import folder_paths
|
9 |
+
import glob
|
10 |
+
import comfy.utils
|
11 |
+
from aiohttp import web
|
12 |
+
from PIL import Image
|
13 |
+
from io import BytesIO
|
14 |
+
from folder_paths import map_legacy, filter_files_extensions, filter_files_content_types
|
15 |
+
|
16 |
+
|
17 |
+
class ModelFileManager:
|
18 |
+
def __init__(self) -> None:
|
19 |
+
self.cache: dict[str, tuple[list[dict], dict[str, float], float]] = {}
|
20 |
+
|
21 |
+
def get_cache(self, key: str, default=None) -> tuple[list[dict], dict[str, float], float] | None:
|
22 |
+
return self.cache.get(key, default)
|
23 |
+
|
24 |
+
def set_cache(self, key: str, value: tuple[list[dict], dict[str, float], float]):
|
25 |
+
self.cache[key] = value
|
26 |
+
|
27 |
+
def clear_cache(self):
|
28 |
+
self.cache.clear()
|
29 |
+
|
30 |
+
def add_routes(self, routes):
|
31 |
+
# NOTE: This is an experiment to replace `/models`
|
32 |
+
@routes.get("/experiment/models")
|
33 |
+
async def get_model_folders(request):
|
34 |
+
model_types = list(folder_paths.folder_names_and_paths.keys())
|
35 |
+
folder_black_list = ["configs", "custom_nodes"]
|
36 |
+
output_folders: list[dict] = []
|
37 |
+
for folder in model_types:
|
38 |
+
if folder in folder_black_list:
|
39 |
+
continue
|
40 |
+
output_folders.append({"name": folder, "folders": folder_paths.get_folder_paths(folder)})
|
41 |
+
return web.json_response(output_folders)
|
42 |
+
|
43 |
+
# NOTE: This is an experiment to replace `/models/{folder}`
|
44 |
+
@routes.get("/experiment/models/{folder}")
|
45 |
+
async def get_all_models(request):
|
46 |
+
folder = request.match_info.get("folder", None)
|
47 |
+
if not folder in folder_paths.folder_names_and_paths:
|
48 |
+
return web.Response(status=404)
|
49 |
+
files = self.get_model_file_list(folder)
|
50 |
+
return web.json_response(files)
|
51 |
+
|
52 |
+
@routes.get("/experiment/models/preview/{folder}/{path_index}/{filename:.*}")
|
53 |
+
async def get_model_preview(request):
|
54 |
+
folder_name = request.match_info.get("folder", None)
|
55 |
+
path_index = int(request.match_info.get("path_index", None))
|
56 |
+
filename = request.match_info.get("filename", None)
|
57 |
+
|
58 |
+
if not folder_name in folder_paths.folder_names_and_paths:
|
59 |
+
return web.Response(status=404)
|
60 |
+
|
61 |
+
folders = folder_paths.folder_names_and_paths[folder_name]
|
62 |
+
folder = folders[0][path_index]
|
63 |
+
full_filename = os.path.join(folder, filename)
|
64 |
+
|
65 |
+
previews = self.get_model_previews(full_filename)
|
66 |
+
default_preview = previews[0] if len(previews) > 0 else None
|
67 |
+
if default_preview is None or (isinstance(default_preview, str) and not os.path.isfile(default_preview)):
|
68 |
+
return web.Response(status=404)
|
69 |
+
|
70 |
+
try:
|
71 |
+
with Image.open(default_preview) as img:
|
72 |
+
img_bytes = BytesIO()
|
73 |
+
img.save(img_bytes, format="WEBP")
|
74 |
+
img_bytes.seek(0)
|
75 |
+
return web.Response(body=img_bytes.getvalue(), content_type="image/webp")
|
76 |
+
except:
|
77 |
+
return web.Response(status=404)
|
78 |
+
|
79 |
+
def get_model_file_list(self, folder_name: str):
|
80 |
+
folder_name = map_legacy(folder_name)
|
81 |
+
folders = folder_paths.folder_names_and_paths[folder_name]
|
82 |
+
output_list: list[dict] = []
|
83 |
+
|
84 |
+
for index, folder in enumerate(folders[0]):
|
85 |
+
if not os.path.isdir(folder):
|
86 |
+
continue
|
87 |
+
out = self.cache_model_file_list_(folder)
|
88 |
+
if out is None:
|
89 |
+
out = self.recursive_search_models_(folder, index)
|
90 |
+
self.set_cache(folder, out)
|
91 |
+
output_list.extend(out[0])
|
92 |
+
|
93 |
+
return output_list
|
94 |
+
|
95 |
+
def cache_model_file_list_(self, folder: str):
|
96 |
+
model_file_list_cache = self.get_cache(folder)
|
97 |
+
|
98 |
+
if model_file_list_cache is None:
|
99 |
+
return None
|
100 |
+
if not os.path.isdir(folder):
|
101 |
+
return None
|
102 |
+
if os.path.getmtime(folder) != model_file_list_cache[1]:
|
103 |
+
return None
|
104 |
+
for x in model_file_list_cache[1]:
|
105 |
+
time_modified = model_file_list_cache[1][x]
|
106 |
+
folder = x
|
107 |
+
if os.path.getmtime(folder) != time_modified:
|
108 |
+
return None
|
109 |
+
|
110 |
+
return model_file_list_cache
|
111 |
+
|
112 |
+
def recursive_search_models_(self, directory: str, pathIndex: int) -> tuple[list[str], dict[str, float], float]:
|
113 |
+
if not os.path.isdir(directory):
|
114 |
+
return [], {}, time.perf_counter()
|
115 |
+
|
116 |
+
excluded_dir_names = [".git"]
|
117 |
+
# TODO use settings
|
118 |
+
include_hidden_files = False
|
119 |
+
|
120 |
+
result: list[str] = []
|
121 |
+
dirs: dict[str, float] = {}
|
122 |
+
|
123 |
+
for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
|
124 |
+
subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
|
125 |
+
if not include_hidden_files:
|
126 |
+
subdirs[:] = [d for d in subdirs if not d.startswith(".")]
|
127 |
+
filenames = [f for f in filenames if not f.startswith(".")]
|
128 |
+
|
129 |
+
filenames = filter_files_extensions(filenames, folder_paths.supported_pt_extensions)
|
130 |
+
|
131 |
+
for file_name in filenames:
|
132 |
+
try:
|
133 |
+
relative_path = os.path.relpath(os.path.join(dirpath, file_name), directory)
|
134 |
+
result.append(relative_path)
|
135 |
+
except:
|
136 |
+
logging.warning(f"Warning: Unable to access {file_name}. Skipping this file.")
|
137 |
+
continue
|
138 |
+
|
139 |
+
for d in subdirs:
|
140 |
+
path: str = os.path.join(dirpath, d)
|
141 |
+
try:
|
142 |
+
dirs[path] = os.path.getmtime(path)
|
143 |
+
except FileNotFoundError:
|
144 |
+
logging.warning(f"Warning: Unable to access {path}. Skipping this path.")
|
145 |
+
continue
|
146 |
+
|
147 |
+
return [{"name": f, "pathIndex": pathIndex} for f in result], dirs, time.perf_counter()
|
148 |
+
|
149 |
+
def get_model_previews(self, filepath: str) -> list[str | BytesIO]:
|
150 |
+
dirname = os.path.dirname(filepath)
|
151 |
+
|
152 |
+
if not os.path.exists(dirname):
|
153 |
+
return []
|
154 |
+
|
155 |
+
basename = os.path.splitext(filepath)[0]
|
156 |
+
match_files = glob.glob(f"{basename}.*", recursive=False)
|
157 |
+
image_files = filter_files_content_types(match_files, "image")
|
158 |
+
safetensors_file = next(filter(lambda x: x.endswith(".safetensors"), match_files), None)
|
159 |
+
safetensors_metadata = {}
|
160 |
+
|
161 |
+
result: list[str | BytesIO] = []
|
162 |
+
|
163 |
+
for filename in image_files:
|
164 |
+
_basename = os.path.splitext(filename)[0]
|
165 |
+
if _basename == basename:
|
166 |
+
result.append(filename)
|
167 |
+
if _basename == f"{basename}.preview":
|
168 |
+
result.append(filename)
|
169 |
+
|
170 |
+
if safetensors_file:
|
171 |
+
safetensors_filepath = os.path.join(dirname, safetensors_file)
|
172 |
+
header = comfy.utils.safetensors_header(safetensors_filepath, max_size=8*1024*1024)
|
173 |
+
if header:
|
174 |
+
safetensors_metadata = json.loads(header)
|
175 |
+
safetensors_images = safetensors_metadata.get("__metadata__", {}).get("ssmd_cover_images", None)
|
176 |
+
if safetensors_images:
|
177 |
+
safetensors_images = json.loads(safetensors_images)
|
178 |
+
for image in safetensors_images:
|
179 |
+
result.append(BytesIO(base64.b64decode(image)))
|
180 |
+
|
181 |
+
return result
|
182 |
+
|
183 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
184 |
+
self.clear_cache()
|
app/user_manager.py
ADDED
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
import uuid
|
6 |
+
import glob
|
7 |
+
import shutil
|
8 |
+
import logging
|
9 |
+
from aiohttp import web
|
10 |
+
from urllib import parse
|
11 |
+
from comfy.cli_args import args
|
12 |
+
import folder_paths
|
13 |
+
from .app_settings import AppSettings
|
14 |
+
from typing import TypedDict
|
15 |
+
|
16 |
+
default_user = "default"
|
17 |
+
|
18 |
+
|
19 |
+
class FileInfo(TypedDict):
|
20 |
+
path: str
|
21 |
+
size: int
|
22 |
+
modified: int
|
23 |
+
|
24 |
+
|
25 |
+
def get_file_info(path: str, relative_to: str) -> FileInfo:
|
26 |
+
return {
|
27 |
+
"path": os.path.relpath(path, relative_to).replace(os.sep, '/'),
|
28 |
+
"size": os.path.getsize(path),
|
29 |
+
"modified": os.path.getmtime(path)
|
30 |
+
}
|
31 |
+
|
32 |
+
|
33 |
+
class UserManager():
|
34 |
+
def __init__(self):
|
35 |
+
user_directory = folder_paths.get_user_directory()
|
36 |
+
|
37 |
+
self.settings = AppSettings(self)
|
38 |
+
if not os.path.exists(user_directory):
|
39 |
+
os.makedirs(user_directory, exist_ok=True)
|
40 |
+
if not args.multi_user:
|
41 |
+
logging.warning("****** User settings have been changed to be stored on the server instead of browser storage. ******")
|
42 |
+
logging.warning("****** For multi-user setups add the --multi-user CLI argument to enable multiple user profiles. ******")
|
43 |
+
|
44 |
+
if args.multi_user:
|
45 |
+
if os.path.isfile(self.get_users_file()):
|
46 |
+
with open(self.get_users_file()) as f:
|
47 |
+
self.users = json.load(f)
|
48 |
+
else:
|
49 |
+
self.users = {}
|
50 |
+
else:
|
51 |
+
self.users = {"default": "default"}
|
52 |
+
|
53 |
+
def get_users_file(self):
|
54 |
+
return os.path.join(folder_paths.get_user_directory(), "users.json")
|
55 |
+
|
56 |
+
def get_request_user_id(self, request):
|
57 |
+
user = "default"
|
58 |
+
if args.multi_user and "comfy-user" in request.headers:
|
59 |
+
user = request.headers["comfy-user"]
|
60 |
+
|
61 |
+
if user not in self.users:
|
62 |
+
raise KeyError("Unknown user: " + user)
|
63 |
+
|
64 |
+
return user
|
65 |
+
|
66 |
+
def get_request_user_filepath(self, request, file, type="userdata", create_dir=True):
|
67 |
+
user_directory = folder_paths.get_user_directory()
|
68 |
+
|
69 |
+
if type == "userdata":
|
70 |
+
root_dir = user_directory
|
71 |
+
else:
|
72 |
+
raise KeyError("Unknown filepath type:" + type)
|
73 |
+
|
74 |
+
user = self.get_request_user_id(request)
|
75 |
+
path = user_root = os.path.abspath(os.path.join(root_dir, user))
|
76 |
+
|
77 |
+
# prevent leaving /{type}
|
78 |
+
if os.path.commonpath((root_dir, user_root)) != root_dir:
|
79 |
+
return None
|
80 |
+
|
81 |
+
if file is not None:
|
82 |
+
# Check if filename is url encoded
|
83 |
+
if "%" in file:
|
84 |
+
file = parse.unquote(file)
|
85 |
+
|
86 |
+
# prevent leaving /{type}/{user}
|
87 |
+
path = os.path.abspath(os.path.join(user_root, file))
|
88 |
+
if os.path.commonpath((user_root, path)) != user_root:
|
89 |
+
return None
|
90 |
+
|
91 |
+
parent = os.path.split(path)[0]
|
92 |
+
|
93 |
+
if create_dir and not os.path.exists(parent):
|
94 |
+
os.makedirs(parent, exist_ok=True)
|
95 |
+
|
96 |
+
return path
|
97 |
+
|
98 |
+
def add_user(self, name):
|
99 |
+
name = name.strip()
|
100 |
+
if not name:
|
101 |
+
raise ValueError("username not provided")
|
102 |
+
user_id = re.sub("[^a-zA-Z0-9-_]+", '-', name)
|
103 |
+
user_id = user_id + "_" + str(uuid.uuid4())
|
104 |
+
|
105 |
+
self.users[user_id] = name
|
106 |
+
|
107 |
+
with open(self.get_users_file(), "w") as f:
|
108 |
+
json.dump(self.users, f)
|
109 |
+
|
110 |
+
return user_id
|
111 |
+
|
112 |
+
def add_routes(self, routes):
|
113 |
+
self.settings.add_routes(routes)
|
114 |
+
|
115 |
+
@routes.get("/users")
|
116 |
+
async def get_users(request):
|
117 |
+
if args.multi_user:
|
118 |
+
return web.json_response({"storage": "server", "users": self.users})
|
119 |
+
else:
|
120 |
+
user_dir = self.get_request_user_filepath(request, None, create_dir=False)
|
121 |
+
return web.json_response({
|
122 |
+
"storage": "server",
|
123 |
+
"migrated": os.path.exists(user_dir)
|
124 |
+
})
|
125 |
+
|
126 |
+
@routes.post("/users")
|
127 |
+
async def post_users(request):
|
128 |
+
body = await request.json()
|
129 |
+
username = body["username"]
|
130 |
+
if username in self.users.values():
|
131 |
+
return web.json_response({"error": "Duplicate username."}, status=400)
|
132 |
+
|
133 |
+
user_id = self.add_user(username)
|
134 |
+
return web.json_response(user_id)
|
135 |
+
|
136 |
+
@routes.get("/userdata")
|
137 |
+
async def listuserdata(request):
|
138 |
+
"""
|
139 |
+
List user data files in a specified directory.
|
140 |
+
|
141 |
+
This endpoint allows listing files in a user's data directory, with options for recursion,
|
142 |
+
full file information, and path splitting.
|
143 |
+
|
144 |
+
Query Parameters:
|
145 |
+
- dir (required): The directory to list files from.
|
146 |
+
- recurse (optional): If "true", recursively list files in subdirectories.
|
147 |
+
- full_info (optional): If "true", return detailed file information (path, size, modified time).
|
148 |
+
- split (optional): If "true", split file paths into components (only applies when full_info is false).
|
149 |
+
|
150 |
+
Returns:
|
151 |
+
- 400: If 'dir' parameter is missing.
|
152 |
+
- 403: If the requested path is not allowed.
|
153 |
+
- 404: If the requested directory does not exist.
|
154 |
+
- 200: JSON response with the list of files or file information.
|
155 |
+
|
156 |
+
The response format depends on the query parameters:
|
157 |
+
- Default: List of relative file paths.
|
158 |
+
- full_info=true: List of dictionaries with file details.
|
159 |
+
- split=true (and full_info=false): List of lists, each containing path components.
|
160 |
+
"""
|
161 |
+
directory = request.rel_url.query.get('dir', '')
|
162 |
+
if not directory:
|
163 |
+
return web.Response(status=400, text="Directory not provided")
|
164 |
+
|
165 |
+
path = self.get_request_user_filepath(request, directory)
|
166 |
+
if not path:
|
167 |
+
return web.Response(status=403, text="Invalid directory")
|
168 |
+
|
169 |
+
if not os.path.exists(path):
|
170 |
+
return web.Response(status=404, text="Directory not found")
|
171 |
+
|
172 |
+
recurse = request.rel_url.query.get('recurse', '').lower() == "true"
|
173 |
+
full_info = request.rel_url.query.get('full_info', '').lower() == "true"
|
174 |
+
split_path = request.rel_url.query.get('split', '').lower() == "true"
|
175 |
+
|
176 |
+
# Use different patterns based on whether we're recursing or not
|
177 |
+
if recurse:
|
178 |
+
pattern = os.path.join(glob.escape(path), '**', '*')
|
179 |
+
else:
|
180 |
+
pattern = os.path.join(glob.escape(path), '*')
|
181 |
+
|
182 |
+
def process_full_path(full_path: str) -> FileInfo | str | list[str]:
|
183 |
+
if full_info:
|
184 |
+
return get_file_info(full_path, path)
|
185 |
+
|
186 |
+
rel_path = os.path.relpath(full_path, path).replace(os.sep, '/')
|
187 |
+
if split_path:
|
188 |
+
return [rel_path] + rel_path.split('/')
|
189 |
+
|
190 |
+
return rel_path
|
191 |
+
|
192 |
+
results = [
|
193 |
+
process_full_path(full_path)
|
194 |
+
for full_path in glob.glob(pattern, recursive=recurse)
|
195 |
+
if os.path.isfile(full_path)
|
196 |
+
]
|
197 |
+
|
198 |
+
return web.json_response(results)
|
199 |
+
|
200 |
+
def get_user_data_path(request, check_exists = False, param = "file"):
|
201 |
+
file = request.match_info.get(param, None)
|
202 |
+
if not file:
|
203 |
+
return web.Response(status=400)
|
204 |
+
|
205 |
+
path = self.get_request_user_filepath(request, file)
|
206 |
+
if not path:
|
207 |
+
return web.Response(status=403)
|
208 |
+
|
209 |
+
if check_exists and not os.path.exists(path):
|
210 |
+
return web.Response(status=404)
|
211 |
+
|
212 |
+
return path
|
213 |
+
|
214 |
+
@routes.get("/userdata/{file}")
|
215 |
+
async def getuserdata(request):
|
216 |
+
path = get_user_data_path(request, check_exists=True)
|
217 |
+
if not isinstance(path, str):
|
218 |
+
return path
|
219 |
+
|
220 |
+
return web.FileResponse(path)
|
221 |
+
|
222 |
+
@routes.post("/userdata/{file}")
|
223 |
+
async def post_userdata(request):
|
224 |
+
"""
|
225 |
+
Upload or update a user data file.
|
226 |
+
|
227 |
+
This endpoint handles file uploads to a user's data directory, with options for
|
228 |
+
controlling overwrite behavior and response format.
|
229 |
+
|
230 |
+
Query Parameters:
|
231 |
+
- overwrite (optional): If "false", prevents overwriting existing files. Defaults to "true".
|
232 |
+
- full_info (optional): If "true", returns detailed file information (path, size, modified time).
|
233 |
+
If "false", returns only the relative file path.
|
234 |
+
|
235 |
+
Path Parameters:
|
236 |
+
- file: The target file path (URL encoded if necessary).
|
237 |
+
|
238 |
+
Returns:
|
239 |
+
- 400: If 'file' parameter is missing.
|
240 |
+
- 403: If the requested path is not allowed.
|
241 |
+
- 409: If overwrite=false and the file already exists.
|
242 |
+
- 200: JSON response with either:
|
243 |
+
- Full file information (if full_info=true)
|
244 |
+
- Relative file path (if full_info=false)
|
245 |
+
|
246 |
+
The request body should contain the raw file content to be written.
|
247 |
+
"""
|
248 |
+
path = get_user_data_path(request)
|
249 |
+
if not isinstance(path, str):
|
250 |
+
return path
|
251 |
+
|
252 |
+
overwrite = request.query.get("overwrite", 'true') != "false"
|
253 |
+
full_info = request.query.get('full_info', 'false').lower() == "true"
|
254 |
+
|
255 |
+
if not overwrite and os.path.exists(path):
|
256 |
+
return web.Response(status=409, text="File already exists")
|
257 |
+
|
258 |
+
body = await request.read()
|
259 |
+
|
260 |
+
with open(path, "wb") as f:
|
261 |
+
f.write(body)
|
262 |
+
|
263 |
+
user_path = self.get_request_user_filepath(request, None)
|
264 |
+
if full_info:
|
265 |
+
resp = get_file_info(path, user_path)
|
266 |
+
else:
|
267 |
+
resp = os.path.relpath(path, user_path)
|
268 |
+
|
269 |
+
return web.json_response(resp)
|
270 |
+
|
271 |
+
@routes.delete("/userdata/{file}")
|
272 |
+
async def delete_userdata(request):
|
273 |
+
path = get_user_data_path(request, check_exists=True)
|
274 |
+
if not isinstance(path, str):
|
275 |
+
return path
|
276 |
+
|
277 |
+
os.remove(path)
|
278 |
+
|
279 |
+
return web.Response(status=204)
|
280 |
+
|
281 |
+
@routes.post("/userdata/{file}/move/{dest}")
|
282 |
+
async def move_userdata(request):
|
283 |
+
"""
|
284 |
+
Move or rename a user data file.
|
285 |
+
|
286 |
+
This endpoint handles moving or renaming files within a user's data directory, with options for
|
287 |
+
controlling overwrite behavior and response format.
|
288 |
+
|
289 |
+
Path Parameters:
|
290 |
+
- file: The source file path (URL encoded if necessary)
|
291 |
+
- dest: The destination file path (URL encoded if necessary)
|
292 |
+
|
293 |
+
Query Parameters:
|
294 |
+
- overwrite (optional): If "false", prevents overwriting existing files. Defaults to "true".
|
295 |
+
- full_info (optional): If "true", returns detailed file information (path, size, modified time).
|
296 |
+
If "false", returns only the relative file path.
|
297 |
+
|
298 |
+
Returns:
|
299 |
+
- 400: If either 'file' or 'dest' parameter is missing
|
300 |
+
- 403: If either requested path is not allowed
|
301 |
+
- 404: If the source file does not exist
|
302 |
+
- 409: If overwrite=false and the destination file already exists
|
303 |
+
- 200: JSON response with either:
|
304 |
+
- Full file information (if full_info=true)
|
305 |
+
- Relative file path (if full_info=false)
|
306 |
+
"""
|
307 |
+
source = get_user_data_path(request, check_exists=True)
|
308 |
+
if not isinstance(source, str):
|
309 |
+
return source
|
310 |
+
|
311 |
+
dest = get_user_data_path(request, check_exists=False, param="dest")
|
312 |
+
if not isinstance(source, str):
|
313 |
+
return dest
|
314 |
+
|
315 |
+
overwrite = request.query.get("overwrite", 'true') != "false"
|
316 |
+
full_info = request.query.get('full_info', 'false').lower() == "true"
|
317 |
+
|
318 |
+
if not overwrite and os.path.exists(dest):
|
319 |
+
return web.Response(status=409, text="File already exists")
|
320 |
+
|
321 |
+
logging.info(f"moving '{source}' -> '{dest}'")
|
322 |
+
shutil.move(source, dest)
|
323 |
+
|
324 |
+
user_path = self.get_request_user_filepath(request, None)
|
325 |
+
if full_info:
|
326 |
+
resp = get_file_info(dest, user_path)
|
327 |
+
else:
|
328 |
+
resp = os.path.relpath(dest, user_path)
|
329 |
+
|
330 |
+
return web.json_response(resp)
|
comfy/__pycache__/checkpoint_pickle.cpython-312.pyc
ADDED
Binary file (892 Bytes). View file
|
|
comfy/__pycache__/cli_args.cpython-312.pyc
ADDED
Binary file (16.6 kB). View file
|
|
comfy/__pycache__/clip_model.cpython-312.pyc
ADDED
Binary file (18.7 kB). View file
|
|
comfy/__pycache__/clip_vision.cpython-312.pyc
ADDED
Binary file (12.2 kB). View file
|
|
comfy/__pycache__/conds.cpython-312.pyc
ADDED
Binary file (4.85 kB). View file
|
|