Spaces:
Running
on
L40S
Running
on
L40S
Commit
•
4450790
0
Parent(s):
Squashing commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .ci/update_windows/update.py +146 -0
- .ci/update_windows/update_comfyui.bat +8 -0
- .ci/update_windows/update_comfyui_stable.bat +8 -0
- .ci/windows_base_files/README_VERY_IMPORTANT.txt +31 -0
- .ci/windows_base_files/run_cpu.bat +2 -0
- .ci/windows_base_files/run_nvidia_gpu.bat +2 -0
- .ci/windows_nightly_base_files/run_nvidia_gpu_fast.bat +2 -0
- .gitattributes +13 -0
- .github/ISSUE_TEMPLATE/bug-report.yml +48 -0
- .github/ISSUE_TEMPLATE/config.yml +11 -0
- .github/ISSUE_TEMPLATE/feature-request.yml +32 -0
- .github/ISSUE_TEMPLATE/user-support.yml +32 -0
- .github/workflows/pullrequest-ci-run.yml +53 -0
- .github/workflows/pylint.yml +23 -0
- .github/workflows/stable-release.yml +104 -0
- .github/workflows/stale-issues.yml +21 -0
- .github/workflows/test-build.yml +31 -0
- .github/workflows/test-ci.yml +95 -0
- .github/workflows/test-launch.yml +45 -0
- .github/workflows/test-unit.yml +30 -0
- .github/workflows/windows_release_dependencies.yml +71 -0
- .github/workflows/windows_release_nightly_pytorch.yml +91 -0
- .github/workflows/windows_release_package.yml +100 -0
- .gitignore +23 -0
- .pylintrc +3 -0
- CODEOWNERS +1 -0
- CONTRIBUTING.md +41 -0
- LICENSE +674 -0
- README.md +319 -0
- api_server/__init__.py +0 -0
- api_server/routes/__init__.py +0 -0
- api_server/routes/internal/README.md +3 -0
- api_server/routes/internal/__init__.py +0 -0
- api_server/routes/internal/internal_routes.py +75 -0
- api_server/services/__init__.py +0 -0
- api_server/services/file_service.py +13 -0
- api_server/services/terminal_service.py +60 -0
- api_server/utils/file_operations.py +42 -0
- app.py +305 -0
- app/__init__.py +0 -0
- app/app_settings.py +54 -0
- app/frontend_management.py +204 -0
- app/logger.py +73 -0
- app/user_manager.py +330 -0
- comfy/checkpoint_pickle.py +13 -0
- comfy/cldm/cldm.py +437 -0
- comfy/cldm/control_types.py +10 -0
- comfy/cldm/dit_embedder.py +122 -0
- comfy/cldm/mmdit.py +81 -0
- comfy/cli_args.py +187 -0
.ci/update_windows/update.py
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pygit2
|
2 |
+
from datetime import datetime
|
3 |
+
import sys
|
4 |
+
import os
|
5 |
+
import shutil
|
6 |
+
import filecmp
|
7 |
+
|
8 |
+
def pull(repo, remote_name='origin', branch='master'):
|
9 |
+
for remote in repo.remotes:
|
10 |
+
if remote.name == remote_name:
|
11 |
+
remote.fetch()
|
12 |
+
remote_master_id = repo.lookup_reference('refs/remotes/origin/%s' % (branch)).target
|
13 |
+
merge_result, _ = repo.merge_analysis(remote_master_id)
|
14 |
+
# Up to date, do nothing
|
15 |
+
if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE:
|
16 |
+
return
|
17 |
+
# We can just fastforward
|
18 |
+
elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD:
|
19 |
+
repo.checkout_tree(repo.get(remote_master_id))
|
20 |
+
try:
|
21 |
+
master_ref = repo.lookup_reference('refs/heads/%s' % (branch))
|
22 |
+
master_ref.set_target(remote_master_id)
|
23 |
+
except KeyError:
|
24 |
+
repo.create_branch(branch, repo.get(remote_master_id))
|
25 |
+
repo.head.set_target(remote_master_id)
|
26 |
+
elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL:
|
27 |
+
repo.merge(remote_master_id)
|
28 |
+
|
29 |
+
if repo.index.conflicts is not None:
|
30 |
+
for conflict in repo.index.conflicts:
|
31 |
+
print('Conflicts found in:', conflict[0].path)
|
32 |
+
raise AssertionError('Conflicts, ahhhhh!!')
|
33 |
+
|
34 |
+
user = repo.default_signature
|
35 |
+
tree = repo.index.write_tree()
|
36 |
+
commit = repo.create_commit('HEAD',
|
37 |
+
user,
|
38 |
+
user,
|
39 |
+
'Merge!',
|
40 |
+
tree,
|
41 |
+
[repo.head.target, remote_master_id])
|
42 |
+
# We need to do this or git CLI will think we are still merging.
|
43 |
+
repo.state_cleanup()
|
44 |
+
else:
|
45 |
+
raise AssertionError('Unknown merge analysis result')
|
46 |
+
|
47 |
+
pygit2.option(pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0)
|
48 |
+
repo_path = str(sys.argv[1])
|
49 |
+
repo = pygit2.Repository(repo_path)
|
50 |
+
ident = pygit2.Signature('comfyui', 'comfy@ui')
|
51 |
+
try:
|
52 |
+
print("stashing current changes")
|
53 |
+
repo.stash(ident)
|
54 |
+
except KeyError:
|
55 |
+
print("nothing to stash")
|
56 |
+
backup_branch_name = 'backup_branch_{}'.format(datetime.today().strftime('%Y-%m-%d_%H_%M_%S'))
|
57 |
+
print("creating backup branch: {}".format(backup_branch_name))
|
58 |
+
try:
|
59 |
+
repo.branches.local.create(backup_branch_name, repo.head.peel())
|
60 |
+
except:
|
61 |
+
pass
|
62 |
+
|
63 |
+
print("checking out master branch")
|
64 |
+
branch = repo.lookup_branch('master')
|
65 |
+
if branch is None:
|
66 |
+
ref = repo.lookup_reference('refs/remotes/origin/master')
|
67 |
+
repo.checkout(ref)
|
68 |
+
branch = repo.lookup_branch('master')
|
69 |
+
if branch is None:
|
70 |
+
repo.create_branch('master', repo.get(ref.target))
|
71 |
+
else:
|
72 |
+
ref = repo.lookup_reference(branch.name)
|
73 |
+
repo.checkout(ref)
|
74 |
+
|
75 |
+
print("pulling latest changes")
|
76 |
+
pull(repo)
|
77 |
+
|
78 |
+
if "--stable" in sys.argv:
|
79 |
+
def latest_tag(repo):
|
80 |
+
versions = []
|
81 |
+
for k in repo.references:
|
82 |
+
try:
|
83 |
+
prefix = "refs/tags/v"
|
84 |
+
if k.startswith(prefix):
|
85 |
+
version = list(map(int, k[len(prefix):].split(".")))
|
86 |
+
versions.append((version[0] * 10000000000 + version[1] * 100000 + version[2], k))
|
87 |
+
except:
|
88 |
+
pass
|
89 |
+
versions.sort()
|
90 |
+
if len(versions) > 0:
|
91 |
+
return versions[-1][1]
|
92 |
+
return None
|
93 |
+
latest_tag = latest_tag(repo)
|
94 |
+
if latest_tag is not None:
|
95 |
+
repo.checkout(latest_tag)
|
96 |
+
|
97 |
+
print("Done!")
|
98 |
+
|
99 |
+
self_update = True
|
100 |
+
if len(sys.argv) > 2:
|
101 |
+
self_update = '--skip_self_update' not in sys.argv
|
102 |
+
|
103 |
+
update_py_path = os.path.realpath(__file__)
|
104 |
+
repo_update_py_path = os.path.join(repo_path, ".ci/update_windows/update.py")
|
105 |
+
|
106 |
+
cur_path = os.path.dirname(update_py_path)
|
107 |
+
|
108 |
+
|
109 |
+
req_path = os.path.join(cur_path, "current_requirements.txt")
|
110 |
+
repo_req_path = os.path.join(repo_path, "requirements.txt")
|
111 |
+
|
112 |
+
|
113 |
+
def files_equal(file1, file2):
|
114 |
+
try:
|
115 |
+
return filecmp.cmp(file1, file2, shallow=False)
|
116 |
+
except:
|
117 |
+
return False
|
118 |
+
|
119 |
+
def file_size(f):
|
120 |
+
try:
|
121 |
+
return os.path.getsize(f)
|
122 |
+
except:
|
123 |
+
return 0
|
124 |
+
|
125 |
+
|
126 |
+
if self_update and not files_equal(update_py_path, repo_update_py_path) and file_size(repo_update_py_path) > 10:
|
127 |
+
shutil.copy(repo_update_py_path, os.path.join(cur_path, "update_new.py"))
|
128 |
+
exit()
|
129 |
+
|
130 |
+
if not os.path.exists(req_path) or not files_equal(repo_req_path, req_path):
|
131 |
+
import subprocess
|
132 |
+
try:
|
133 |
+
subprocess.check_call([sys.executable, '-s', '-m', 'pip', 'install', '-r', repo_req_path])
|
134 |
+
shutil.copy(repo_req_path, req_path)
|
135 |
+
except:
|
136 |
+
pass
|
137 |
+
|
138 |
+
|
139 |
+
stable_update_script = os.path.join(repo_path, ".ci/update_windows/update_comfyui_stable.bat")
|
140 |
+
stable_update_script_to = os.path.join(cur_path, "update_comfyui_stable.bat")
|
141 |
+
|
142 |
+
try:
|
143 |
+
if not file_size(stable_update_script_to) > 10:
|
144 |
+
shutil.copy(stable_update_script, stable_update_script_to)
|
145 |
+
except:
|
146 |
+
pass
|
.ci/update_windows/update_comfyui.bat
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
..\python_embeded\python.exe .\update.py ..\ComfyUI\
|
3 |
+
if exist update_new.py (
|
4 |
+
move /y update_new.py update.py
|
5 |
+
echo Running updater again since it got updated.
|
6 |
+
..\python_embeded\python.exe .\update.py ..\ComfyUI\ --skip_self_update
|
7 |
+
)
|
8 |
+
if "%~1"=="" pause
|
.ci/update_windows/update_comfyui_stable.bat
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
..\python_embeded\python.exe .\update.py ..\ComfyUI\ --stable
|
3 |
+
if exist update_new.py (
|
4 |
+
move /y update_new.py update.py
|
5 |
+
echo Running updater again since it got updated.
|
6 |
+
..\python_embeded\python.exe .\update.py ..\ComfyUI\ --skip_self_update --stable
|
7 |
+
)
|
8 |
+
if "%~1"=="" pause
|
.ci/windows_base_files/README_VERY_IMPORTANT.txt
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
HOW TO RUN:
|
2 |
+
|
3 |
+
if you have a NVIDIA gpu:
|
4 |
+
|
5 |
+
run_nvidia_gpu.bat
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
To run it in slow CPU mode:
|
10 |
+
|
11 |
+
run_cpu.bat
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
IF YOU GET A RED ERROR IN THE UI MAKE SURE YOU HAVE A MODEL/CHECKPOINT IN: ComfyUI\models\checkpoints
|
16 |
+
|
17 |
+
You can download the stable diffusion 1.5 one from: https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/blob/main/v1-5-pruned-emaonly-fp16.safetensors
|
18 |
+
|
19 |
+
|
20 |
+
RECOMMENDED WAY TO UPDATE:
|
21 |
+
To update the ComfyUI code: update\update_comfyui.bat
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
To update ComfyUI with the python dependencies, note that you should ONLY run this if you have issues with python dependencies.
|
26 |
+
update\update_comfyui_and_python_dependencies.bat
|
27 |
+
|
28 |
+
|
29 |
+
TO SHARE MODELS BETWEEN COMFYUI AND ANOTHER UI:
|
30 |
+
In the ComfyUI directory you will find a file: extra_model_paths.yaml.example
|
31 |
+
Rename this file to: extra_model_paths.yaml and edit it with your favorite text editor.
|
.ci/windows_base_files/run_cpu.bat
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.\python_embeded\python.exe -s ComfyUI\main.py --cpu --windows-standalone-build
|
2 |
+
pause
|
.ci/windows_base_files/run_nvidia_gpu.bat
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build
|
2 |
+
pause
|
.ci/windows_nightly_base_files/run_nvidia_gpu_fast.bat
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build --fast
|
2 |
+
pause
|
.gitattributes
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/web/assets/** linguist-generated
|
2 |
+
/web/** linguist-vendored
|
3 |
+
comfy/text_encoders/t5_pile_tokenizer/tokenizer.model filter=lfs diff=lfs merge=lfs -text
|
4 |
+
custom_nodes/ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_albedo.safetensors filter=lfs diff=lfs merge=lfs -text
|
5 |
+
custom_nodes/ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_depth.safetensors filter=lfs diff=lfs merge=lfs -text
|
6 |
+
custom_nodes/ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_normal.safetensors filter=lfs diff=lfs merge=lfs -text
|
7 |
+
custom_nodes/ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_shading.safetensors filter=lfs diff=lfs merge=lfs -text
|
8 |
+
custom_nodes/rgthree-comfy/docs/rgthree_context_metadata.png filter=lfs diff=lfs merge=lfs -text
|
9 |
+
custom_nodes/comfy_mtb/extern/frame_interpolation/moment.gif filter=lfs diff=lfs merge=lfs -text
|
10 |
+
custom_nodes/comfy_mtb/extern/frame_interpolation/photos/one.png filter=lfs diff=lfs merge=lfs -text
|
11 |
+
custom_nodes/comfy_mtb/extern/frame_interpolation/photos/two.png filter=lfs diff=lfs merge=lfs -text
|
12 |
+
custom_nodes/comfy_mtb/extern/GFPGAN/inputs/whole_imgs/00.jpg filter=lfs diff=lfs merge=lfs -text
|
13 |
+
custom_nodes/comfy_mtb/extern/GFPGAN/inputs/whole_imgs/10045.png filter=lfs diff=lfs merge=lfs -text
|
.github/ISSUE_TEMPLATE/bug-report.yml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Bug Report
|
2 |
+
description: "Something is broken inside of ComfyUI. (Do not use this if you're just having issues and need help, or if the issue relates to a custom node)"
|
3 |
+
labels: ["Potential Bug"]
|
4 |
+
body:
|
5 |
+
- type: markdown
|
6 |
+
attributes:
|
7 |
+
value: |
|
8 |
+
Before submitting a **Bug Report**, please ensure the following:
|
9 |
+
|
10 |
+
- **1:** You are running the latest version of ComfyUI.
|
11 |
+
- **2:** You have looked at the existing bug reports and made sure this isn't already reported.
|
12 |
+
- **3:** You confirmed that the bug is not caused by a custom node. You can disable all custom nodes by passing
|
13 |
+
`--disable-all-custom-nodes` command line argument.
|
14 |
+
- **4:** This is an actual bug in ComfyUI, not just a support question. A bug is when you can specify exact
|
15 |
+
steps to replicate what went wrong and others will be able to repeat your steps and see the same issue happen.
|
16 |
+
|
17 |
+
If unsure, ask on the [ComfyUI Matrix Space](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) or the [Comfy Org Discord](https://discord.gg/comfyorg) first.
|
18 |
+
- type: textarea
|
19 |
+
attributes:
|
20 |
+
label: Expected Behavior
|
21 |
+
description: "What you expected to happen."
|
22 |
+
validations:
|
23 |
+
required: true
|
24 |
+
- type: textarea
|
25 |
+
attributes:
|
26 |
+
label: Actual Behavior
|
27 |
+
description: "What actually happened. Please include a screenshot of the issue if possible."
|
28 |
+
validations:
|
29 |
+
required: true
|
30 |
+
- type: textarea
|
31 |
+
attributes:
|
32 |
+
label: Steps to Reproduce
|
33 |
+
description: "Describe how to reproduce the issue. Please be sure to attach a workflow JSON or PNG, ideally one that doesn't require custom nodes to test. If the bug open happens when certain custom nodes are used, most likely that custom node is what has the bug rather than ComfyUI, in which case it should be reported to the node's author."
|
34 |
+
validations:
|
35 |
+
required: true
|
36 |
+
- type: textarea
|
37 |
+
attributes:
|
38 |
+
label: Debug Logs
|
39 |
+
description: "Please copy the output from your terminal logs here."
|
40 |
+
render: powershell
|
41 |
+
validations:
|
42 |
+
required: true
|
43 |
+
- type: textarea
|
44 |
+
attributes:
|
45 |
+
label: Other
|
46 |
+
description: "Any other additional information you think might be helpful."
|
47 |
+
validations:
|
48 |
+
required: false
|
.github/ISSUE_TEMPLATE/config.yml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
blank_issues_enabled: true
|
2 |
+
contact_links:
|
3 |
+
- name: ComfyUI Frontend Issues
|
4 |
+
url: https://github.com/Comfy-Org/ComfyUI_frontend/issues
|
5 |
+
about: Issues related to the ComfyUI frontend (display issues, user interaction bugs), please go to the frontend repo to file the issue
|
6 |
+
- name: ComfyUI Matrix Space
|
7 |
+
url: https://app.element.io/#/room/%23comfyui_space%3Amatrix.org
|
8 |
+
about: The ComfyUI Matrix Space is available for support and general discussion related to ComfyUI (Matrix is like Discord but open source).
|
9 |
+
- name: Comfy Org Discord
|
10 |
+
url: https://discord.gg/comfyorg
|
11 |
+
about: The Comfy Org Discord is available for support and general discussion related to ComfyUI.
|
.github/ISSUE_TEMPLATE/feature-request.yml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Feature Request
|
2 |
+
description: "You have an idea for something new you would like to see added to ComfyUI's core."
|
3 |
+
labels: [ "Feature" ]
|
4 |
+
body:
|
5 |
+
- type: markdown
|
6 |
+
attributes:
|
7 |
+
value: |
|
8 |
+
Before submitting a **Feature Request**, please ensure the following:
|
9 |
+
|
10 |
+
**1:** You are running the latest version of ComfyUI.
|
11 |
+
**2:** You have looked to make sure there is not already a feature that does what you need, and there is not already a Feature Request listed for the same idea.
|
12 |
+
**3:** This is something that makes sense to add to ComfyUI Core, and wouldn't make more sense as a custom node.
|
13 |
+
|
14 |
+
If unsure, ask on the [ComfyUI Matrix Space](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) or the [Comfy Org Discord](https://discord.gg/comfyorg) first.
|
15 |
+
- type: textarea
|
16 |
+
attributes:
|
17 |
+
label: Feature Idea
|
18 |
+
description: "Describe the feature you want to see."
|
19 |
+
validations:
|
20 |
+
required: true
|
21 |
+
- type: textarea
|
22 |
+
attributes:
|
23 |
+
label: Existing Solutions
|
24 |
+
description: "Please search through available custom nodes / extensions to see if there are existing custom solutions for this. If so, please link the options you found here as a reference."
|
25 |
+
validations:
|
26 |
+
required: false
|
27 |
+
- type: textarea
|
28 |
+
attributes:
|
29 |
+
label: Other
|
30 |
+
description: "Any other additional information you think might be helpful."
|
31 |
+
validations:
|
32 |
+
required: false
|
.github/ISSUE_TEMPLATE/user-support.yml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: User Support
|
2 |
+
description: "Use this if you need help with something, or you're experiencing an issue."
|
3 |
+
labels: [ "User Support" ]
|
4 |
+
body:
|
5 |
+
- type: markdown
|
6 |
+
attributes:
|
7 |
+
value: |
|
8 |
+
Before submitting a **User Report** issue, please ensure the following:
|
9 |
+
|
10 |
+
**1:** You are running the latest version of ComfyUI.
|
11 |
+
**2:** You have made an effort to find public answers to your question before asking here. In other words, you googled it first, and scrolled through recent help topics.
|
12 |
+
|
13 |
+
If unsure, ask on the [ComfyUI Matrix Space](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) or the [Comfy Org Discord](https://discord.gg/comfyorg) first.
|
14 |
+
- type: textarea
|
15 |
+
attributes:
|
16 |
+
label: Your question
|
17 |
+
description: "Post your question here. Please be as detailed as possible."
|
18 |
+
validations:
|
19 |
+
required: true
|
20 |
+
- type: textarea
|
21 |
+
attributes:
|
22 |
+
label: Logs
|
23 |
+
description: "If your question relates to an issue you're experiencing, please go to `Server` -> `Logs` -> potentially set `View Type` to `Debug` as well, then copypaste all the text into here."
|
24 |
+
render: powershell
|
25 |
+
validations:
|
26 |
+
required: false
|
27 |
+
- type: textarea
|
28 |
+
attributes:
|
29 |
+
label: Other
|
30 |
+
description: "Any other additional information you think might be helpful."
|
31 |
+
validations:
|
32 |
+
required: false
|
.github/workflows/pullrequest-ci-run.yml
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This is the GitHub Workflow that drives full-GPU-enabled tests of pull requests to ComfyUI, when the 'Run-CI-Test' label is added
|
2 |
+
# Results are reported as checkmarks on the commits, as well as onto https://ci.comfy.org/
|
3 |
+
name: Pull Request CI Workflow Runs
|
4 |
+
on:
|
5 |
+
pull_request_target:
|
6 |
+
types: [labeled]
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
pr-test-stable:
|
10 |
+
if: ${{ github.event.label.name == 'Run-CI-Test' }}
|
11 |
+
strategy:
|
12 |
+
fail-fast: false
|
13 |
+
matrix:
|
14 |
+
os: [macos, linux, windows]
|
15 |
+
python_version: ["3.9", "3.10", "3.11", "3.12"]
|
16 |
+
cuda_version: ["12.1"]
|
17 |
+
torch_version: ["stable"]
|
18 |
+
include:
|
19 |
+
- os: macos
|
20 |
+
runner_label: [self-hosted, macOS]
|
21 |
+
flags: "--use-pytorch-cross-attention"
|
22 |
+
- os: linux
|
23 |
+
runner_label: [self-hosted, Linux]
|
24 |
+
flags: ""
|
25 |
+
- os: windows
|
26 |
+
runner_label: [self-hosted, Windows]
|
27 |
+
flags: ""
|
28 |
+
runs-on: ${{ matrix.runner_label }}
|
29 |
+
steps:
|
30 |
+
- name: Test Workflows
|
31 |
+
uses: comfy-org/comfy-action@main
|
32 |
+
with:
|
33 |
+
os: ${{ matrix.os }}
|
34 |
+
python_version: ${{ matrix.python_version }}
|
35 |
+
torch_version: ${{ matrix.torch_version }}
|
36 |
+
google_credentials: ${{ secrets.GCS_SERVICE_ACCOUNT_JSON }}
|
37 |
+
comfyui_flags: ${{ matrix.flags }}
|
38 |
+
use_prior_commit: 'true'
|
39 |
+
comment:
|
40 |
+
if: ${{ github.event.label.name == 'Run-CI-Test' }}
|
41 |
+
runs-on: ubuntu-latest
|
42 |
+
permissions:
|
43 |
+
pull-requests: write
|
44 |
+
steps:
|
45 |
+
- uses: actions/github-script@v6
|
46 |
+
with:
|
47 |
+
script: |
|
48 |
+
github.rest.issues.createComment({
|
49 |
+
issue_number: context.issue.number,
|
50 |
+
owner: context.repo.owner,
|
51 |
+
repo: context.repo.repo,
|
52 |
+
body: '(Automated Bot Message) CI Tests are running, you can view the results at https://ci.comfy.org/?branch=${{ github.event.pull_request.number }}%2Fmerge'
|
53 |
+
})
|
.github/workflows/pylint.yml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Python Linting
|
2 |
+
|
3 |
+
on: [push, pull_request]
|
4 |
+
|
5 |
+
jobs:
|
6 |
+
pylint:
|
7 |
+
name: Run Pylint
|
8 |
+
runs-on: ubuntu-latest
|
9 |
+
|
10 |
+
steps:
|
11 |
+
- name: Checkout repository
|
12 |
+
uses: actions/checkout@v4
|
13 |
+
|
14 |
+
- name: Set up Python
|
15 |
+
uses: actions/setup-python@v2
|
16 |
+
with:
|
17 |
+
python-version: 3.x
|
18 |
+
|
19 |
+
- name: Install Pylint
|
20 |
+
run: pip install pylint
|
21 |
+
|
22 |
+
- name: Run Pylint
|
23 |
+
run: pylint --rcfile=.pylintrc $(find . -type f -name "*.py")
|
.github/workflows/stable-release.yml
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
name: "Release Stable Version"
|
3 |
+
|
4 |
+
on:
|
5 |
+
workflow_dispatch:
|
6 |
+
inputs:
|
7 |
+
git_tag:
|
8 |
+
description: 'Git tag'
|
9 |
+
required: true
|
10 |
+
type: string
|
11 |
+
cu:
|
12 |
+
description: 'CUDA version'
|
13 |
+
required: true
|
14 |
+
type: string
|
15 |
+
default: "124"
|
16 |
+
python_minor:
|
17 |
+
description: 'Python minor version'
|
18 |
+
required: true
|
19 |
+
type: string
|
20 |
+
default: "12"
|
21 |
+
python_patch:
|
22 |
+
description: 'Python patch version'
|
23 |
+
required: true
|
24 |
+
type: string
|
25 |
+
default: "7"
|
26 |
+
|
27 |
+
|
28 |
+
jobs:
|
29 |
+
package_comfy_windows:
|
30 |
+
permissions:
|
31 |
+
contents: "write"
|
32 |
+
packages: "write"
|
33 |
+
pull-requests: "read"
|
34 |
+
runs-on: windows-latest
|
35 |
+
steps:
|
36 |
+
- uses: actions/checkout@v4
|
37 |
+
with:
|
38 |
+
ref: ${{ inputs.git_tag }}
|
39 |
+
fetch-depth: 0
|
40 |
+
persist-credentials: false
|
41 |
+
- uses: actions/cache/restore@v4
|
42 |
+
id: cache
|
43 |
+
with:
|
44 |
+
path: |
|
45 |
+
cu${{ inputs.cu }}_python_deps.tar
|
46 |
+
update_comfyui_and_python_dependencies.bat
|
47 |
+
key: ${{ runner.os }}-build-cu${{ inputs.cu }}-${{ inputs.python_minor }}
|
48 |
+
- shell: bash
|
49 |
+
run: |
|
50 |
+
mv cu${{ inputs.cu }}_python_deps.tar ../
|
51 |
+
mv update_comfyui_and_python_dependencies.bat ../
|
52 |
+
cd ..
|
53 |
+
tar xf cu${{ inputs.cu }}_python_deps.tar
|
54 |
+
pwd
|
55 |
+
ls
|
56 |
+
|
57 |
+
- shell: bash
|
58 |
+
run: |
|
59 |
+
cd ..
|
60 |
+
cp -r ComfyUI ComfyUI_copy
|
61 |
+
curl https://www.python.org/ftp/python/3.${{ inputs.python_minor }}.${{ inputs.python_patch }}/python-3.${{ inputs.python_minor }}.${{ inputs.python_patch }}-embed-amd64.zip -o python_embeded.zip
|
62 |
+
unzip python_embeded.zip -d python_embeded
|
63 |
+
cd python_embeded
|
64 |
+
echo ${{ env.MINOR_VERSION }}
|
65 |
+
echo 'import site' >> ./python3${{ inputs.python_minor }}._pth
|
66 |
+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
67 |
+
./python.exe get-pip.py
|
68 |
+
./python.exe -s -m pip install ../cu${{ inputs.cu }}_python_deps/*
|
69 |
+
sed -i '1i../ComfyUI' ./python3${{ inputs.python_minor }}._pth
|
70 |
+
cd ..
|
71 |
+
|
72 |
+
git clone --depth 1 https://github.com/comfyanonymous/taesd
|
73 |
+
cp taesd/*.pth ./ComfyUI_copy/models/vae_approx/
|
74 |
+
|
75 |
+
mkdir ComfyUI_windows_portable
|
76 |
+
mv python_embeded ComfyUI_windows_portable
|
77 |
+
mv ComfyUI_copy ComfyUI_windows_portable/ComfyUI
|
78 |
+
|
79 |
+
cd ComfyUI_windows_portable
|
80 |
+
|
81 |
+
mkdir update
|
82 |
+
cp -r ComfyUI/.ci/update_windows/* ./update/
|
83 |
+
cp -r ComfyUI/.ci/windows_base_files/* ./
|
84 |
+
cp ../update_comfyui_and_python_dependencies.bat ./update/
|
85 |
+
|
86 |
+
cd ..
|
87 |
+
|
88 |
+
"C:\Program Files\7-Zip\7z.exe" a -t7z -m0=lzma2 -mx=8 -mfb=64 -md=32m -ms=on -mf=BCJ2 ComfyUI_windows_portable.7z ComfyUI_windows_portable
|
89 |
+
mv ComfyUI_windows_portable.7z ComfyUI/ComfyUI_windows_portable_nvidia.7z
|
90 |
+
|
91 |
+
cd ComfyUI_windows_portable
|
92 |
+
python_embeded/python.exe -s ComfyUI/main.py --quick-test-for-ci --cpu
|
93 |
+
|
94 |
+
ls
|
95 |
+
|
96 |
+
- name: Upload binaries to release
|
97 |
+
uses: svenstaro/upload-release-action@v2
|
98 |
+
with:
|
99 |
+
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
100 |
+
file: ComfyUI_windows_portable_nvidia.7z
|
101 |
+
tag: ${{ inputs.git_tag }}
|
102 |
+
overwrite: true
|
103 |
+
prerelease: true
|
104 |
+
make_latest: false
|
.github/workflows/stale-issues.yml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: 'Close stale issues'
|
2 |
+
on:
|
3 |
+
schedule:
|
4 |
+
# Run daily at 430 am PT
|
5 |
+
- cron: '30 11 * * *'
|
6 |
+
permissions:
|
7 |
+
issues: write
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
stale:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- uses: actions/stale@v9
|
14 |
+
with:
|
15 |
+
stale-issue-message: "This issue is being marked stale because it has not had any activity for 30 days. Reply below within 7 days if your issue still isn't solved, and it will be left open. Otherwise, the issue will be closed automatically."
|
16 |
+
days-before-stale: 30
|
17 |
+
days-before-close: 7
|
18 |
+
stale-issue-label: 'Stale'
|
19 |
+
only-labels: 'User Support'
|
20 |
+
exempt-all-assignees: true
|
21 |
+
exempt-all-milestones: true
|
.github/workflows/test-build.yml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Build package
|
2 |
+
|
3 |
+
#
|
4 |
+
# This workflow is a test of the python package build.
|
5 |
+
# Install Python dependencies across different Python versions.
|
6 |
+
#
|
7 |
+
|
8 |
+
on:
|
9 |
+
push:
|
10 |
+
paths:
|
11 |
+
- "requirements.txt"
|
12 |
+
- ".github/workflows/test-build.yml"
|
13 |
+
|
14 |
+
jobs:
|
15 |
+
build:
|
16 |
+
name: Build Test
|
17 |
+
runs-on: ubuntu-latest
|
18 |
+
strategy:
|
19 |
+
fail-fast: false
|
20 |
+
matrix:
|
21 |
+
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
22 |
+
steps:
|
23 |
+
- uses: actions/checkout@v4
|
24 |
+
- name: Set up Python ${{ matrix.python-version }}
|
25 |
+
uses: actions/setup-python@v4
|
26 |
+
with:
|
27 |
+
python-version: ${{ matrix.python-version }}
|
28 |
+
- name: Install dependencies
|
29 |
+
run: |
|
30 |
+
python -m pip install --upgrade pip
|
31 |
+
pip install -r requirements.txt
|
.github/workflows/test-ci.yml
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This is the GitHub Workflow that drives automatic full-GPU-enabled tests of all new commits to the master branch of ComfyUI
|
2 |
+
# Results are reported as checkmarks on the commits, as well as onto https://ci.comfy.org/
|
3 |
+
name: Full Comfy CI Workflow Runs
|
4 |
+
on:
|
5 |
+
push:
|
6 |
+
branches:
|
7 |
+
- master
|
8 |
+
paths-ignore:
|
9 |
+
- 'app/**'
|
10 |
+
- 'input/**'
|
11 |
+
- 'output/**'
|
12 |
+
- 'notebooks/**'
|
13 |
+
- 'script_examples/**'
|
14 |
+
- '.github/**'
|
15 |
+
- 'web/**'
|
16 |
+
workflow_dispatch:
|
17 |
+
|
18 |
+
jobs:
|
19 |
+
test-stable:
|
20 |
+
strategy:
|
21 |
+
fail-fast: false
|
22 |
+
matrix:
|
23 |
+
os: [macos, linux, windows]
|
24 |
+
python_version: ["3.9", "3.10", "3.11", "3.12"]
|
25 |
+
cuda_version: ["12.1"]
|
26 |
+
torch_version: ["stable"]
|
27 |
+
include:
|
28 |
+
- os: macos
|
29 |
+
runner_label: [self-hosted, macOS]
|
30 |
+
flags: "--use-pytorch-cross-attention"
|
31 |
+
- os: linux
|
32 |
+
runner_label: [self-hosted, Linux]
|
33 |
+
flags: ""
|
34 |
+
- os: windows
|
35 |
+
runner_label: [self-hosted, Windows]
|
36 |
+
flags: ""
|
37 |
+
runs-on: ${{ matrix.runner_label }}
|
38 |
+
steps:
|
39 |
+
- name: Test Workflows
|
40 |
+
uses: comfy-org/comfy-action@main
|
41 |
+
with:
|
42 |
+
os: ${{ matrix.os }}
|
43 |
+
python_version: ${{ matrix.python_version }}
|
44 |
+
torch_version: ${{ matrix.torch_version }}
|
45 |
+
google_credentials: ${{ secrets.GCS_SERVICE_ACCOUNT_JSON }}
|
46 |
+
comfyui_flags: ${{ matrix.flags }}
|
47 |
+
|
48 |
+
test-win-nightly:
|
49 |
+
strategy:
|
50 |
+
fail-fast: true
|
51 |
+
matrix:
|
52 |
+
os: [windows]
|
53 |
+
python_version: ["3.9", "3.10", "3.11", "3.12"]
|
54 |
+
cuda_version: ["12.1"]
|
55 |
+
torch_version: ["nightly"]
|
56 |
+
include:
|
57 |
+
- os: windows
|
58 |
+
runner_label: [self-hosted, Windows]
|
59 |
+
flags: ""
|
60 |
+
runs-on: ${{ matrix.runner_label }}
|
61 |
+
steps:
|
62 |
+
- name: Test Workflows
|
63 |
+
uses: comfy-org/comfy-action@main
|
64 |
+
with:
|
65 |
+
os: ${{ matrix.os }}
|
66 |
+
python_version: ${{ matrix.python_version }}
|
67 |
+
torch_version: ${{ matrix.torch_version }}
|
68 |
+
google_credentials: ${{ secrets.GCS_SERVICE_ACCOUNT_JSON }}
|
69 |
+
comfyui_flags: ${{ matrix.flags }}
|
70 |
+
|
71 |
+
test-unix-nightly:
|
72 |
+
strategy:
|
73 |
+
fail-fast: false
|
74 |
+
matrix:
|
75 |
+
os: [macos, linux]
|
76 |
+
python_version: ["3.11"]
|
77 |
+
cuda_version: ["12.1"]
|
78 |
+
torch_version: ["nightly"]
|
79 |
+
include:
|
80 |
+
- os: macos
|
81 |
+
runner_label: [self-hosted, macOS]
|
82 |
+
flags: "--use-pytorch-cross-attention"
|
83 |
+
- os: linux
|
84 |
+
runner_label: [self-hosted, Linux]
|
85 |
+
flags: ""
|
86 |
+
runs-on: ${{ matrix.runner_label }}
|
87 |
+
steps:
|
88 |
+
- name: Test Workflows
|
89 |
+
uses: comfy-org/comfy-action@main
|
90 |
+
with:
|
91 |
+
os: ${{ matrix.os }}
|
92 |
+
python_version: ${{ matrix.python_version }}
|
93 |
+
torch_version: ${{ matrix.torch_version }}
|
94 |
+
google_credentials: ${{ secrets.GCS_SERVICE_ACCOUNT_JSON }}
|
95 |
+
comfyui_flags: ${{ matrix.flags }}
|
.github/workflows/test-launch.yml
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Test server launches without errors
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches: [ main, master ]
|
6 |
+
pull_request:
|
7 |
+
branches: [ main, master ]
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
test:
|
11 |
+
runs-on: ubuntu-latest
|
12 |
+
steps:
|
13 |
+
- name: Checkout ComfyUI
|
14 |
+
uses: actions/checkout@v4
|
15 |
+
with:
|
16 |
+
repository: "comfyanonymous/ComfyUI"
|
17 |
+
path: "ComfyUI"
|
18 |
+
- uses: actions/setup-python@v4
|
19 |
+
with:
|
20 |
+
python-version: '3.8'
|
21 |
+
- name: Install requirements
|
22 |
+
run: |
|
23 |
+
python -m pip install --upgrade pip
|
24 |
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
25 |
+
pip install -r requirements.txt
|
26 |
+
pip install wait-for-it
|
27 |
+
working-directory: ComfyUI
|
28 |
+
- name: Start ComfyUI server
|
29 |
+
run: |
|
30 |
+
python main.py --cpu 2>&1 | tee console_output.log &
|
31 |
+
wait-for-it --service 127.0.0.1:8188 -t 600
|
32 |
+
working-directory: ComfyUI
|
33 |
+
- name: Check for unhandled exceptions in server log
|
34 |
+
run: |
|
35 |
+
if grep -qE "Exception|Error" console_output.log; then
|
36 |
+
echo "Unhandled exception/error found in server log."
|
37 |
+
exit 1
|
38 |
+
fi
|
39 |
+
working-directory: ComfyUI
|
40 |
+
- uses: actions/upload-artifact@v4
|
41 |
+
if: always()
|
42 |
+
with:
|
43 |
+
name: console-output
|
44 |
+
path: ComfyUI/console_output.log
|
45 |
+
retention-days: 30
|
.github/workflows/test-unit.yml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Unit Tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches: [ main, master ]
|
6 |
+
pull_request:
|
7 |
+
branches: [ main, master ]
|
8 |
+
|
9 |
+
jobs:
|
10 |
+
test:
|
11 |
+
strategy:
|
12 |
+
matrix:
|
13 |
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
14 |
+
runs-on: ${{ matrix.os }}
|
15 |
+
continue-on-error: true
|
16 |
+
steps:
|
17 |
+
- uses: actions/checkout@v4
|
18 |
+
- name: Set up Python
|
19 |
+
uses: actions/setup-python@v4
|
20 |
+
with:
|
21 |
+
python-version: '3.10'
|
22 |
+
- name: Install requirements
|
23 |
+
run: |
|
24 |
+
python -m pip install --upgrade pip
|
25 |
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
26 |
+
pip install -r requirements.txt
|
27 |
+
- name: Run Unit Tests
|
28 |
+
run: |
|
29 |
+
pip install -r tests-unit/requirements.txt
|
30 |
+
python -m pytest tests-unit
|
.github/workflows/windows_release_dependencies.yml
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Windows Release dependencies"
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
xformers:
|
7 |
+
description: 'xformers version'
|
8 |
+
required: false
|
9 |
+
type: string
|
10 |
+
default: ""
|
11 |
+
extra_dependencies:
|
12 |
+
description: 'extra dependencies'
|
13 |
+
required: false
|
14 |
+
type: string
|
15 |
+
default: ""
|
16 |
+
cu:
|
17 |
+
description: 'cuda version'
|
18 |
+
required: true
|
19 |
+
type: string
|
20 |
+
default: "124"
|
21 |
+
|
22 |
+
python_minor:
|
23 |
+
description: 'python minor version'
|
24 |
+
required: true
|
25 |
+
type: string
|
26 |
+
default: "12"
|
27 |
+
|
28 |
+
python_patch:
|
29 |
+
description: 'python patch version'
|
30 |
+
required: true
|
31 |
+
type: string
|
32 |
+
default: "7"
|
33 |
+
# push:
|
34 |
+
# branches:
|
35 |
+
# - master
|
36 |
+
|
37 |
+
jobs:
|
38 |
+
build_dependencies:
|
39 |
+
runs-on: windows-latest
|
40 |
+
steps:
|
41 |
+
- uses: actions/checkout@v4
|
42 |
+
- uses: actions/setup-python@v5
|
43 |
+
with:
|
44 |
+
python-version: 3.${{ inputs.python_minor }}.${{ inputs.python_patch }}
|
45 |
+
|
46 |
+
- shell: bash
|
47 |
+
run: |
|
48 |
+
echo "@echo off
|
49 |
+
call update_comfyui.bat nopause
|
50 |
+
echo -
|
51 |
+
echo This will try to update pytorch and all python dependencies.
|
52 |
+
echo -
|
53 |
+
echo If you just want to update normally, close this and run update_comfyui.bat instead.
|
54 |
+
echo -
|
55 |
+
pause
|
56 |
+
..\python_embeded\python.exe -s -m pip install --upgrade torch torchvision torchaudio ${{ inputs.xformers }} --extra-index-url https://download.pytorch.org/whl/cu${{ inputs.cu }} -r ../ComfyUI/requirements.txt pygit2
|
57 |
+
pause" > update_comfyui_and_python_dependencies.bat
|
58 |
+
|
59 |
+
python -m pip wheel --no-cache-dir torch torchvision torchaudio ${{ inputs.xformers }} ${{ inputs.extra_dependencies }} --extra-index-url https://download.pytorch.org/whl/cu${{ inputs.cu }} -r requirements.txt pygit2 -w ./temp_wheel_dir
|
60 |
+
python -m pip install --no-cache-dir ./temp_wheel_dir/*
|
61 |
+
echo installed basic
|
62 |
+
ls -lah temp_wheel_dir
|
63 |
+
mv temp_wheel_dir cu${{ inputs.cu }}_python_deps
|
64 |
+
tar cf cu${{ inputs.cu }}_python_deps.tar cu${{ inputs.cu }}_python_deps
|
65 |
+
|
66 |
+
- uses: actions/cache/save@v4
|
67 |
+
with:
|
68 |
+
path: |
|
69 |
+
cu${{ inputs.cu }}_python_deps.tar
|
70 |
+
update_comfyui_and_python_dependencies.bat
|
71 |
+
key: ${{ runner.os }}-build-cu${{ inputs.cu }}-${{ inputs.python_minor }}
|
.github/workflows/windows_release_nightly_pytorch.yml
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Windows Release Nightly pytorch"
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
cu:
|
7 |
+
description: 'cuda version'
|
8 |
+
required: true
|
9 |
+
type: string
|
10 |
+
default: "124"
|
11 |
+
|
12 |
+
python_minor:
|
13 |
+
description: 'python minor version'
|
14 |
+
required: true
|
15 |
+
type: string
|
16 |
+
default: "12"
|
17 |
+
|
18 |
+
python_patch:
|
19 |
+
description: 'python patch version'
|
20 |
+
required: true
|
21 |
+
type: string
|
22 |
+
default: "4"
|
23 |
+
# push:
|
24 |
+
# branches:
|
25 |
+
# - master
|
26 |
+
|
27 |
+
jobs:
|
28 |
+
build:
|
29 |
+
permissions:
|
30 |
+
contents: "write"
|
31 |
+
packages: "write"
|
32 |
+
pull-requests: "read"
|
33 |
+
runs-on: windows-latest
|
34 |
+
steps:
|
35 |
+
- uses: actions/checkout@v4
|
36 |
+
with:
|
37 |
+
fetch-depth: 0
|
38 |
+
persist-credentials: false
|
39 |
+
- uses: actions/setup-python@v5
|
40 |
+
with:
|
41 |
+
python-version: 3.${{ inputs.python_minor }}.${{ inputs.python_patch }}
|
42 |
+
- shell: bash
|
43 |
+
run: |
|
44 |
+
cd ..
|
45 |
+
cp -r ComfyUI ComfyUI_copy
|
46 |
+
curl https://www.python.org/ftp/python/3.${{ inputs.python_minor }}.${{ inputs.python_patch }}/python-3.${{ inputs.python_minor }}.${{ inputs.python_patch }}-embed-amd64.zip -o python_embeded.zip
|
47 |
+
unzip python_embeded.zip -d python_embeded
|
48 |
+
cd python_embeded
|
49 |
+
echo 'import site' >> ./python3${{ inputs.python_minor }}._pth
|
50 |
+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
51 |
+
./python.exe get-pip.py
|
52 |
+
python -m pip wheel torch torchvision torchaudio --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu${{ inputs.cu }} -r ../ComfyUI/requirements.txt pygit2 -w ../temp_wheel_dir
|
53 |
+
ls ../temp_wheel_dir
|
54 |
+
./python.exe -s -m pip install --pre ../temp_wheel_dir/*
|
55 |
+
sed -i '1i../ComfyUI' ./python3${{ inputs.python_minor }}._pth
|
56 |
+
cd ..
|
57 |
+
|
58 |
+
git clone --depth 1 https://github.com/comfyanonymous/taesd
|
59 |
+
cp taesd/*.pth ./ComfyUI_copy/models/vae_approx/
|
60 |
+
|
61 |
+
mkdir ComfyUI_windows_portable_nightly_pytorch
|
62 |
+
mv python_embeded ComfyUI_windows_portable_nightly_pytorch
|
63 |
+
mv ComfyUI_copy ComfyUI_windows_portable_nightly_pytorch/ComfyUI
|
64 |
+
|
65 |
+
cd ComfyUI_windows_portable_nightly_pytorch
|
66 |
+
|
67 |
+
mkdir update
|
68 |
+
cp -r ComfyUI/.ci/update_windows/* ./update/
|
69 |
+
cp -r ComfyUI/.ci/windows_base_files/* ./
|
70 |
+
cp -r ComfyUI/.ci/windows_nightly_base_files/* ./
|
71 |
+
|
72 |
+
echo "call update_comfyui.bat nopause
|
73 |
+
..\python_embeded\python.exe -s -m pip install --upgrade --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu${{ inputs.cu }} -r ../ComfyUI/requirements.txt pygit2
|
74 |
+
pause" > ./update/update_comfyui_and_python_dependencies.bat
|
75 |
+
cd ..
|
76 |
+
|
77 |
+
"C:\Program Files\7-Zip\7z.exe" a -t7z -m0=lzma2 -mx=8 -mfb=64 -md=32m -ms=on -mf=BCJ2 ComfyUI_windows_portable_nightly_pytorch.7z ComfyUI_windows_portable_nightly_pytorch
|
78 |
+
mv ComfyUI_windows_portable_nightly_pytorch.7z ComfyUI/ComfyUI_windows_portable_nvidia_or_cpu_nightly_pytorch.7z
|
79 |
+
|
80 |
+
cd ComfyUI_windows_portable_nightly_pytorch
|
81 |
+
python_embeded/python.exe -s ComfyUI/main.py --quick-test-for-ci --cpu
|
82 |
+
|
83 |
+
ls
|
84 |
+
|
85 |
+
- name: Upload binaries to release
|
86 |
+
uses: svenstaro/upload-release-action@v2
|
87 |
+
with:
|
88 |
+
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
89 |
+
file: ComfyUI_windows_portable_nvidia_or_cpu_nightly_pytorch.7z
|
90 |
+
tag: "latest"
|
91 |
+
overwrite: true
|
.github/workflows/windows_release_package.yml
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: "Windows Release packaging"
|
2 |
+
|
3 |
+
on:
|
4 |
+
workflow_dispatch:
|
5 |
+
inputs:
|
6 |
+
cu:
|
7 |
+
description: 'cuda version'
|
8 |
+
required: true
|
9 |
+
type: string
|
10 |
+
default: "124"
|
11 |
+
|
12 |
+
python_minor:
|
13 |
+
description: 'python minor version'
|
14 |
+
required: true
|
15 |
+
type: string
|
16 |
+
default: "12"
|
17 |
+
|
18 |
+
python_patch:
|
19 |
+
description: 'python patch version'
|
20 |
+
required: true
|
21 |
+
type: string
|
22 |
+
default: "7"
|
23 |
+
# push:
|
24 |
+
# branches:
|
25 |
+
# - master
|
26 |
+
|
27 |
+
jobs:
|
28 |
+
package_comfyui:
|
29 |
+
permissions:
|
30 |
+
contents: "write"
|
31 |
+
packages: "write"
|
32 |
+
pull-requests: "read"
|
33 |
+
runs-on: windows-latest
|
34 |
+
steps:
|
35 |
+
- uses: actions/cache/restore@v4
|
36 |
+
id: cache
|
37 |
+
with:
|
38 |
+
path: |
|
39 |
+
cu${{ inputs.cu }}_python_deps.tar
|
40 |
+
update_comfyui_and_python_dependencies.bat
|
41 |
+
key: ${{ runner.os }}-build-cu${{ inputs.cu }}-${{ inputs.python_minor }}
|
42 |
+
- shell: bash
|
43 |
+
run: |
|
44 |
+
mv cu${{ inputs.cu }}_python_deps.tar ../
|
45 |
+
mv update_comfyui_and_python_dependencies.bat ../
|
46 |
+
cd ..
|
47 |
+
tar xf cu${{ inputs.cu }}_python_deps.tar
|
48 |
+
pwd
|
49 |
+
ls
|
50 |
+
|
51 |
+
- uses: actions/checkout@v4
|
52 |
+
with:
|
53 |
+
fetch-depth: 0
|
54 |
+
persist-credentials: false
|
55 |
+
- shell: bash
|
56 |
+
run: |
|
57 |
+
cd ..
|
58 |
+
cp -r ComfyUI ComfyUI_copy
|
59 |
+
curl https://www.python.org/ftp/python/3.${{ inputs.python_minor }}.${{ inputs.python_patch }}/python-3.${{ inputs.python_minor }}.${{ inputs.python_patch }}-embed-amd64.zip -o python_embeded.zip
|
60 |
+
unzip python_embeded.zip -d python_embeded
|
61 |
+
cd python_embeded
|
62 |
+
echo 'import site' >> ./python3${{ inputs.python_minor }}._pth
|
63 |
+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
64 |
+
./python.exe get-pip.py
|
65 |
+
./python.exe -s -m pip install ../cu${{ inputs.cu }}_python_deps/*
|
66 |
+
sed -i '1i../ComfyUI' ./python3${{ inputs.python_minor }}._pth
|
67 |
+
cd ..
|
68 |
+
|
69 |
+
git clone --depth 1 https://github.com/comfyanonymous/taesd
|
70 |
+
cp taesd/*.pth ./ComfyUI_copy/models/vae_approx/
|
71 |
+
|
72 |
+
mkdir ComfyUI_windows_portable
|
73 |
+
mv python_embeded ComfyUI_windows_portable
|
74 |
+
mv ComfyUI_copy ComfyUI_windows_portable/ComfyUI
|
75 |
+
|
76 |
+
cd ComfyUI_windows_portable
|
77 |
+
|
78 |
+
mkdir update
|
79 |
+
cp -r ComfyUI/.ci/update_windows/* ./update/
|
80 |
+
cp -r ComfyUI/.ci/windows_base_files/* ./
|
81 |
+
cp ../update_comfyui_and_python_dependencies.bat ./update/
|
82 |
+
|
83 |
+
cd ..
|
84 |
+
|
85 |
+
"C:\Program Files\7-Zip\7z.exe" a -t7z -m0=lzma2 -mx=8 -mfb=64 -md=32m -ms=on -mf=BCJ2 ComfyUI_windows_portable.7z ComfyUI_windows_portable
|
86 |
+
mv ComfyUI_windows_portable.7z ComfyUI/new_ComfyUI_windows_portable_nvidia_cu${{ inputs.cu }}_or_cpu.7z
|
87 |
+
|
88 |
+
cd ComfyUI_windows_portable
|
89 |
+
python_embeded/python.exe -s ComfyUI/main.py --quick-test-for-ci --cpu
|
90 |
+
|
91 |
+
ls
|
92 |
+
|
93 |
+
- name: Upload binaries to release
|
94 |
+
uses: svenstaro/upload-release-action@v2
|
95 |
+
with:
|
96 |
+
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
97 |
+
file: new_ComfyUI_windows_portable_nvidia_cu${{ inputs.cu }}_or_cpu.7z
|
98 |
+
tag: "latest"
|
99 |
+
overwrite: true
|
100 |
+
|
.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
|
.pylintrc
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[MESSAGES CONTROL]
|
2 |
+
disable=all
|
3 |
+
enable=eval-used
|
CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
* @comfyanonymous
|
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
ADDED
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Flux Illusion Diffusion
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: gray
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.7.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: Optical illusions and style transfer with FLUX
|
12 |
+
---
|
13 |
+
<div align="center">
|
14 |
+
|
15 |
+
# ComfyUI
|
16 |
+
**The most powerful and modular diffusion model GUI and backend.**
|
17 |
+
|
18 |
+
|
19 |
+
[![Website][website-shield]][website-url]
|
20 |
+
[![Dynamic JSON Badge][discord-shield]][discord-url]
|
21 |
+
[![Matrix][matrix-shield]][matrix-url]
|
22 |
+
<br>
|
23 |
+
[![][github-release-shield]][github-release-link]
|
24 |
+
[![][github-release-date-shield]][github-release-link]
|
25 |
+
[![][github-downloads-shield]][github-downloads-link]
|
26 |
+
[![][github-downloads-latest-shield]][github-downloads-link]
|
27 |
+
|
28 |
+
[matrix-shield]: https://img.shields.io/badge/Matrix-000000?style=flat&logo=matrix&logoColor=white
|
29 |
+
[matrix-url]: https://app.element.io/#/room/%23comfyui_space%3Amatrix.org
|
30 |
+
[website-shield]: https://img.shields.io/badge/ComfyOrg-4285F4?style=flat
|
31 |
+
[website-url]: https://www.comfy.org/
|
32 |
+
<!-- Workaround to display total user from https://github.com/badges/shields/issues/4500#issuecomment-2060079995 -->
|
33 |
+
[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
|
34 |
+
[discord-url]: https://www.comfy.org/discord
|
35 |
+
|
36 |
+
[github-release-shield]: https://img.shields.io/github/v/release/comfyanonymous/ComfyUI?style=flat&sort=semver
|
37 |
+
[github-release-link]: https://github.com/comfyanonymous/ComfyUI/releases
|
38 |
+
[github-release-date-shield]: https://img.shields.io/github/release-date/comfyanonymous/ComfyUI?style=flat
|
39 |
+
[github-downloads-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/total?style=flat
|
40 |
+
[github-downloads-latest-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/latest/total?style=flat&label=downloads%40latest
|
41 |
+
[github-downloads-link]: https://github.com/comfyanonymous/ComfyUI/releases
|
42 |
+
|
43 |
+
![ComfyUI Screenshot](https://github.com/user-attachments/assets/7ccaf2c1-9b72-41ae-9a89-5688c94b7abe)
|
44 |
+
</div>
|
45 |
+
|
46 |
+
This ui will let you design and execute advanced stable diffusion pipelines using a graph/nodes/flowchart based interface. For some workflow examples and see what ComfyUI can do you can check out:
|
47 |
+
### [ComfyUI Examples](https://comfyanonymous.github.io/ComfyUI_examples/)
|
48 |
+
|
49 |
+
### [Installing ComfyUI](#installing)
|
50 |
+
|
51 |
+
## Features
|
52 |
+
- Nodes/graph/flowchart interface to experiment and create complex Stable Diffusion workflows without needing to code anything.
|
53 |
+
- Fully supports SD1.x, SD2.x, [SDXL](https://comfyanonymous.github.io/ComfyUI_examples/sdxl/), [Stable Video Diffusion](https://comfyanonymous.github.io/ComfyUI_examples/video/), [Stable Cascade](https://comfyanonymous.github.io/ComfyUI_examples/stable_cascade/), [SD3](https://comfyanonymous.github.io/ComfyUI_examples/sd3/) and [Stable Audio](https://comfyanonymous.github.io/ComfyUI_examples/audio/)
|
54 |
+
- [LTX-Video](https://comfyanonymous.github.io/ComfyUI_examples/ltxv/)
|
55 |
+
- [Flux](https://comfyanonymous.github.io/ComfyUI_examples/flux/)
|
56 |
+
- [Mochi](https://comfyanonymous.github.io/ComfyUI_examples/mochi/)
|
57 |
+
- Asynchronous Queue system
|
58 |
+
- Many optimizations: Only re-executes the parts of the workflow that changes between executions.
|
59 |
+
- Smart memory management: can automatically run models on GPUs with as low as 1GB vram.
|
60 |
+
- Works even if you don't have a GPU with: ```--cpu``` (slow)
|
61 |
+
- Can load ckpt, safetensors and diffusers models/checkpoints. Standalone VAEs and CLIP models.
|
62 |
+
- Embeddings/Textual inversion
|
63 |
+
- [Loras (regular, locon and loha)](https://comfyanonymous.github.io/ComfyUI_examples/lora/)
|
64 |
+
- [Hypernetworks](https://comfyanonymous.github.io/ComfyUI_examples/hypernetworks/)
|
65 |
+
- Loading full workflows (with seeds) from generated PNG, WebP and FLAC files.
|
66 |
+
- Saving/Loading workflows as Json files.
|
67 |
+
- 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.
|
68 |
+
- [Area Composition](https://comfyanonymous.github.io/ComfyUI_examples/area_composition/)
|
69 |
+
- [Inpainting](https://comfyanonymous.github.io/ComfyUI_examples/inpaint/) with both regular and inpainting models.
|
70 |
+
- [ControlNet and T2I-Adapter](https://comfyanonymous.github.io/ComfyUI_examples/controlnet/)
|
71 |
+
- [Upscale Models (ESRGAN, ESRGAN variants, SwinIR, Swin2SR, etc...)](https://comfyanonymous.github.io/ComfyUI_examples/upscale_models/)
|
72 |
+
- [unCLIP Models](https://comfyanonymous.github.io/ComfyUI_examples/unclip/)
|
73 |
+
- [GLIGEN](https://comfyanonymous.github.io/ComfyUI_examples/gligen/)
|
74 |
+
- [Model Merging](https://comfyanonymous.github.io/ComfyUI_examples/model_merging/)
|
75 |
+
- [LCM models and Loras](https://comfyanonymous.github.io/ComfyUI_examples/lcm/)
|
76 |
+
- [SDXL Turbo](https://comfyanonymous.github.io/ComfyUI_examples/sdturbo/)
|
77 |
+
- [AuraFlow](https://comfyanonymous.github.io/ComfyUI_examples/aura_flow/)
|
78 |
+
- [HunyuanDiT](https://comfyanonymous.github.io/ComfyUI_examples/hunyuan_dit/)
|
79 |
+
- Latent previews with [TAESD](#how-to-show-high-quality-previews)
|
80 |
+
- Starts up very fast.
|
81 |
+
- Works fully offline: will never download anything.
|
82 |
+
- [Config file](extra_model_paths.yaml.example) to set the search paths for models.
|
83 |
+
|
84 |
+
Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/)
|
85 |
+
|
86 |
+
## Shortcuts
|
87 |
+
|
88 |
+
| Keybind | Explanation |
|
89 |
+
|------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
90 |
+
| `Ctrl` + `Enter` | Queue up current graph for generation |
|
91 |
+
| `Ctrl` + `Shift` + `Enter` | Queue up current graph as first for generation |
|
92 |
+
| `Ctrl` + `Alt` + `Enter` | Cancel current generation |
|
93 |
+
| `Ctrl` + `Z`/`Ctrl` + `Y` | Undo/Redo |
|
94 |
+
| `Ctrl` + `S` | Save workflow |
|
95 |
+
| `Ctrl` + `O` | Load workflow |
|
96 |
+
| `Ctrl` + `A` | Select all nodes |
|
97 |
+
| `Alt `+ `C` | Collapse/uncollapse selected nodes |
|
98 |
+
| `Ctrl` + `M` | Mute/unmute selected nodes |
|
99 |
+
| `Ctrl` + `B` | Bypass selected nodes (acts like the node was removed from the graph and the wires reconnected through) |
|
100 |
+
| `Delete`/`Backspace` | Delete selected nodes |
|
101 |
+
| `Ctrl` + `Backspace` | Delete the current graph |
|
102 |
+
| `Space` | Move the canvas around when held and moving the cursor |
|
103 |
+
| `Ctrl`/`Shift` + `Click` | Add clicked node to selection |
|
104 |
+
| `Ctrl` + `C`/`Ctrl` + `V` | Copy and paste selected nodes (without maintaining connections to outputs of unselected nodes) |
|
105 |
+
| `Ctrl` + `C`/`Ctrl` + `Shift` + `V` | Copy and paste selected nodes (maintaining connections from outputs of unselected nodes to inputs of pasted nodes) |
|
106 |
+
| `Shift` + `Drag` | Move multiple selected nodes at the same time |
|
107 |
+
| `Ctrl` + `D` | Load default graph |
|
108 |
+
| `Alt` + `+` | Canvas Zoom in |
|
109 |
+
| `Alt` + `-` | Canvas Zoom out |
|
110 |
+
| `Ctrl` + `Shift` + LMB + Vertical drag | Canvas Zoom in/out |
|
111 |
+
| `P` | Pin/Unpin selected nodes |
|
112 |
+
| `Ctrl` + `G` | Group selected nodes |
|
113 |
+
| `Q` | Toggle visibility of the queue |
|
114 |
+
| `H` | Toggle visibility of history |
|
115 |
+
| `R` | Refresh graph |
|
116 |
+
| Double-Click LMB | Open node quick search palette |
|
117 |
+
| `Shift` + Drag | Move multiple wires at once |
|
118 |
+
| `Ctrl` + `Alt` + LMB | Disconnect all wires from clicked slot |
|
119 |
+
|
120 |
+
`Ctrl` can also be replaced with `Cmd` instead for macOS users
|
121 |
+
|
122 |
+
# Installing
|
123 |
+
|
124 |
+
## Windows
|
125 |
+
|
126 |
+
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).
|
127 |
+
|
128 |
+
### [Direct link to download](https://github.com/comfyanonymous/ComfyUI/releases/latest/download/ComfyUI_windows_portable_nvidia.7z)
|
129 |
+
|
130 |
+
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
|
131 |
+
|
132 |
+
If you have trouble extracting it, right click the file -> properties -> unblock
|
133 |
+
|
134 |
+
#### How do I share models between another UI and ComfyUI?
|
135 |
+
|
136 |
+
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.
|
137 |
+
|
138 |
+
## Jupyter Notebook
|
139 |
+
|
140 |
+
To run it on services like paperspace, kaggle or colab you can use my [Jupyter Notebook](notebooks/comfyui_colab.ipynb)
|
141 |
+
|
142 |
+
## Manual Install (Windows, Linux)
|
143 |
+
|
144 |
+
Note that some dependencies do not yet support python 3.13 so using 3.12 is recommended.
|
145 |
+
|
146 |
+
Git clone this repo.
|
147 |
+
|
148 |
+
Put your SD checkpoints (the huge ckpt/safetensors files) in: models/checkpoints
|
149 |
+
|
150 |
+
Put your VAE in: models/vae
|
151 |
+
|
152 |
+
|
153 |
+
### AMD GPUs (Linux only)
|
154 |
+
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:
|
155 |
+
|
156 |
+
```pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2```
|
157 |
+
|
158 |
+
This is the command to install the nightly with ROCm 6.2 which might have some performance improvements:
|
159 |
+
|
160 |
+
```pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.2```
|
161 |
+
|
162 |
+
### NVIDIA
|
163 |
+
|
164 |
+
Nvidia users should install stable pytorch using this command:
|
165 |
+
|
166 |
+
```pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu124```
|
167 |
+
|
168 |
+
This is the command to install pytorch nightly instead which might have performance improvements:
|
169 |
+
|
170 |
+
```pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu124```
|
171 |
+
|
172 |
+
#### Troubleshooting
|
173 |
+
|
174 |
+
If you get the "Torch not compiled with CUDA enabled" error, uninstall torch with:
|
175 |
+
|
176 |
+
```pip uninstall torch```
|
177 |
+
|
178 |
+
And install it again with the command above.
|
179 |
+
|
180 |
+
### Dependencies
|
181 |
+
|
182 |
+
Install the dependencies by opening your terminal inside the ComfyUI folder and:
|
183 |
+
|
184 |
+
```pip install -r requirements.txt```
|
185 |
+
|
186 |
+
After this you should have everything installed and can proceed to running ComfyUI.
|
187 |
+
|
188 |
+
### Others:
|
189 |
+
|
190 |
+
#### Intel GPUs
|
191 |
+
|
192 |
+
Intel GPU support is available for all Intel GPUs supported by Intel's Extension for Pytorch (IPEX) with the support requirements listed in the [Installation](https://intel.github.io/intel-extension-for-pytorch/index.html#installation?platform=gpu) page. Choose your platform and method of install and follow the instructions. The steps are as follows:
|
193 |
+
|
194 |
+
1. Start by installing the drivers or kernel listed or newer in the Installation page of IPEX linked above for Windows and Linux if needed.
|
195 |
+
1. Follow the instructions to install [Intel's oneAPI Basekit](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html) for your platform.
|
196 |
+
1. Install the packages for IPEX using the instructions provided in the Installation page for your platform.
|
197 |
+
1. Follow the [ComfyUI manual installation](#manual-install-windows-linux) instructions for Windows and Linux and run ComfyUI normally as described above after everything is installed.
|
198 |
+
|
199 |
+
Additional discussion and help can be found [here](https://github.com/comfyanonymous/ComfyUI/discussions/476).
|
200 |
+
|
201 |
+
#### Apple Mac silicon
|
202 |
+
|
203 |
+
You can install ComfyUI in Apple Mac silicon (M1 or M2) with any recent macOS version.
|
204 |
+
|
205 |
+
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).
|
206 |
+
1. Follow the [ComfyUI manual installation](#manual-install-windows-linux) instructions for Windows and Linux.
|
207 |
+
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).
|
208 |
+
1. Launch ComfyUI by running `python main.py`
|
209 |
+
|
210 |
+
> **Note**: Remember to add your models, VAE, LoRAs etc. to the corresponding Comfy folders, as discussed in [ComfyUI manual installation](#manual-install-windows-linux).
|
211 |
+
|
212 |
+
#### DirectML (AMD Cards on Windows)
|
213 |
+
|
214 |
+
```pip install torch-directml``` Then you can launch ComfyUI with: ```python main.py --directml```
|
215 |
+
|
216 |
+
# Running
|
217 |
+
|
218 |
+
```python main.py```
|
219 |
+
|
220 |
+
### For AMD cards not officially supported by ROCm
|
221 |
+
|
222 |
+
Try running it with this command if you have issues:
|
223 |
+
|
224 |
+
For 6700, 6600 and maybe other RDNA2 or older: ```HSA_OVERRIDE_GFX_VERSION=10.3.0 python main.py```
|
225 |
+
|
226 |
+
For AMD 7600 and maybe other RDNA3 cards: ```HSA_OVERRIDE_GFX_VERSION=11.0.0 python main.py```
|
227 |
+
|
228 |
+
### AMD ROCm Tips
|
229 |
+
|
230 |
+
You can enable experimental memory efficient attention on pytorch 2.5 in ComfyUI on RDNA3 and potentially other AMD GPUs using this command:
|
231 |
+
|
232 |
+
```TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1 python main.py --use-pytorch-cross-attention```
|
233 |
+
|
234 |
+
# Notes
|
235 |
+
|
236 |
+
Only parts of the graph that have an output with all the correct inputs will be executed.
|
237 |
+
|
238 |
+
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.
|
239 |
+
|
240 |
+
Dragging a generated png on the webpage or loading one will give you the full workflow including seeds that were used to create it.
|
241 |
+
|
242 |
+
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 \\).
|
243 |
+
|
244 |
+
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 \\}.
|
245 |
+
|
246 |
+
Dynamic prompts also support C-style comments, like `// comment` or `/* comment */`.
|
247 |
+
|
248 |
+
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):
|
249 |
+
|
250 |
+
```embedding:embedding_filename.pt```
|
251 |
+
|
252 |
+
|
253 |
+
## How to show high-quality previews?
|
254 |
+
|
255 |
+
Use ```--preview-method auto``` to enable previews.
|
256 |
+
|
257 |
+
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.
|
258 |
+
|
259 |
+
## How to use TLS/SSL?
|
260 |
+
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"`
|
261 |
+
|
262 |
+
Use `--tls-keyfile key.pem --tls-certfile cert.pem` to enable TLS/SSL, the app will now be accessible with `https://...` instead of `http://...`.
|
263 |
+
|
264 |
+
> 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.
|
265 |
+
<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.
|
266 |
+
|
267 |
+
## Support and dev channel
|
268 |
+
|
269 |
+
[Matrix space: #comfyui_space:matrix.org](https://app.element.io/#/room/%23comfyui_space%3Amatrix.org) (it's like discord but open source).
|
270 |
+
|
271 |
+
See also: [https://www.comfy.org/](https://www.comfy.org/)
|
272 |
+
|
273 |
+
## Frontend Development
|
274 |
+
|
275 |
+
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.
|
276 |
+
|
277 |
+
### Reporting Issues and Requesting Features
|
278 |
+
|
279 |
+
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.
|
280 |
+
|
281 |
+
### Using the Latest Frontend
|
282 |
+
|
283 |
+
The new frontend is now the default for ComfyUI. However, please note:
|
284 |
+
|
285 |
+
1. The frontend in the main ComfyUI repository is updated weekly.
|
286 |
+
2. Daily releases are available in the separate frontend repository.
|
287 |
+
|
288 |
+
To use the most up-to-date frontend version:
|
289 |
+
|
290 |
+
1. For the latest daily release, launch ComfyUI with this command line argument:
|
291 |
+
|
292 |
+
```
|
293 |
+
--front-end-version Comfy-Org/ComfyUI_frontend@latest
|
294 |
+
```
|
295 |
+
|
296 |
+
2. For a specific version, replace `latest` with the desired version number:
|
297 |
+
|
298 |
+
```
|
299 |
+
--front-end-version Comfy-Org/ComfyUI_frontend@1.2.2
|
300 |
+
```
|
301 |
+
|
302 |
+
This approach allows you to easily switch between the stable weekly release and the cutting-edge daily updates, or even specific versions for testing purposes.
|
303 |
+
|
304 |
+
### Accessing the Legacy Frontend
|
305 |
+
|
306 |
+
If you need to use the legacy frontend for any reason, you can access it using the following command line argument:
|
307 |
+
|
308 |
+
```
|
309 |
+
--front-end-version Comfy-Org/ComfyUI_legacy_frontend@latest
|
310 |
+
```
|
311 |
+
|
312 |
+
This will use a snapshot of the legacy frontend preserved in the [ComfyUI Legacy Frontend repository](https://github.com/Comfy-Org/ComfyUI_legacy_frontend).
|
313 |
+
|
314 |
+
# QA
|
315 |
+
|
316 |
+
### Which GPU should I buy for this?
|
317 |
+
|
318 |
+
[See this page for some recommendations](https://github.com/comfyanonymous/ComfyUI/wiki/Which-GPU-should-I-buy-for-ComfyUI)
|
319 |
+
|
api_server/__init__.py
ADDED
File without changes
|
api_server/routes/__init__.py
ADDED
File without changes
|
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/internal_routes.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from aiohttp import web
|
2 |
+
from typing import Optional
|
3 |
+
from folder_paths import models_dir, user_directory, output_directory, folder_names_and_paths
|
4 |
+
from api_server.services.file_service import FileService
|
5 |
+
from api_server.services.terminal_service import TerminalService
|
6 |
+
import app.logger
|
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.file_service = FileService({
|
19 |
+
"models": models_dir,
|
20 |
+
"user": user_directory,
|
21 |
+
"output": output_directory
|
22 |
+
})
|
23 |
+
self.prompt_server = prompt_server
|
24 |
+
self.terminal_service = TerminalService(prompt_server)
|
25 |
+
|
26 |
+
def setup_routes(self):
|
27 |
+
@self.routes.get('/files')
|
28 |
+
async def list_files(request):
|
29 |
+
directory_key = request.query.get('directory', '')
|
30 |
+
try:
|
31 |
+
file_list = self.file_service.list_files(directory_key)
|
32 |
+
return web.json_response({"files": file_list})
|
33 |
+
except ValueError as e:
|
34 |
+
return web.json_response({"error": str(e)}, status=400)
|
35 |
+
except Exception as e:
|
36 |
+
return web.json_response({"error": str(e)}, status=500)
|
37 |
+
|
38 |
+
@self.routes.get('/logs')
|
39 |
+
async def get_logs(request):
|
40 |
+
return web.json_response("".join([(l["t"] + " - " + l["m"]) for l in app.logger.get_logs()]))
|
41 |
+
|
42 |
+
@self.routes.get('/logs/raw')
|
43 |
+
async def get_logs(request):
|
44 |
+
self.terminal_service.update_size()
|
45 |
+
return web.json_response({
|
46 |
+
"entries": list(app.logger.get_logs()),
|
47 |
+
"size": {"cols": self.terminal_service.cols, "rows": self.terminal_service.rows}
|
48 |
+
})
|
49 |
+
|
50 |
+
@self.routes.patch('/logs/subscribe')
|
51 |
+
async def subscribe_logs(request):
|
52 |
+
json_data = await request.json()
|
53 |
+
client_id = json_data["clientId"]
|
54 |
+
enabled = json_data["enabled"]
|
55 |
+
if enabled:
|
56 |
+
self.terminal_service.subscribe(client_id)
|
57 |
+
else:
|
58 |
+
self.terminal_service.unsubscribe(client_id)
|
59 |
+
|
60 |
+
return web.Response(status=200)
|
61 |
+
|
62 |
+
|
63 |
+
@self.routes.get('/folder_paths')
|
64 |
+
async def get_folder_paths(request):
|
65 |
+
response = {}
|
66 |
+
for key in folder_names_and_paths:
|
67 |
+
response[key] = folder_names_and_paths[key][0]
|
68 |
+
return web.json_response(response)
|
69 |
+
|
70 |
+
def get_app(self):
|
71 |
+
if self._app is None:
|
72 |
+
self._app = web.Application()
|
73 |
+
self.setup_routes()
|
74 |
+
self._app.add_routes(self.routes)
|
75 |
+
return self._app
|
api_server/services/__init__.py
ADDED
File without changes
|
api_server/services/file_service.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Optional
|
2 |
+
from api_server.utils.file_operations import FileSystemOperations, FileSystemItem
|
3 |
+
|
4 |
+
class FileService:
|
5 |
+
def __init__(self, allowed_directories: Dict[str, str], file_system_ops: Optional[FileSystemOperations] = None):
|
6 |
+
self.allowed_directories: Dict[str, str] = allowed_directories
|
7 |
+
self.file_system_ops: FileSystemOperations = file_system_ops or FileSystemOperations()
|
8 |
+
|
9 |
+
def list_files(self, directory_key: str) -> List[FileSystemItem]:
|
10 |
+
if directory_key not in self.allowed_directories:
|
11 |
+
raise ValueError("Invalid directory key")
|
12 |
+
directory_path: str = self.allowed_directories[directory_key]
|
13 |
+
return self.file_system_ops.walk_directory(directory_path)
|
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,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
9 |
+
# Import all the necessary functions from the original script
|
10 |
+
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
11 |
+
try:
|
12 |
+
return obj[index]
|
13 |
+
except KeyError:
|
14 |
+
return obj["result"][index]
|
15 |
+
|
16 |
+
# Add all the necessary setup functions from the original script
|
17 |
+
def find_path(name: str, path: str = None) -> str:
|
18 |
+
if path is None:
|
19 |
+
path = os.getcwd()
|
20 |
+
if name in os.listdir(path):
|
21 |
+
path_name = os.path.join(path, name)
|
22 |
+
print(f"{name} found: {path_name}")
|
23 |
+
return path_name
|
24 |
+
parent_directory = os.path.dirname(path)
|
25 |
+
if parent_directory == path:
|
26 |
+
return None
|
27 |
+
return find_path(name, parent_directory)
|
28 |
+
|
29 |
+
def add_comfyui_directory_to_sys_path() -> None:
|
30 |
+
comfyui_path = find_path("ComfyUI")
|
31 |
+
if comfyui_path is not None and os.path.isdir(comfyui_path):
|
32 |
+
sys.path.append(comfyui_path)
|
33 |
+
print(f"'{comfyui_path}' added to sys.path")
|
34 |
+
|
35 |
+
def add_extra_model_paths() -> None:
|
36 |
+
try:
|
37 |
+
from main import load_extra_path_config
|
38 |
+
except ImportError:
|
39 |
+
from utils.extra_config import load_extra_path_config
|
40 |
+
extra_model_paths = find_path("extra_model_paths.yaml")
|
41 |
+
if extra_model_paths is not None:
|
42 |
+
load_extra_path_config(extra_model_paths)
|
43 |
+
else:
|
44 |
+
print("Could not find the extra_model_paths config file.")
|
45 |
+
|
46 |
+
# Initialize paths
|
47 |
+
add_comfyui_directory_to_sys_path()
|
48 |
+
add_extra_model_paths()
|
49 |
+
|
50 |
+
def import_custom_nodes() -> None:
|
51 |
+
import asyncio
|
52 |
+
import execution
|
53 |
+
from nodes import init_extra_nodes
|
54 |
+
import server
|
55 |
+
loop = asyncio.new_event_loop()
|
56 |
+
asyncio.set_event_loop(loop)
|
57 |
+
server_instance = server.PromptServer(loop)
|
58 |
+
execution.PromptQueue(server_instance)
|
59 |
+
init_extra_nodes()
|
60 |
+
|
61 |
+
# Import all necessary nodes
|
62 |
+
from nodes import (
|
63 |
+
StyleModelLoader,
|
64 |
+
VAEEncode,
|
65 |
+
NODE_CLASS_MAPPINGS,
|
66 |
+
LoadImage,
|
67 |
+
CLIPVisionLoader,
|
68 |
+
SaveImage,
|
69 |
+
VAELoader,
|
70 |
+
CLIPVisionEncode,
|
71 |
+
DualCLIPLoader,
|
72 |
+
EmptyLatentImage,
|
73 |
+
VAEDecode,
|
74 |
+
UNETLoader,
|
75 |
+
CLIPTextEncode,
|
76 |
+
)
|
77 |
+
|
78 |
+
# Initialize all constant nodes and models in global context
|
79 |
+
import_custom_nodes()
|
80 |
+
|
81 |
+
# Global variables for preloaded models and constants
|
82 |
+
with torch.inference_mode():
|
83 |
+
# Initialize constants
|
84 |
+
intconstant = NODE_CLASS_MAPPINGS["INTConstant"]()
|
85 |
+
CONST_1024 = intconstant.get_value(value=1024)
|
86 |
+
|
87 |
+
# Load CLIP
|
88 |
+
dualcliploader = DualCLIPLoader()
|
89 |
+
CLIP_MODEL = dualcliploader.load_clip(
|
90 |
+
clip_name1="t5/t5xxl_fp16.safetensors",
|
91 |
+
clip_name2="clip_l.safetensors",
|
92 |
+
type="flux",
|
93 |
+
)
|
94 |
+
|
95 |
+
# Load VAE
|
96 |
+
vaeloader = VAELoader()
|
97 |
+
VAE_MODEL = vaeloader.load_vae(vae_name="FLUX1/ae.safetensors")
|
98 |
+
|
99 |
+
# Load UNET
|
100 |
+
unetloader = UNETLoader()
|
101 |
+
UNET_MODEL = unetloader.load_unet(
|
102 |
+
unet_name="flux1-depth-dev.safetensors", weight_dtype="default"
|
103 |
+
)
|
104 |
+
|
105 |
+
# Load CLIP Vision
|
106 |
+
clipvisionloader = CLIPVisionLoader()
|
107 |
+
CLIP_VISION_MODEL = clipvisionloader.load_clip(
|
108 |
+
clip_name="sigclip_vision_patch14_384.safetensors"
|
109 |
+
)
|
110 |
+
|
111 |
+
# Load Style Model
|
112 |
+
stylemodelloader = StyleModelLoader()
|
113 |
+
STYLE_MODEL = stylemodelloader.load_style_model(
|
114 |
+
style_model_name="flux1-redux-dev.safetensors"
|
115 |
+
)
|
116 |
+
|
117 |
+
# Initialize samplers
|
118 |
+
ksamplerselect = NODE_CLASS_MAPPINGS["KSamplerSelect"]()
|
119 |
+
SAMPLER = ksamplerselect.get_sampler(sampler_name="euler")
|
120 |
+
|
121 |
+
# Initialize depth model
|
122 |
+
cr_clip_input_switch = NODE_CLASS_MAPPINGS["CR Clip Input Switch"]()
|
123 |
+
downloadandloaddepthanythingv2model = NODE_CLASS_MAPPINGS["DownloadAndLoadDepthAnythingV2Model"]()
|
124 |
+
DEPTH_MODEL = downloadandloaddepthanythingv2model.loadmodel(
|
125 |
+
model="depth_anything_v2_vitl_fp32.safetensors"
|
126 |
+
)
|
127 |
+
cliptextencode = CLIPTextEncode()
|
128 |
+
loadimage = LoadImage()
|
129 |
+
vaeencode = VAEEncode()
|
130 |
+
fluxguidance = NODE_CLASS_MAPPINGS["FluxGuidance"]()
|
131 |
+
instructpixtopixconditioning = NODE_CLASS_MAPPINGS["InstructPixToPixConditioning"]()
|
132 |
+
clipvisionencode = CLIPVisionEncode()
|
133 |
+
stylemodelapplyadvanced = NODE_CLASS_MAPPINGS["StyleModelApplyAdvanced"]()
|
134 |
+
emptylatentimage = EmptyLatentImage()
|
135 |
+
basicguider = NODE_CLASS_MAPPINGS["BasicGuider"]()
|
136 |
+
basicscheduler = NODE_CLASS_MAPPINGS["BasicScheduler"]()
|
137 |
+
randomnoise = NODE_CLASS_MAPPINGS["RandomNoise"]()
|
138 |
+
samplercustomadvanced = NODE_CLASS_MAPPINGS["SamplerCustomAdvanced"]()
|
139 |
+
vaedecode = VAEDecode()
|
140 |
+
cr_text = NODE_CLASS_MAPPINGS["CR Text"]()
|
141 |
+
saveimage = SaveImage()
|
142 |
+
getimagesizeandcount = NODE_CLASS_MAPPINGS["GetImageSizeAndCount"]()
|
143 |
+
depthanything_v2 = NODE_CLASS_MAPPINGS["DepthAnything_V2"]()
|
144 |
+
imageresize = NODE_CLASS_MAPPINGS["ImageResize+"]()
|
145 |
+
def generate_image(prompt: str, structure_image: str, depth_strength: float, style_image: str, style_strength: float, progress=gr.Progress(track_tqdm=True)) -> str:
|
146 |
+
"""Main generation function that processes inputs and returns the path to the generated image."""
|
147 |
+
|
148 |
+
with torch.inference_mode():
|
149 |
+
# Set up CLIP
|
150 |
+
clip_switch = cr_clip_input_switch.switch(
|
151 |
+
Input=1,
|
152 |
+
clip1=get_value_at_index(CLIP_MODEL, 0),
|
153 |
+
clip2=get_value_at_index(CLIP_MODEL, 0),
|
154 |
+
)
|
155 |
+
|
156 |
+
# Encode text
|
157 |
+
text_encoded = cliptextencode.encode(
|
158 |
+
text=prompt,
|
159 |
+
clip=get_value_at_index(clip_switch, 0),
|
160 |
+
)
|
161 |
+
empty_text = cliptextencode.encode(
|
162 |
+
text="",
|
163 |
+
clip=get_value_at_index(clip_switch, 0),
|
164 |
+
)
|
165 |
+
|
166 |
+
# Process structure image
|
167 |
+
structure_img = loadimage.load_image(image=structure_image)
|
168 |
+
|
169 |
+
# Resize image
|
170 |
+
resized_img = imageresize.execute(
|
171 |
+
width=get_value_at_index(CONST_1024, 0),
|
172 |
+
height=get_value_at_index(CONST_1024, 0),
|
173 |
+
interpolation="bicubic",
|
174 |
+
method="keep proportion",
|
175 |
+
condition="always",
|
176 |
+
multiple_of=16,
|
177 |
+
image=get_value_at_index(structure_img, 0),
|
178 |
+
)
|
179 |
+
|
180 |
+
# Get image size
|
181 |
+
size_info = getimagesizeandcount.getsize(
|
182 |
+
image=get_value_at_index(resized_img, 0)
|
183 |
+
)
|
184 |
+
|
185 |
+
# Encode VAE
|
186 |
+
vae_encoded = vaeencode.encode(
|
187 |
+
pixels=get_value_at_index(size_info, 0),
|
188 |
+
vae=get_value_at_index(VAE_MODEL, 0),
|
189 |
+
)
|
190 |
+
|
191 |
+
# Process depth
|
192 |
+
depth_processed = depthanything_v2.process(
|
193 |
+
da_model=get_value_at_index(DEPTH_MODEL, 0),
|
194 |
+
images=get_value_at_index(size_info, 0),
|
195 |
+
)
|
196 |
+
|
197 |
+
# Apply Flux guidance
|
198 |
+
flux_guided = fluxguidance.append(
|
199 |
+
guidance=depth_strength,
|
200 |
+
conditioning=get_value_at_index(text_encoded, 0),
|
201 |
+
)
|
202 |
+
|
203 |
+
# Process style image
|
204 |
+
style_img = loadimage.load_image(image=style_image)
|
205 |
+
|
206 |
+
# Encode style with CLIP Vision
|
207 |
+
style_encoded = clipvisionencode.encode(
|
208 |
+
crop="center",
|
209 |
+
clip_vision=get_value_at_index(CLIP_VISION_MODEL, 0),
|
210 |
+
image=get_value_at_index(style_img, 0),
|
211 |
+
)
|
212 |
+
|
213 |
+
# Set up conditioning
|
214 |
+
conditioning = instructpixtopixconditioning.encode(
|
215 |
+
positive=get_value_at_index(flux_guided, 0),
|
216 |
+
negative=get_value_at_index(empty_text, 0),
|
217 |
+
vae=get_value_at_index(VAE_MODEL, 0),
|
218 |
+
pixels=get_value_at_index(depth_processed, 0),
|
219 |
+
)
|
220 |
+
|
221 |
+
# Apply style
|
222 |
+
style_applied = stylemodelapplyadvanced.apply_stylemodel(
|
223 |
+
strength=style_strength,
|
224 |
+
conditioning=get_value_at_index(conditioning, 0),
|
225 |
+
style_model=get_value_at_index(STYLE_MODEL, 0),
|
226 |
+
clip_vision_output=get_value_at_index(style_encoded, 0),
|
227 |
+
)
|
228 |
+
|
229 |
+
# Set up empty latent
|
230 |
+
empty_latent = emptylatentimage.generate(
|
231 |
+
width=get_value_at_index(resized_img, 1),
|
232 |
+
height=get_value_at_index(resized_img, 2),
|
233 |
+
batch_size=1,
|
234 |
+
)
|
235 |
+
|
236 |
+
# Set up guidance
|
237 |
+
guided = basicguider.get_guider(
|
238 |
+
model=get_value_at_index(UNET_MODEL, 0),
|
239 |
+
conditioning=get_value_at_index(style_applied, 0),
|
240 |
+
)
|
241 |
+
|
242 |
+
# Set up scheduler
|
243 |
+
schedule = basicscheduler.get_sigmas(
|
244 |
+
scheduler="simple",
|
245 |
+
steps=28,
|
246 |
+
denoise=1,
|
247 |
+
model=get_value_at_index(UNET_MODEL, 0),
|
248 |
+
)
|
249 |
+
|
250 |
+
# Generate random noise
|
251 |
+
noise = randomnoise.get_noise(noise_seed=random.randint(1, 2**64))
|
252 |
+
|
253 |
+
# Sample
|
254 |
+
sampled = samplercustomadvanced.sample(
|
255 |
+
noise=get_value_at_index(noise, 0),
|
256 |
+
guider=get_value_at_index(guided, 0),
|
257 |
+
sampler=get_value_at_index(SAMPLER, 0),
|
258 |
+
sigmas=get_value_at_index(schedule, 0),
|
259 |
+
latent_image=get_value_at_index(empty_latent, 0),
|
260 |
+
)
|
261 |
+
|
262 |
+
# Decode VAE
|
263 |
+
decoded = vaedecode.decode(
|
264 |
+
samples=get_value_at_index(sampled, 0),
|
265 |
+
vae=get_value_at_index(VAE_MODEL, 0),
|
266 |
+
)
|
267 |
+
|
268 |
+
# Save image
|
269 |
+
prefix = cr_text.text_multiline(text="Flux_BFL_Depth_Redux")
|
270 |
+
|
271 |
+
saved = saveimage.save_images(
|
272 |
+
filename_prefix=get_value_at_index(prefix, 0),
|
273 |
+
images=get_value_at_index(decoded, 0),
|
274 |
+
)
|
275 |
+
saved_path = f"output/{saved['ui']['images'][0]['filename']}"
|
276 |
+
print(saved_path)
|
277 |
+
return saved_path
|
278 |
+
|
279 |
+
# Create Gradio interface
|
280 |
+
with gr.Blocks() as app:
|
281 |
+
gr.Markdown("# Image Generation with Style Transfer")
|
282 |
+
|
283 |
+
with gr.Row():
|
284 |
+
with gr.Column():
|
285 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
286 |
+
with gr.Row():
|
287 |
+
with gr.Group():
|
288 |
+
structure_image = gr.Image(label="Structure Image", type="filepath")
|
289 |
+
depth_strength = gr.Slider(minimum=0, maximum=50, value=15, label="Depth Strength")
|
290 |
+
with gr.Group():
|
291 |
+
style_image = gr.Image(label="Style Image", type="filepath")
|
292 |
+
style_strength = gr.Slider(minimum=0, maximum=1, value=0.5, label="Style Strength")
|
293 |
+
generate_btn = gr.Button("Generate")
|
294 |
+
|
295 |
+
with gr.Column():
|
296 |
+
output_image = gr.Image(label="Generated Image")
|
297 |
+
|
298 |
+
generate_btn.click(
|
299 |
+
fn=generate_image,
|
300 |
+
inputs=[prompt_input, structure_image, depth_strength, style_image, style_strength],
|
301 |
+
outputs=[output_image]
|
302 |
+
)
|
303 |
+
|
304 |
+
if __name__ == "__main__":
|
305 |
+
app.launch(share=True)
|
app/__init__.py
ADDED
File without changes
|
app/app_settings.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from aiohttp import web
|
4 |
+
|
5 |
+
|
6 |
+
class AppSettings():
|
7 |
+
def __init__(self, user_manager):
|
8 |
+
self.user_manager = user_manager
|
9 |
+
|
10 |
+
def get_settings(self, request):
|
11 |
+
file = self.user_manager.get_request_user_filepath(
|
12 |
+
request, "comfy.settings.json")
|
13 |
+
if os.path.isfile(file):
|
14 |
+
with open(file) as f:
|
15 |
+
return json.load(f)
|
16 |
+
else:
|
17 |
+
return {}
|
18 |
+
|
19 |
+
def save_settings(self, request, settings):
|
20 |
+
file = self.user_manager.get_request_user_filepath(
|
21 |
+
request, "comfy.settings.json")
|
22 |
+
with open(file, "w") as f:
|
23 |
+
f.write(json.dumps(settings, indent=4))
|
24 |
+
|
25 |
+
def add_routes(self, routes):
|
26 |
+
@routes.get("/settings")
|
27 |
+
async def get_settings(request):
|
28 |
+
return web.json_response(self.get_settings(request))
|
29 |
+
|
30 |
+
@routes.get("/settings/{id}")
|
31 |
+
async def get_setting(request):
|
32 |
+
value = None
|
33 |
+
settings = self.get_settings(request)
|
34 |
+
setting_id = request.match_info.get("id", None)
|
35 |
+
if setting_id and setting_id in settings:
|
36 |
+
value = settings[setting_id]
|
37 |
+
return web.json_response(value)
|
38 |
+
|
39 |
+
@routes.post("/settings")
|
40 |
+
async def post_settings(request):
|
41 |
+
settings = self.get_settings(request)
|
42 |
+
new_settings = await request.json()
|
43 |
+
self.save_settings(request, {**settings, **new_settings})
|
44 |
+
return web.Response(status=200)
|
45 |
+
|
46 |
+
@routes.post("/settings/{id}")
|
47 |
+
async def post_setting(request):
|
48 |
+
setting_id = request.match_info.get("id", None)
|
49 |
+
if not setting_id:
|
50 |
+
return web.Response(status=400)
|
51 |
+
settings = self.get_settings(request)
|
52 |
+
settings[setting_id] = await request.json()
|
53 |
+
self.save_settings(request, settings)
|
54 |
+
return web.Response(status=200)
|
app/frontend_management.py
ADDED
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
import argparse
|
3 |
+
import logging
|
4 |
+
import os
|
5 |
+
import re
|
6 |
+
import tempfile
|
7 |
+
import zipfile
|
8 |
+
from dataclasses import dataclass
|
9 |
+
from functools import cached_property
|
10 |
+
from pathlib import Path
|
11 |
+
from typing import TypedDict, Optional
|
12 |
+
|
13 |
+
import requests
|
14 |
+
from typing_extensions import NotRequired
|
15 |
+
from comfy.cli_args import DEFAULT_VERSION_STRING
|
16 |
+
|
17 |
+
|
18 |
+
REQUEST_TIMEOUT = 10 # seconds
|
19 |
+
|
20 |
+
|
21 |
+
class Asset(TypedDict):
|
22 |
+
url: str
|
23 |
+
|
24 |
+
|
25 |
+
class Release(TypedDict):
|
26 |
+
id: int
|
27 |
+
tag_name: str
|
28 |
+
name: str
|
29 |
+
prerelease: bool
|
30 |
+
created_at: str
|
31 |
+
published_at: str
|
32 |
+
body: str
|
33 |
+
assets: NotRequired[list[Asset]]
|
34 |
+
|
35 |
+
|
36 |
+
@dataclass
|
37 |
+
class FrontEndProvider:
|
38 |
+
owner: str
|
39 |
+
repo: str
|
40 |
+
|
41 |
+
@property
|
42 |
+
def folder_name(self) -> str:
|
43 |
+
return f"{self.owner}_{self.repo}"
|
44 |
+
|
45 |
+
@property
|
46 |
+
def release_url(self) -> str:
|
47 |
+
return f"https://api.github.com/repos/{self.owner}/{self.repo}/releases"
|
48 |
+
|
49 |
+
@cached_property
|
50 |
+
def all_releases(self) -> list[Release]:
|
51 |
+
releases = []
|
52 |
+
api_url = self.release_url
|
53 |
+
while api_url:
|
54 |
+
response = requests.get(api_url, timeout=REQUEST_TIMEOUT)
|
55 |
+
response.raise_for_status() # Raises an HTTPError if the response was an error
|
56 |
+
releases.extend(response.json())
|
57 |
+
# GitHub uses the Link header to provide pagination links. Check if it exists and update api_url accordingly.
|
58 |
+
if "next" in response.links:
|
59 |
+
api_url = response.links["next"]["url"]
|
60 |
+
else:
|
61 |
+
api_url = None
|
62 |
+
return releases
|
63 |
+
|
64 |
+
@cached_property
|
65 |
+
def latest_release(self) -> Release:
|
66 |
+
latest_release_url = f"{self.release_url}/latest"
|
67 |
+
response = requests.get(latest_release_url, timeout=REQUEST_TIMEOUT)
|
68 |
+
response.raise_for_status() # Raises an HTTPError if the response was an error
|
69 |
+
return response.json()
|
70 |
+
|
71 |
+
def get_release(self, version: str) -> Release:
|
72 |
+
if version == "latest":
|
73 |
+
return self.latest_release
|
74 |
+
else:
|
75 |
+
for release in self.all_releases:
|
76 |
+
if release["tag_name"] in [version, f"v{version}"]:
|
77 |
+
return release
|
78 |
+
raise ValueError(f"Version {version} not found in releases")
|
79 |
+
|
80 |
+
|
81 |
+
def download_release_asset_zip(release: Release, destination_path: str) -> None:
|
82 |
+
"""Download dist.zip from github release."""
|
83 |
+
asset_url = None
|
84 |
+
for asset in release.get("assets", []):
|
85 |
+
if asset["name"] == "dist.zip":
|
86 |
+
asset_url = asset["url"]
|
87 |
+
break
|
88 |
+
|
89 |
+
if not asset_url:
|
90 |
+
raise ValueError("dist.zip not found in the release assets")
|
91 |
+
|
92 |
+
# Use a temporary file to download the zip content
|
93 |
+
with tempfile.TemporaryFile() as tmp_file:
|
94 |
+
headers = {"Accept": "application/octet-stream"}
|
95 |
+
response = requests.get(
|
96 |
+
asset_url, headers=headers, allow_redirects=True, timeout=REQUEST_TIMEOUT
|
97 |
+
)
|
98 |
+
response.raise_for_status() # Ensure we got a successful response
|
99 |
+
|
100 |
+
# Write the content to the temporary file
|
101 |
+
tmp_file.write(response.content)
|
102 |
+
|
103 |
+
# Go back to the beginning of the temporary file
|
104 |
+
tmp_file.seek(0)
|
105 |
+
|
106 |
+
# Extract the zip file content to the destination path
|
107 |
+
with zipfile.ZipFile(tmp_file, "r") as zip_ref:
|
108 |
+
zip_ref.extractall(destination_path)
|
109 |
+
|
110 |
+
|
111 |
+
class FrontendManager:
|
112 |
+
DEFAULT_FRONTEND_PATH = str(Path(__file__).parents[1] / "web")
|
113 |
+
CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions")
|
114 |
+
|
115 |
+
@classmethod
|
116 |
+
def parse_version_string(cls, value: str) -> tuple[str, str, str]:
|
117 |
+
"""
|
118 |
+
Args:
|
119 |
+
value (str): The version string to parse.
|
120 |
+
|
121 |
+
Returns:
|
122 |
+
tuple[str, str]: A tuple containing provider name and version.
|
123 |
+
|
124 |
+
Raises:
|
125 |
+
argparse.ArgumentTypeError: If the version string is invalid.
|
126 |
+
"""
|
127 |
+
VERSION_PATTERN = r"^([a-zA-Z0-9][a-zA-Z0-9-]{0,38})/([a-zA-Z0-9_.-]+)@(v?\d+\.\d+\.\d+|latest)$"
|
128 |
+
match_result = re.match(VERSION_PATTERN, value)
|
129 |
+
if match_result is None:
|
130 |
+
raise argparse.ArgumentTypeError(f"Invalid version string: {value}")
|
131 |
+
|
132 |
+
return match_result.group(1), match_result.group(2), match_result.group(3)
|
133 |
+
|
134 |
+
@classmethod
|
135 |
+
def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndProvider] = None) -> str:
|
136 |
+
"""
|
137 |
+
Initializes the frontend for the specified version.
|
138 |
+
|
139 |
+
Args:
|
140 |
+
version_string (str): The version string.
|
141 |
+
provider (FrontEndProvider, optional): The provider to use. Defaults to None.
|
142 |
+
|
143 |
+
Returns:
|
144 |
+
str: The path to the initialized frontend.
|
145 |
+
|
146 |
+
Raises:
|
147 |
+
Exception: If there is an error during the initialization process.
|
148 |
+
main error source might be request timeout or invalid URL.
|
149 |
+
"""
|
150 |
+
if version_string == DEFAULT_VERSION_STRING:
|
151 |
+
return cls.DEFAULT_FRONTEND_PATH
|
152 |
+
|
153 |
+
repo_owner, repo_name, version = cls.parse_version_string(version_string)
|
154 |
+
|
155 |
+
if version.startswith("v"):
|
156 |
+
expected_path = str(Path(cls.CUSTOM_FRONTENDS_ROOT) / f"{repo_owner}_{repo_name}" / version.lstrip("v"))
|
157 |
+
if os.path.exists(expected_path):
|
158 |
+
logging.info(f"Using existing copy of specific frontend version tag: {repo_owner}/{repo_name}@{version}")
|
159 |
+
return expected_path
|
160 |
+
|
161 |
+
logging.info(f"Initializing frontend: {repo_owner}/{repo_name}@{version}, requesting version details from GitHub...")
|
162 |
+
|
163 |
+
provider = provider or FrontEndProvider(repo_owner, repo_name)
|
164 |
+
release = provider.get_release(version)
|
165 |
+
|
166 |
+
semantic_version = release["tag_name"].lstrip("v")
|
167 |
+
web_root = str(
|
168 |
+
Path(cls.CUSTOM_FRONTENDS_ROOT) / provider.folder_name / semantic_version
|
169 |
+
)
|
170 |
+
if not os.path.exists(web_root):
|
171 |
+
try:
|
172 |
+
os.makedirs(web_root, exist_ok=True)
|
173 |
+
logging.info(
|
174 |
+
"Downloading frontend(%s) version(%s) to (%s)",
|
175 |
+
provider.folder_name,
|
176 |
+
semantic_version,
|
177 |
+
web_root,
|
178 |
+
)
|
179 |
+
logging.debug(release)
|
180 |
+
download_release_asset_zip(release, destination_path=web_root)
|
181 |
+
finally:
|
182 |
+
# Clean up the directory if it is empty, i.e. the download failed
|
183 |
+
if not os.listdir(web_root):
|
184 |
+
os.rmdir(web_root)
|
185 |
+
|
186 |
+
return web_root
|
187 |
+
|
188 |
+
@classmethod
|
189 |
+
def init_frontend(cls, version_string: str) -> str:
|
190 |
+
"""
|
191 |
+
Initializes the frontend with the specified version string.
|
192 |
+
|
193 |
+
Args:
|
194 |
+
version_string (str): The version string to initialize the frontend with.
|
195 |
+
|
196 |
+
Returns:
|
197 |
+
str: The path of the initialized frontend.
|
198 |
+
"""
|
199 |
+
try:
|
200 |
+
return cls.init_frontend_unsafe(version_string)
|
201 |
+
except Exception as e:
|
202 |
+
logging.error("Failed to initialize frontend: %s", e)
|
203 |
+
logging.info("Falling back to the default frontend.")
|
204 |
+
return cls.DEFAULT_FRONTEND_PATH
|
app/logger.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
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 |
+
logger.addHandler(stream_handler)
|
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 |
+
print("****** User settings have been changed to be stored on the server instead of browser storage. ******")
|
42 |
+
print("****** 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/checkpoint_pickle.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
|
3 |
+
load = pickle.load
|
4 |
+
|
5 |
+
class Empty:
|
6 |
+
pass
|
7 |
+
|
8 |
+
class Unpickler(pickle.Unpickler):
|
9 |
+
def find_class(self, module, name):
|
10 |
+
#TODO: safe unpickle
|
11 |
+
if module.startswith("pytorch_lightning"):
|
12 |
+
return Empty
|
13 |
+
return super().find_class(module, name)
|
comfy/cldm/cldm.py
ADDED
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#taken from: https://github.com/lllyasviel/ControlNet
|
2 |
+
#and modified
|
3 |
+
|
4 |
+
import torch
|
5 |
+
import torch as th
|
6 |
+
import torch.nn as nn
|
7 |
+
|
8 |
+
from ..ldm.modules.diffusionmodules.util import (
|
9 |
+
zero_module,
|
10 |
+
timestep_embedding,
|
11 |
+
)
|
12 |
+
|
13 |
+
from ..ldm.modules.attention import SpatialTransformer
|
14 |
+
from ..ldm.modules.diffusionmodules.openaimodel import UNetModel, TimestepEmbedSequential, ResBlock, Downsample
|
15 |
+
from ..ldm.util import exists
|
16 |
+
from .control_types import UNION_CONTROLNET_TYPES
|
17 |
+
from collections import OrderedDict
|
18 |
+
import comfy.ops
|
19 |
+
from comfy.ldm.modules.attention import optimized_attention
|
20 |
+
|
21 |
+
class OptimizedAttention(nn.Module):
|
22 |
+
def __init__(self, c, nhead, dropout=0.0, dtype=None, device=None, operations=None):
|
23 |
+
super().__init__()
|
24 |
+
self.heads = nhead
|
25 |
+
self.c = c
|
26 |
+
|
27 |
+
self.in_proj = operations.Linear(c, c * 3, bias=True, dtype=dtype, device=device)
|
28 |
+
self.out_proj = operations.Linear(c, c, bias=True, dtype=dtype, device=device)
|
29 |
+
|
30 |
+
def forward(self, x):
|
31 |
+
x = self.in_proj(x)
|
32 |
+
q, k, v = x.split(self.c, dim=2)
|
33 |
+
out = optimized_attention(q, k, v, self.heads)
|
34 |
+
return self.out_proj(out)
|
35 |
+
|
36 |
+
class QuickGELU(nn.Module):
|
37 |
+
def forward(self, x: torch.Tensor):
|
38 |
+
return x * torch.sigmoid(1.702 * x)
|
39 |
+
|
40 |
+
class ResBlockUnionControlnet(nn.Module):
|
41 |
+
def __init__(self, dim, nhead, dtype=None, device=None, operations=None):
|
42 |
+
super().__init__()
|
43 |
+
self.attn = OptimizedAttention(dim, nhead, dtype=dtype, device=device, operations=operations)
|
44 |
+
self.ln_1 = operations.LayerNorm(dim, dtype=dtype, device=device)
|
45 |
+
self.mlp = nn.Sequential(
|
46 |
+
OrderedDict([("c_fc", operations.Linear(dim, dim * 4, dtype=dtype, device=device)), ("gelu", QuickGELU()),
|
47 |
+
("c_proj", operations.Linear(dim * 4, dim, dtype=dtype, device=device))]))
|
48 |
+
self.ln_2 = operations.LayerNorm(dim, dtype=dtype, device=device)
|
49 |
+
|
50 |
+
def attention(self, x: torch.Tensor):
|
51 |
+
return self.attn(x)
|
52 |
+
|
53 |
+
def forward(self, x: torch.Tensor):
|
54 |
+
x = x + self.attention(self.ln_1(x))
|
55 |
+
x = x + self.mlp(self.ln_2(x))
|
56 |
+
return x
|
57 |
+
|
58 |
+
class ControlledUnetModel(UNetModel):
|
59 |
+
#implemented in the ldm unet
|
60 |
+
pass
|
61 |
+
|
62 |
+
class ControlNet(nn.Module):
|
63 |
+
def __init__(
|
64 |
+
self,
|
65 |
+
image_size,
|
66 |
+
in_channels,
|
67 |
+
model_channels,
|
68 |
+
hint_channels,
|
69 |
+
num_res_blocks,
|
70 |
+
dropout=0,
|
71 |
+
channel_mult=(1, 2, 4, 8),
|
72 |
+
conv_resample=True,
|
73 |
+
dims=2,
|
74 |
+
num_classes=None,
|
75 |
+
use_checkpoint=False,
|
76 |
+
dtype=torch.float32,
|
77 |
+
num_heads=-1,
|
78 |
+
num_head_channels=-1,
|
79 |
+
num_heads_upsample=-1,
|
80 |
+
use_scale_shift_norm=False,
|
81 |
+
resblock_updown=False,
|
82 |
+
use_new_attention_order=False,
|
83 |
+
use_spatial_transformer=False, # custom transformer support
|
84 |
+
transformer_depth=1, # custom transformer support
|
85 |
+
context_dim=None, # custom transformer support
|
86 |
+
n_embed=None, # custom support for prediction of discrete ids into codebook of first stage vq model
|
87 |
+
legacy=True,
|
88 |
+
disable_self_attentions=None,
|
89 |
+
num_attention_blocks=None,
|
90 |
+
disable_middle_self_attn=False,
|
91 |
+
use_linear_in_transformer=False,
|
92 |
+
adm_in_channels=None,
|
93 |
+
transformer_depth_middle=None,
|
94 |
+
transformer_depth_output=None,
|
95 |
+
attn_precision=None,
|
96 |
+
union_controlnet_num_control_type=None,
|
97 |
+
device=None,
|
98 |
+
operations=comfy.ops.disable_weight_init,
|
99 |
+
**kwargs,
|
100 |
+
):
|
101 |
+
super().__init__()
|
102 |
+
assert use_spatial_transformer == True, "use_spatial_transformer has to be true"
|
103 |
+
if use_spatial_transformer:
|
104 |
+
assert context_dim is not None, 'Fool!! You forgot to include the dimension of your cross-attention conditioning...'
|
105 |
+
|
106 |
+
if context_dim is not None:
|
107 |
+
assert use_spatial_transformer, 'Fool!! You forgot to use the spatial transformer for your cross-attention conditioning...'
|
108 |
+
# from omegaconf.listconfig import ListConfig
|
109 |
+
# if type(context_dim) == ListConfig:
|
110 |
+
# context_dim = list(context_dim)
|
111 |
+
|
112 |
+
if num_heads_upsample == -1:
|
113 |
+
num_heads_upsample = num_heads
|
114 |
+
|
115 |
+
if num_heads == -1:
|
116 |
+
assert num_head_channels != -1, 'Either num_heads or num_head_channels has to be set'
|
117 |
+
|
118 |
+
if num_head_channels == -1:
|
119 |
+
assert num_heads != -1, 'Either num_heads or num_head_channels has to be set'
|
120 |
+
|
121 |
+
self.dims = dims
|
122 |
+
self.image_size = image_size
|
123 |
+
self.in_channels = in_channels
|
124 |
+
self.model_channels = model_channels
|
125 |
+
|
126 |
+
if isinstance(num_res_blocks, int):
|
127 |
+
self.num_res_blocks = len(channel_mult) * [num_res_blocks]
|
128 |
+
else:
|
129 |
+
if len(num_res_blocks) != len(channel_mult):
|
130 |
+
raise ValueError("provide num_res_blocks either as an int (globally constant) or "
|
131 |
+
"as a list/tuple (per-level) with the same length as channel_mult")
|
132 |
+
self.num_res_blocks = num_res_blocks
|
133 |
+
|
134 |
+
if disable_self_attentions is not None:
|
135 |
+
# should be a list of booleans, indicating whether to disable self-attention in TransformerBlocks or not
|
136 |
+
assert len(disable_self_attentions) == len(channel_mult)
|
137 |
+
if num_attention_blocks is not None:
|
138 |
+
assert len(num_attention_blocks) == len(self.num_res_blocks)
|
139 |
+
assert all(map(lambda i: self.num_res_blocks[i] >= num_attention_blocks[i], range(len(num_attention_blocks))))
|
140 |
+
|
141 |
+
transformer_depth = transformer_depth[:]
|
142 |
+
|
143 |
+
self.dropout = dropout
|
144 |
+
self.channel_mult = channel_mult
|
145 |
+
self.conv_resample = conv_resample
|
146 |
+
self.num_classes = num_classes
|
147 |
+
self.use_checkpoint = use_checkpoint
|
148 |
+
self.dtype = dtype
|
149 |
+
self.num_heads = num_heads
|
150 |
+
self.num_head_channels = num_head_channels
|
151 |
+
self.num_heads_upsample = num_heads_upsample
|
152 |
+
self.predict_codebook_ids = n_embed is not None
|
153 |
+
|
154 |
+
time_embed_dim = model_channels * 4
|
155 |
+
self.time_embed = nn.Sequential(
|
156 |
+
operations.Linear(model_channels, time_embed_dim, dtype=self.dtype, device=device),
|
157 |
+
nn.SiLU(),
|
158 |
+
operations.Linear(time_embed_dim, time_embed_dim, dtype=self.dtype, device=device),
|
159 |
+
)
|
160 |
+
|
161 |
+
if self.num_classes is not None:
|
162 |
+
if isinstance(self.num_classes, int):
|
163 |
+
self.label_emb = nn.Embedding(num_classes, time_embed_dim)
|
164 |
+
elif self.num_classes == "continuous":
|
165 |
+
print("setting up linear c_adm embedding layer")
|
166 |
+
self.label_emb = nn.Linear(1, time_embed_dim)
|
167 |
+
elif self.num_classes == "sequential":
|
168 |
+
assert adm_in_channels is not None
|
169 |
+
self.label_emb = nn.Sequential(
|
170 |
+
nn.Sequential(
|
171 |
+
operations.Linear(adm_in_channels, time_embed_dim, dtype=self.dtype, device=device),
|
172 |
+
nn.SiLU(),
|
173 |
+
operations.Linear(time_embed_dim, time_embed_dim, dtype=self.dtype, device=device),
|
174 |
+
)
|
175 |
+
)
|
176 |
+
else:
|
177 |
+
raise ValueError()
|
178 |
+
|
179 |
+
self.input_blocks = nn.ModuleList(
|
180 |
+
[
|
181 |
+
TimestepEmbedSequential(
|
182 |
+
operations.conv_nd(dims, in_channels, model_channels, 3, padding=1, dtype=self.dtype, device=device)
|
183 |
+
)
|
184 |
+
]
|
185 |
+
)
|
186 |
+
self.zero_convs = nn.ModuleList([self.make_zero_conv(model_channels, operations=operations, dtype=self.dtype, device=device)])
|
187 |
+
|
188 |
+
self.input_hint_block = TimestepEmbedSequential(
|
189 |
+
operations.conv_nd(dims, hint_channels, 16, 3, padding=1, dtype=self.dtype, device=device),
|
190 |
+
nn.SiLU(),
|
191 |
+
operations.conv_nd(dims, 16, 16, 3, padding=1, dtype=self.dtype, device=device),
|
192 |
+
nn.SiLU(),
|
193 |
+
operations.conv_nd(dims, 16, 32, 3, padding=1, stride=2, dtype=self.dtype, device=device),
|
194 |
+
nn.SiLU(),
|
195 |
+
operations.conv_nd(dims, 32, 32, 3, padding=1, dtype=self.dtype, device=device),
|
196 |
+
nn.SiLU(),
|
197 |
+
operations.conv_nd(dims, 32, 96, 3, padding=1, stride=2, dtype=self.dtype, device=device),
|
198 |
+
nn.SiLU(),
|
199 |
+
operations.conv_nd(dims, 96, 96, 3, padding=1, dtype=self.dtype, device=device),
|
200 |
+
nn.SiLU(),
|
201 |
+
operations.conv_nd(dims, 96, 256, 3, padding=1, stride=2, dtype=self.dtype, device=device),
|
202 |
+
nn.SiLU(),
|
203 |
+
operations.conv_nd(dims, 256, model_channels, 3, padding=1, dtype=self.dtype, device=device)
|
204 |
+
)
|
205 |
+
|
206 |
+
self._feature_size = model_channels
|
207 |
+
input_block_chans = [model_channels]
|
208 |
+
ch = model_channels
|
209 |
+
ds = 1
|
210 |
+
for level, mult in enumerate(channel_mult):
|
211 |
+
for nr in range(self.num_res_blocks[level]):
|
212 |
+
layers = [
|
213 |
+
ResBlock(
|
214 |
+
ch,
|
215 |
+
time_embed_dim,
|
216 |
+
dropout,
|
217 |
+
out_channels=mult * model_channels,
|
218 |
+
dims=dims,
|
219 |
+
use_checkpoint=use_checkpoint,
|
220 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
221 |
+
dtype=self.dtype,
|
222 |
+
device=device,
|
223 |
+
operations=operations,
|
224 |
+
)
|
225 |
+
]
|
226 |
+
ch = mult * model_channels
|
227 |
+
num_transformers = transformer_depth.pop(0)
|
228 |
+
if num_transformers > 0:
|
229 |
+
if num_head_channels == -1:
|
230 |
+
dim_head = ch // num_heads
|
231 |
+
else:
|
232 |
+
num_heads = ch // num_head_channels
|
233 |
+
dim_head = num_head_channels
|
234 |
+
if legacy:
|
235 |
+
#num_heads = 1
|
236 |
+
dim_head = ch // num_heads if use_spatial_transformer else num_head_channels
|
237 |
+
if exists(disable_self_attentions):
|
238 |
+
disabled_sa = disable_self_attentions[level]
|
239 |
+
else:
|
240 |
+
disabled_sa = False
|
241 |
+
|
242 |
+
if not exists(num_attention_blocks) or nr < num_attention_blocks[level]:
|
243 |
+
layers.append(
|
244 |
+
SpatialTransformer(
|
245 |
+
ch, num_heads, dim_head, depth=num_transformers, context_dim=context_dim,
|
246 |
+
disable_self_attn=disabled_sa, use_linear=use_linear_in_transformer,
|
247 |
+
use_checkpoint=use_checkpoint, attn_precision=attn_precision, dtype=self.dtype, device=device, operations=operations
|
248 |
+
)
|
249 |
+
)
|
250 |
+
self.input_blocks.append(TimestepEmbedSequential(*layers))
|
251 |
+
self.zero_convs.append(self.make_zero_conv(ch, operations=operations, dtype=self.dtype, device=device))
|
252 |
+
self._feature_size += ch
|
253 |
+
input_block_chans.append(ch)
|
254 |
+
if level != len(channel_mult) - 1:
|
255 |
+
out_ch = ch
|
256 |
+
self.input_blocks.append(
|
257 |
+
TimestepEmbedSequential(
|
258 |
+
ResBlock(
|
259 |
+
ch,
|
260 |
+
time_embed_dim,
|
261 |
+
dropout,
|
262 |
+
out_channels=out_ch,
|
263 |
+
dims=dims,
|
264 |
+
use_checkpoint=use_checkpoint,
|
265 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
266 |
+
down=True,
|
267 |
+
dtype=self.dtype,
|
268 |
+
device=device,
|
269 |
+
operations=operations
|
270 |
+
)
|
271 |
+
if resblock_updown
|
272 |
+
else Downsample(
|
273 |
+
ch, conv_resample, dims=dims, out_channels=out_ch, dtype=self.dtype, device=device, operations=operations
|
274 |
+
)
|
275 |
+
)
|
276 |
+
)
|
277 |
+
ch = out_ch
|
278 |
+
input_block_chans.append(ch)
|
279 |
+
self.zero_convs.append(self.make_zero_conv(ch, operations=operations, dtype=self.dtype, device=device))
|
280 |
+
ds *= 2
|
281 |
+
self._feature_size += ch
|
282 |
+
|
283 |
+
if num_head_channels == -1:
|
284 |
+
dim_head = ch // num_heads
|
285 |
+
else:
|
286 |
+
num_heads = ch // num_head_channels
|
287 |
+
dim_head = num_head_channels
|
288 |
+
if legacy:
|
289 |
+
#num_heads = 1
|
290 |
+
dim_head = ch // num_heads if use_spatial_transformer else num_head_channels
|
291 |
+
mid_block = [
|
292 |
+
ResBlock(
|
293 |
+
ch,
|
294 |
+
time_embed_dim,
|
295 |
+
dropout,
|
296 |
+
dims=dims,
|
297 |
+
use_checkpoint=use_checkpoint,
|
298 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
299 |
+
dtype=self.dtype,
|
300 |
+
device=device,
|
301 |
+
operations=operations
|
302 |
+
)]
|
303 |
+
if transformer_depth_middle >= 0:
|
304 |
+
mid_block += [SpatialTransformer( # always uses a self-attn
|
305 |
+
ch, num_heads, dim_head, depth=transformer_depth_middle, context_dim=context_dim,
|
306 |
+
disable_self_attn=disable_middle_self_attn, use_linear=use_linear_in_transformer,
|
307 |
+
use_checkpoint=use_checkpoint, attn_precision=attn_precision, dtype=self.dtype, device=device, operations=operations
|
308 |
+
),
|
309 |
+
ResBlock(
|
310 |
+
ch,
|
311 |
+
time_embed_dim,
|
312 |
+
dropout,
|
313 |
+
dims=dims,
|
314 |
+
use_checkpoint=use_checkpoint,
|
315 |
+
use_scale_shift_norm=use_scale_shift_norm,
|
316 |
+
dtype=self.dtype,
|
317 |
+
device=device,
|
318 |
+
operations=operations
|
319 |
+
)]
|
320 |
+
self.middle_block = TimestepEmbedSequential(*mid_block)
|
321 |
+
self.middle_block_out = self.make_zero_conv(ch, operations=operations, dtype=self.dtype, device=device)
|
322 |
+
self._feature_size += ch
|
323 |
+
|
324 |
+
if union_controlnet_num_control_type is not None:
|
325 |
+
self.num_control_type = union_controlnet_num_control_type
|
326 |
+
num_trans_channel = 320
|
327 |
+
num_trans_head = 8
|
328 |
+
num_trans_layer = 1
|
329 |
+
num_proj_channel = 320
|
330 |
+
# task_scale_factor = num_trans_channel ** 0.5
|
331 |
+
self.task_embedding = nn.Parameter(torch.empty(self.num_control_type, num_trans_channel, dtype=self.dtype, device=device))
|
332 |
+
|
333 |
+
self.transformer_layes = nn.Sequential(*[ResBlockUnionControlnet(num_trans_channel, num_trans_head, dtype=self.dtype, device=device, operations=operations) for _ in range(num_trans_layer)])
|
334 |
+
self.spatial_ch_projs = operations.Linear(num_trans_channel, num_proj_channel, dtype=self.dtype, device=device)
|
335 |
+
#-----------------------------------------------------------------------------------------------------
|
336 |
+
|
337 |
+
control_add_embed_dim = 256
|
338 |
+
class ControlAddEmbedding(nn.Module):
|
339 |
+
def __init__(self, in_dim, out_dim, num_control_type, dtype=None, device=None, operations=None):
|
340 |
+
super().__init__()
|
341 |
+
self.num_control_type = num_control_type
|
342 |
+
self.in_dim = in_dim
|
343 |
+
self.linear_1 = operations.Linear(in_dim * num_control_type, out_dim, dtype=dtype, device=device)
|
344 |
+
self.linear_2 = operations.Linear(out_dim, out_dim, dtype=dtype, device=device)
|
345 |
+
def forward(self, control_type, dtype, device):
|
346 |
+
c_type = torch.zeros((self.num_control_type,), device=device)
|
347 |
+
c_type[control_type] = 1.0
|
348 |
+
c_type = timestep_embedding(c_type.flatten(), self.in_dim, repeat_only=False).to(dtype).reshape((-1, self.num_control_type * self.in_dim))
|
349 |
+
return self.linear_2(torch.nn.functional.silu(self.linear_1(c_type)))
|
350 |
+
|
351 |
+
self.control_add_embedding = ControlAddEmbedding(control_add_embed_dim, time_embed_dim, self.num_control_type, dtype=self.dtype, device=device, operations=operations)
|
352 |
+
else:
|
353 |
+
self.task_embedding = None
|
354 |
+
self.control_add_embedding = None
|
355 |
+
|
356 |
+
def union_controlnet_merge(self, hint, control_type, emb, context):
|
357 |
+
# Equivalent to: https://github.com/xinsir6/ControlNetPlus/tree/main
|
358 |
+
inputs = []
|
359 |
+
condition_list = []
|
360 |
+
|
361 |
+
for idx in range(min(1, len(control_type))):
|
362 |
+
controlnet_cond = self.input_hint_block(hint[idx], emb, context)
|
363 |
+
feat_seq = torch.mean(controlnet_cond, dim=(2, 3))
|
364 |
+
if idx < len(control_type):
|
365 |
+
feat_seq += self.task_embedding[control_type[idx]].to(dtype=feat_seq.dtype, device=feat_seq.device)
|
366 |
+
|
367 |
+
inputs.append(feat_seq.unsqueeze(1))
|
368 |
+
condition_list.append(controlnet_cond)
|
369 |
+
|
370 |
+
x = torch.cat(inputs, dim=1)
|
371 |
+
x = self.transformer_layes(x)
|
372 |
+
controlnet_cond_fuser = None
|
373 |
+
for idx in range(len(control_type)):
|
374 |
+
alpha = self.spatial_ch_projs(x[:, idx])
|
375 |
+
alpha = alpha.unsqueeze(-1).unsqueeze(-1)
|
376 |
+
o = condition_list[idx] + alpha
|
377 |
+
if controlnet_cond_fuser is None:
|
378 |
+
controlnet_cond_fuser = o
|
379 |
+
else:
|
380 |
+
controlnet_cond_fuser += o
|
381 |
+
return controlnet_cond_fuser
|
382 |
+
|
383 |
+
def make_zero_conv(self, channels, operations=None, dtype=None, device=None):
|
384 |
+
return TimestepEmbedSequential(operations.conv_nd(self.dims, channels, channels, 1, padding=0, dtype=dtype, device=device))
|
385 |
+
|
386 |
+
def forward(self, x, hint, timesteps, context, y=None, **kwargs):
|
387 |
+
t_emb = timestep_embedding(timesteps, self.model_channels, repeat_only=False).to(x.dtype)
|
388 |
+
emb = self.time_embed(t_emb)
|
389 |
+
|
390 |
+
guided_hint = None
|
391 |
+
if self.control_add_embedding is not None: #Union Controlnet
|
392 |
+
control_type = kwargs.get("control_type", [])
|
393 |
+
|
394 |
+
if any([c >= self.num_control_type for c in control_type]):
|
395 |
+
max_type = max(control_type)
|
396 |
+
max_type_name = {
|
397 |
+
v: k for k, v in UNION_CONTROLNET_TYPES.items()
|
398 |
+
}[max_type]
|
399 |
+
raise ValueError(
|
400 |
+
f"Control type {max_type_name}({max_type}) is out of range for the number of control types" +
|
401 |
+
f"({self.num_control_type}) supported.\n" +
|
402 |
+
"Please consider using the ProMax ControlNet Union model.\n" +
|
403 |
+
"https://huggingface.co/xinsir/controlnet-union-sdxl-1.0/tree/main"
|
404 |
+
)
|
405 |
+
|
406 |
+
emb += self.control_add_embedding(control_type, emb.dtype, emb.device)
|
407 |
+
if len(control_type) > 0:
|
408 |
+
if len(hint.shape) < 5:
|
409 |
+
hint = hint.unsqueeze(dim=0)
|
410 |
+
guided_hint = self.union_controlnet_merge(hint, control_type, emb, context)
|
411 |
+
|
412 |
+
if guided_hint is None:
|
413 |
+
guided_hint = self.input_hint_block(hint, emb, context)
|
414 |
+
|
415 |
+
out_output = []
|
416 |
+
out_middle = []
|
417 |
+
|
418 |
+
hs = []
|
419 |
+
if self.num_classes is not None:
|
420 |
+
assert y.shape[0] == x.shape[0]
|
421 |
+
emb = emb + self.label_emb(y)
|
422 |
+
|
423 |
+
h = x
|
424 |
+
for module, zero_conv in zip(self.input_blocks, self.zero_convs):
|
425 |
+
if guided_hint is not None:
|
426 |
+
h = module(h, emb, context)
|
427 |
+
h += guided_hint
|
428 |
+
guided_hint = None
|
429 |
+
else:
|
430 |
+
h = module(h, emb, context)
|
431 |
+
out_output.append(zero_conv(h, emb, context))
|
432 |
+
|
433 |
+
h = self.middle_block(h, emb, context)
|
434 |
+
out_middle.append(self.middle_block_out(h, emb, context))
|
435 |
+
|
436 |
+
return {"middle": out_middle, "output": out_output}
|
437 |
+
|
comfy/cldm/control_types.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
UNION_CONTROLNET_TYPES = {
|
2 |
+
"openpose": 0,
|
3 |
+
"depth": 1,
|
4 |
+
"hed/pidi/scribble/ted": 2,
|
5 |
+
"canny/lineart/anime_lineart/mlsd": 3,
|
6 |
+
"normal": 4,
|
7 |
+
"segment": 5,
|
8 |
+
"tile": 6,
|
9 |
+
"repaint": 7,
|
10 |
+
}
|
comfy/cldm/dit_embedder.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
from typing import List, Optional, Tuple
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
from einops import rearrange
|
8 |
+
from torch import Tensor
|
9 |
+
|
10 |
+
from comfy.ldm.modules.diffusionmodules.mmdit import DismantledBlock, PatchEmbed, VectorEmbedder, TimestepEmbedder, get_2d_sincos_pos_embed_torch
|
11 |
+
|
12 |
+
|
13 |
+
class ControlNetEmbedder(nn.Module):
|
14 |
+
|
15 |
+
def __init__(
|
16 |
+
self,
|
17 |
+
img_size: int,
|
18 |
+
patch_size: int,
|
19 |
+
in_chans: int,
|
20 |
+
attention_head_dim: int,
|
21 |
+
num_attention_heads: int,
|
22 |
+
adm_in_channels: int,
|
23 |
+
num_layers: int,
|
24 |
+
main_model_double: int,
|
25 |
+
double_y_emb: bool,
|
26 |
+
device: torch.device,
|
27 |
+
dtype: torch.dtype,
|
28 |
+
pos_embed_max_size: Optional[int] = None,
|
29 |
+
operations = None,
|
30 |
+
):
|
31 |
+
super().__init__()
|
32 |
+
self.main_model_double = main_model_double
|
33 |
+
self.dtype = dtype
|
34 |
+
self.hidden_size = num_attention_heads * attention_head_dim
|
35 |
+
self.patch_size = patch_size
|
36 |
+
self.x_embedder = PatchEmbed(
|
37 |
+
img_size=img_size,
|
38 |
+
patch_size=patch_size,
|
39 |
+
in_chans=in_chans,
|
40 |
+
embed_dim=self.hidden_size,
|
41 |
+
strict_img_size=pos_embed_max_size is None,
|
42 |
+
device=device,
|
43 |
+
dtype=dtype,
|
44 |
+
operations=operations,
|
45 |
+
)
|
46 |
+
|
47 |
+
self.t_embedder = TimestepEmbedder(self.hidden_size, dtype=dtype, device=device, operations=operations)
|
48 |
+
|
49 |
+
self.double_y_emb = double_y_emb
|
50 |
+
if self.double_y_emb:
|
51 |
+
self.orig_y_embedder = VectorEmbedder(
|
52 |
+
adm_in_channels, self.hidden_size, dtype, device, operations=operations
|
53 |
+
)
|
54 |
+
self.y_embedder = VectorEmbedder(
|
55 |
+
self.hidden_size, self.hidden_size, dtype, device, operations=operations
|
56 |
+
)
|
57 |
+
else:
|
58 |
+
self.y_embedder = VectorEmbedder(
|
59 |
+
adm_in_channels, self.hidden_size, dtype, device, operations=operations
|
60 |
+
)
|
61 |
+
|
62 |
+
self.transformer_blocks = nn.ModuleList(
|
63 |
+
DismantledBlock(
|
64 |
+
hidden_size=self.hidden_size, num_heads=num_attention_heads, qkv_bias=True,
|
65 |
+
dtype=dtype, device=device, operations=operations
|
66 |
+
)
|
67 |
+
for _ in range(num_layers)
|
68 |
+
)
|
69 |
+
|
70 |
+
# self.use_y_embedder = pooled_projection_dim != self.time_text_embed.text_embedder.linear_1.in_features
|
71 |
+
# TODO double check this logic when 8b
|
72 |
+
self.use_y_embedder = True
|
73 |
+
|
74 |
+
self.controlnet_blocks = nn.ModuleList([])
|
75 |
+
for _ in range(len(self.transformer_blocks)):
|
76 |
+
controlnet_block = operations.Linear(self.hidden_size, self.hidden_size, dtype=dtype, device=device)
|
77 |
+
self.controlnet_blocks.append(controlnet_block)
|
78 |
+
|
79 |
+
self.pos_embed_input = PatchEmbed(
|
80 |
+
img_size=img_size,
|
81 |
+
patch_size=patch_size,
|
82 |
+
in_chans=in_chans,
|
83 |
+
embed_dim=self.hidden_size,
|
84 |
+
strict_img_size=False,
|
85 |
+
device=device,
|
86 |
+
dtype=dtype,
|
87 |
+
operations=operations,
|
88 |
+
)
|
89 |
+
|
90 |
+
def forward(
|
91 |
+
self,
|
92 |
+
x: torch.Tensor,
|
93 |
+
timesteps: torch.Tensor,
|
94 |
+
y: Optional[torch.Tensor] = None,
|
95 |
+
context: Optional[torch.Tensor] = None,
|
96 |
+
hint = None,
|
97 |
+
) -> Tuple[Tensor, List[Tensor]]:
|
98 |
+
x_shape = list(x.shape)
|
99 |
+
x = self.x_embedder(x)
|
100 |
+
if not self.double_y_emb:
|
101 |
+
h = (x_shape[-2] + 1) // self.patch_size
|
102 |
+
w = (x_shape[-1] + 1) // self.patch_size
|
103 |
+
x += get_2d_sincos_pos_embed_torch(self.hidden_size, w, h, device=x.device)
|
104 |
+
c = self.t_embedder(timesteps, dtype=x.dtype)
|
105 |
+
if y is not None and self.y_embedder is not None:
|
106 |
+
if self.double_y_emb:
|
107 |
+
y = self.orig_y_embedder(y)
|
108 |
+
y = self.y_embedder(y)
|
109 |
+
c = c + y
|
110 |
+
|
111 |
+
x = x + self.pos_embed_input(hint)
|
112 |
+
|
113 |
+
block_out = ()
|
114 |
+
|
115 |
+
repeat = math.ceil(self.main_model_double / len(self.transformer_blocks))
|
116 |
+
for i in range(len(self.transformer_blocks)):
|
117 |
+
out = self.transformer_blocks[i](x, c)
|
118 |
+
if not self.double_y_emb:
|
119 |
+
x = out
|
120 |
+
block_out += (self.controlnet_blocks[i](out),) * repeat
|
121 |
+
|
122 |
+
return {"output": block_out}
|
comfy/cldm/mmdit.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from typing import Dict, Optional
|
3 |
+
import comfy.ldm.modules.diffusionmodules.mmdit
|
4 |
+
|
5 |
+
class ControlNet(comfy.ldm.modules.diffusionmodules.mmdit.MMDiT):
|
6 |
+
def __init__(
|
7 |
+
self,
|
8 |
+
num_blocks = None,
|
9 |
+
control_latent_channels = None,
|
10 |
+
dtype = None,
|
11 |
+
device = None,
|
12 |
+
operations = None,
|
13 |
+
**kwargs,
|
14 |
+
):
|
15 |
+
super().__init__(dtype=dtype, device=device, operations=operations, final_layer=False, num_blocks=num_blocks, **kwargs)
|
16 |
+
# controlnet_blocks
|
17 |
+
self.controlnet_blocks = torch.nn.ModuleList([])
|
18 |
+
for _ in range(len(self.joint_blocks)):
|
19 |
+
self.controlnet_blocks.append(operations.Linear(self.hidden_size, self.hidden_size, device=device, dtype=dtype))
|
20 |
+
|
21 |
+
if control_latent_channels is None:
|
22 |
+
control_latent_channels = self.in_channels
|
23 |
+
|
24 |
+
self.pos_embed_input = comfy.ldm.modules.diffusionmodules.mmdit.PatchEmbed(
|
25 |
+
None,
|
26 |
+
self.patch_size,
|
27 |
+
control_latent_channels,
|
28 |
+
self.hidden_size,
|
29 |
+
bias=True,
|
30 |
+
strict_img_size=False,
|
31 |
+
dtype=dtype,
|
32 |
+
device=device,
|
33 |
+
operations=operations
|
34 |
+
)
|
35 |
+
|
36 |
+
def forward(
|
37 |
+
self,
|
38 |
+
x: torch.Tensor,
|
39 |
+
timesteps: torch.Tensor,
|
40 |
+
y: Optional[torch.Tensor] = None,
|
41 |
+
context: Optional[torch.Tensor] = None,
|
42 |
+
hint = None,
|
43 |
+
) -> torch.Tensor:
|
44 |
+
|
45 |
+
#weird sd3 controlnet specific stuff
|
46 |
+
y = torch.zeros_like(y)
|
47 |
+
|
48 |
+
if self.context_processor is not None:
|
49 |
+
context = self.context_processor(context)
|
50 |
+
|
51 |
+
hw = x.shape[-2:]
|
52 |
+
x = self.x_embedder(x) + self.cropped_pos_embed(hw, device=x.device).to(dtype=x.dtype, device=x.device)
|
53 |
+
x += self.pos_embed_input(hint)
|
54 |
+
|
55 |
+
c = self.t_embedder(timesteps, dtype=x.dtype)
|
56 |
+
if y is not None and self.y_embedder is not None:
|
57 |
+
y = self.y_embedder(y)
|
58 |
+
c = c + y
|
59 |
+
|
60 |
+
if context is not None:
|
61 |
+
context = self.context_embedder(context)
|
62 |
+
|
63 |
+
output = []
|
64 |
+
|
65 |
+
blocks = len(self.joint_blocks)
|
66 |
+
for i in range(blocks):
|
67 |
+
context, x = self.joint_blocks[i](
|
68 |
+
context,
|
69 |
+
x,
|
70 |
+
c=c,
|
71 |
+
use_checkpoint=self.use_checkpoint,
|
72 |
+
)
|
73 |
+
|
74 |
+
out = self.controlnet_blocks[i](x)
|
75 |
+
count = self.depth // blocks
|
76 |
+
if i == blocks - 1:
|
77 |
+
count -= 1
|
78 |
+
for j in range(count):
|
79 |
+
output.append(out)
|
80 |
+
|
81 |
+
return {"output": output}
|
comfy/cli_args.py
ADDED
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import enum
|
3 |
+
import os
|
4 |
+
from typing import Optional
|
5 |
+
import comfy.options
|
6 |
+
|
7 |
+
|
8 |
+
class EnumAction(argparse.Action):
|
9 |
+
"""
|
10 |
+
Argparse action for handling Enums
|
11 |
+
"""
|
12 |
+
def __init__(self, **kwargs):
|
13 |
+
# Pop off the type value
|
14 |
+
enum_type = kwargs.pop("type", None)
|
15 |
+
|
16 |
+
# Ensure an Enum subclass is provided
|
17 |
+
if enum_type is None:
|
18 |
+
raise ValueError("type must be assigned an Enum when using EnumAction")
|
19 |
+
if not issubclass(enum_type, enum.Enum):
|
20 |
+
raise TypeError("type must be an Enum when using EnumAction")
|
21 |
+
|
22 |
+
# Generate choices from the Enum
|
23 |
+
choices = tuple(e.value for e in enum_type)
|
24 |
+
kwargs.setdefault("choices", choices)
|
25 |
+
kwargs.setdefault("metavar", f"[{','.join(list(choices))}]")
|
26 |
+
|
27 |
+
super(EnumAction, self).__init__(**kwargs)
|
28 |
+
|
29 |
+
self._enum = enum_type
|
30 |
+
|
31 |
+
def __call__(self, parser, namespace, values, option_string=None):
|
32 |
+
# Convert value back into an Enum
|
33 |
+
value = self._enum(values)
|
34 |
+
setattr(namespace, self.dest, value)
|
35 |
+
|
36 |
+
|
37 |
+
parser = argparse.ArgumentParser()
|
38 |
+
|
39 |
+
parser.add_argument("--listen", type=str, default="127.0.0.1", metavar="IP", nargs="?", const="0.0.0.0,::", help="Specify the IP address to listen on (default: 127.0.0.1). You can give a list of ip addresses by separating them with a comma like: 127.2.2.2,127.3.3.3 If --listen is provided without an argument, it defaults to 0.0.0.0,:: (listens on all ipv4 and ipv6)")
|
40 |
+
parser.add_argument("--port", type=int, default=8188, help="Set the listen port.")
|
41 |
+
parser.add_argument("--tls-keyfile", type=str, help="Path to TLS (SSL) key file. Enables TLS, makes app accessible at https://... requires --tls-certfile to function")
|
42 |
+
parser.add_argument("--tls-certfile", type=str, help="Path to TLS (SSL) certificate file. Enables TLS, makes app accessible at https://... requires --tls-keyfile to function")
|
43 |
+
parser.add_argument("--enable-cors-header", type=str, default=None, metavar="ORIGIN", nargs="?", const="*", help="Enable CORS (Cross-Origin Resource Sharing) with optional origin or allow all with default '*'.")
|
44 |
+
parser.add_argument("--max-upload-size", type=float, default=100, help="Set the maximum upload size in MB.")
|
45 |
+
|
46 |
+
parser.add_argument("--extra-model-paths-config", type=str, default=None, metavar="PATH", nargs='+', action='append', help="Load one or more extra_model_paths.yaml files.")
|
47 |
+
parser.add_argument("--output-directory", type=str, default=None, help="Set the ComfyUI output directory.")
|
48 |
+
parser.add_argument("--temp-directory", type=str, default=None, help="Set the ComfyUI temp directory (default is in the ComfyUI directory).")
|
49 |
+
parser.add_argument("--input-directory", type=str, default=None, help="Set the ComfyUI input directory.")
|
50 |
+
parser.add_argument("--auto-launch", action="store_true", help="Automatically launch ComfyUI in the default browser.")
|
51 |
+
parser.add_argument("--disable-auto-launch", action="store_true", help="Disable auto launching the browser.")
|
52 |
+
parser.add_argument("--cuda-device", type=int, default=None, metavar="DEVICE_ID", help="Set the id of the cuda device this instance will use.")
|
53 |
+
cm_group = parser.add_mutually_exclusive_group()
|
54 |
+
cm_group.add_argument("--cuda-malloc", action="store_true", help="Enable cudaMallocAsync (enabled by default for torch 2.0 and up).")
|
55 |
+
cm_group.add_argument("--disable-cuda-malloc", action="store_true", help="Disable cudaMallocAsync.")
|
56 |
+
|
57 |
+
|
58 |
+
fp_group = parser.add_mutually_exclusive_group()
|
59 |
+
fp_group.add_argument("--force-fp32", action="store_true", help="Force fp32 (If this makes your GPU work better please report it).")
|
60 |
+
fp_group.add_argument("--force-fp16", action="store_true", help="Force fp16.")
|
61 |
+
|
62 |
+
fpunet_group = parser.add_mutually_exclusive_group()
|
63 |
+
fpunet_group.add_argument("--fp32-unet", action="store_true", help="Run the diffusion model in fp32.")
|
64 |
+
fpunet_group.add_argument("--fp64-unet", action="store_true", help="Run the diffusion model in fp64.")
|
65 |
+
fpunet_group.add_argument("--bf16-unet", action="store_true", help="Run the diffusion model in bf16.")
|
66 |
+
fpunet_group.add_argument("--fp16-unet", action="store_true", help="Run the diffusion model in fp16")
|
67 |
+
fpunet_group.add_argument("--fp8_e4m3fn-unet", action="store_true", help="Store unet weights in fp8_e4m3fn.")
|
68 |
+
fpunet_group.add_argument("--fp8_e5m2-unet", action="store_true", help="Store unet weights in fp8_e5m2.")
|
69 |
+
|
70 |
+
fpvae_group = parser.add_mutually_exclusive_group()
|
71 |
+
fpvae_group.add_argument("--fp16-vae", action="store_true", help="Run the VAE in fp16, might cause black images.")
|
72 |
+
fpvae_group.add_argument("--fp32-vae", action="store_true", help="Run the VAE in full precision fp32.")
|
73 |
+
fpvae_group.add_argument("--bf16-vae", action="store_true", help="Run the VAE in bf16.")
|
74 |
+
|
75 |
+
parser.add_argument("--cpu-vae", action="store_true", help="Run the VAE on the CPU.")
|
76 |
+
|
77 |
+
fpte_group = parser.add_mutually_exclusive_group()
|
78 |
+
fpte_group.add_argument("--fp8_e4m3fn-text-enc", action="store_true", help="Store text encoder weights in fp8 (e4m3fn variant).")
|
79 |
+
fpte_group.add_argument("--fp8_e5m2-text-enc", action="store_true", help="Store text encoder weights in fp8 (e5m2 variant).")
|
80 |
+
fpte_group.add_argument("--fp16-text-enc", action="store_true", help="Store text encoder weights in fp16.")
|
81 |
+
fpte_group.add_argument("--fp32-text-enc", action="store_true", help="Store text encoder weights in fp32.")
|
82 |
+
|
83 |
+
parser.add_argument("--force-channels-last", action="store_true", help="Force channels last format when inferencing the models.")
|
84 |
+
|
85 |
+
parser.add_argument("--directml", type=int, nargs="?", metavar="DIRECTML_DEVICE", const=-1, help="Use torch-directml.")
|
86 |
+
|
87 |
+
parser.add_argument("--disable-ipex-optimize", action="store_true", help="Disables ipex.optimize when loading models with Intel GPUs.")
|
88 |
+
|
89 |
+
class LatentPreviewMethod(enum.Enum):
|
90 |
+
NoPreviews = "none"
|
91 |
+
Auto = "auto"
|
92 |
+
Latent2RGB = "latent2rgb"
|
93 |
+
TAESD = "taesd"
|
94 |
+
|
95 |
+
parser.add_argument("--preview-method", type=LatentPreviewMethod, default=LatentPreviewMethod.NoPreviews, help="Default preview method for sampler nodes.", action=EnumAction)
|
96 |
+
|
97 |
+
parser.add_argument("--preview-size", type=int, default=512, help="Sets the maximum preview size for sampler nodes.")
|
98 |
+
|
99 |
+
cache_group = parser.add_mutually_exclusive_group()
|
100 |
+
cache_group.add_argument("--cache-classic", action="store_true", help="Use the old style (aggressive) caching.")
|
101 |
+
cache_group.add_argument("--cache-lru", type=int, default=0, help="Use LRU caching with a maximum of N node results cached. May use more RAM/VRAM.")
|
102 |
+
|
103 |
+
attn_group = parser.add_mutually_exclusive_group()
|
104 |
+
attn_group.add_argument("--use-split-cross-attention", action="store_true", help="Use the split cross attention optimization. Ignored when xformers is used.")
|
105 |
+
attn_group.add_argument("--use-quad-cross-attention", action="store_true", help="Use the sub-quadratic cross attention optimization . Ignored when xformers is used.")
|
106 |
+
attn_group.add_argument("--use-pytorch-cross-attention", action="store_true", help="Use the new pytorch 2.0 cross attention function.")
|
107 |
+
|
108 |
+
parser.add_argument("--disable-xformers", action="store_true", help="Disable xformers.")
|
109 |
+
|
110 |
+
upcast = parser.add_mutually_exclusive_group()
|
111 |
+
upcast.add_argument("--force-upcast-attention", action="store_true", help="Force enable attention upcasting, please report if it fixes black images.")
|
112 |
+
upcast.add_argument("--dont-upcast-attention", action="store_true", help="Disable all upcasting of attention. Should be unnecessary except for debugging.")
|
113 |
+
|
114 |
+
|
115 |
+
vram_group = parser.add_mutually_exclusive_group()
|
116 |
+
vram_group.add_argument("--gpu-only", action="store_true", help="Store and run everything (text encoders/CLIP models, etc... on the GPU).")
|
117 |
+
vram_group.add_argument("--highvram", action="store_true", help="By default models will be unloaded to CPU memory after being used. This option keeps them in GPU memory.")
|
118 |
+
vram_group.add_argument("--normalvram", action="store_true", help="Used to force normal vram use if lowvram gets automatically enabled.")
|
119 |
+
vram_group.add_argument("--lowvram", action="store_true", help="Split the unet in parts to use less vram.")
|
120 |
+
vram_group.add_argument("--novram", action="store_true", help="When lowvram isn't enough.")
|
121 |
+
vram_group.add_argument("--cpu", action="store_true", help="To use the CPU for everything (slow).")
|
122 |
+
|
123 |
+
parser.add_argument("--reserve-vram", type=float, default=None, help="Set the amount of vram in GB you want to reserve for use by your OS/other software. By default some amount is reverved depending on your OS.")
|
124 |
+
|
125 |
+
|
126 |
+
parser.add_argument("--default-hashing-function", type=str, choices=['md5', 'sha1', 'sha256', 'sha512'], default='sha256', help="Allows you to choose the hash function to use for duplicate filename / contents comparison. Default is sha256.")
|
127 |
+
|
128 |
+
parser.add_argument("--disable-smart-memory", action="store_true", help="Force ComfyUI to agressively offload to regular ram instead of keeping models in vram when it can.")
|
129 |
+
parser.add_argument("--deterministic", action="store_true", help="Make pytorch use slower deterministic algorithms when it can. Note that this might not make images deterministic in all cases.")
|
130 |
+
parser.add_argument("--fast", action="store_true", help="Enable some untested and potentially quality deteriorating optimizations.")
|
131 |
+
|
132 |
+
parser.add_argument("--dont-print-server", action="store_true", help="Don't print server output.")
|
133 |
+
parser.add_argument("--quick-test-for-ci", action="store_true", help="Quick test for CI.")
|
134 |
+
parser.add_argument("--windows-standalone-build", action="store_true", help="Windows standalone build: Enable convenient things that most people using the standalone windows build will probably enjoy (like auto opening the page on startup).")
|
135 |
+
|
136 |
+
parser.add_argument("--disable-metadata", action="store_true", help="Disable saving prompt metadata in files.")
|
137 |
+
parser.add_argument("--disable-all-custom-nodes", action="store_true", help="Disable loading all custom nodes.")
|
138 |
+
|
139 |
+
parser.add_argument("--multi-user", action="store_true", help="Enables per-user storage.")
|
140 |
+
|
141 |
+
parser.add_argument("--verbose", default='INFO', const='DEBUG', nargs="?", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Set the logging level')
|
142 |
+
|
143 |
+
# The default built-in provider hosted under web/
|
144 |
+
DEFAULT_VERSION_STRING = "comfyanonymous/ComfyUI@latest"
|
145 |
+
|
146 |
+
parser.add_argument(
|
147 |
+
"--front-end-version",
|
148 |
+
type=str,
|
149 |
+
default=DEFAULT_VERSION_STRING,
|
150 |
+
help="""
|
151 |
+
Specifies the version of the frontend to be used. This command needs internet connectivity to query and
|
152 |
+
download available frontend implementations from GitHub releases.
|
153 |
+
|
154 |
+
The version string should be in the format of:
|
155 |
+
[repoOwner]/[repoName]@[version]
|
156 |
+
where version is one of: "latest" or a valid version number (e.g. "1.0.0")
|
157 |
+
""",
|
158 |
+
)
|
159 |
+
|
160 |
+
def is_valid_directory(path: Optional[str]) -> Optional[str]:
|
161 |
+
"""Validate if the given path is a directory."""
|
162 |
+
if path is None:
|
163 |
+
return None
|
164 |
+
|
165 |
+
if not os.path.isdir(path):
|
166 |
+
raise argparse.ArgumentTypeError(f"{path} is not a valid directory.")
|
167 |
+
return path
|
168 |
+
|
169 |
+
parser.add_argument(
|
170 |
+
"--front-end-root",
|
171 |
+
type=is_valid_directory,
|
172 |
+
default=None,
|
173 |
+
help="The local filesystem path to the directory where the frontend is located. Overrides --front-end-version.",
|
174 |
+
)
|
175 |
+
|
176 |
+
parser.add_argument("--user-directory", type=is_valid_directory, default=None, help="Set the ComfyUI user directory with an absolute path.")
|
177 |
+
|
178 |
+
if comfy.options.args_parsing:
|
179 |
+
args = parser.parse_args()
|
180 |
+
else:
|
181 |
+
args = parser.parse_args([])
|
182 |
+
|
183 |
+
if args.windows_standalone_build:
|
184 |
+
args.auto_launch = True
|
185 |
+
|
186 |
+
if args.disable_auto_launch:
|
187 |
+
args.auto_launch = False
|