eichellis commited on
Commit
b68e587
·
1 Parent(s): 42ccab6

Upload 331 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/bug_report.yaml +53 -0
  2. TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/feature_request.yaml +24 -0
  3. TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/question.yaml +10 -0
  4. TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/workflows/stale.yml +13 -0
  5. TestingforfaivsixEx/content/eichellis/extensions/adetai/.gitignore +196 -0
  6. TestingforfaivsixEx/content/eichellis/extensions/adetai/.pre-commit-config.yaml +19 -0
  7. TestingforfaivsixEx/content/eichellis/extensions/adetai/.vscode/extensions.json +8 -0
  8. TestingforfaivsixEx/content/eichellis/extensions/adetai/.vscode/settings.json +8 -0
  9. TestingforfaivsixEx/content/eichellis/extensions/adetai/CHANGELOG.md +309 -0
  10. TestingforfaivsixEx/content/eichellis/extensions/adetai/LICENSE.md +662 -0
  11. TestingforfaivsixEx/content/eichellis/extensions/adetai/README.md +94 -0
  12. TestingforfaivsixEx/content/eichellis/extensions/adetai/Taskfile.yml +27 -0
  13. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/__init__.py +20 -0
  14. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/__version__.py +1 -0
  15. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/args.py +251 -0
  16. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/common.py +127 -0
  17. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/mask.py +255 -0
  18. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/mediapipe.py +179 -0
  19. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/traceback.py +161 -0
  20. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/ui.py +605 -0
  21. TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/ultralytics.py +50 -0
  22. TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/__init__.py +7 -0
  23. TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/controlnet_ext.py +140 -0
  24. TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/restore.py +43 -0
  25. TestingforfaivsixEx/content/eichellis/extensions/adetai/install.py +76 -0
  26. TestingforfaivsixEx/content/eichellis/extensions/adetai/preload.py +9 -0
  27. TestingforfaivsixEx/content/eichellis/extensions/adetai/pyproject.toml +40 -0
  28. TestingforfaivsixEx/content/eichellis/extensions/adetai/scripts/!adetailer.py +834 -0
  29. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.github/workflows/pytest.yml +31 -0
  30. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.gitignore +2 -0
  31. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.pre-commit-config.yaml +35 -0
  32. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/README.md +91 -0
  33. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_components.py +360 -0
  34. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_constants.py +27 -0
  35. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_settings.py +178 -0
  36. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_util.py +119 -0
  37. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/main.py +72 -0
  38. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/docs/opts.png +0 -0
  39. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/docs/ui.png +0 -0
  40. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/javascript/aspectRatioController.js +474 -0
  41. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/scripts/sd_webui_aspect_ratio_helper.py +5 -0
  42. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/style.css +36 -0
  43. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tests/__init__.py +0 -0
  44. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tests/_util_test.py +291 -0
  45. TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tox.ini +6 -0
  46. TestingforfaivsixEx/content/eichellis/extensions/batch-link/.github/CODEOWNERS +2 -0
  47. TestingforfaivsixEx/content/eichellis/extensions/batch-link/.gitignore +168 -0
  48. TestingforfaivsixEx/content/eichellis/extensions/batch-link/LICENSE +21 -0
  49. TestingforfaivsixEx/content/eichellis/extensions/batch-link/README.md +491 -0
  50. TestingforfaivsixEx/content/eichellis/extensions/batch-link/howtogetthedirectlinks.md +104 -0
TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/bug_report.yaml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Bug report
2
+ description: Create a report
3
+ title: "[Bug]: "
4
+ labels:
5
+ - bug
6
+
7
+ body:
8
+ - type: textarea
9
+ attributes:
10
+ label: Describe the bug
11
+ description: A clear and concise description of what the bug is.
12
+ placeholder: |
13
+ Any language accepted
14
+ 아무 언어 사용가능
15
+ すべての言語に対応
16
+ 接受所有语言
17
+ Se aceptan todos los idiomas
18
+ Alle Sprachen werden akzeptiert
19
+ Toutes les langues sont acceptées
20
+ Принимаются все языки
21
+
22
+ - type: textarea
23
+ attributes:
24
+ label: Screenshots
25
+ description: Screenshots related to the issue.
26
+
27
+ - type: textarea
28
+ attributes:
29
+ label: Console logs, from start to end.
30
+ description: |
31
+ The full console log of your terminal.
32
+ placeholder: |
33
+ Python ...
34
+ Version: ...
35
+ Commit hash: ...
36
+ Installing requirements
37
+ ...
38
+
39
+ Launching Web UI with arguments: ...
40
+ [-] ADetailer initialized. version: ...
41
+ ...
42
+ ...
43
+
44
+ Traceback (most recent call last):
45
+ ...
46
+ ...
47
+ render: Shell
48
+ validations:
49
+ required: true
50
+
51
+ - type: textarea
52
+ attributes:
53
+ label: List of installed extensions
TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/feature_request.yaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Feature request
2
+ description: Suggest an idea for this project
3
+ title: "[Feature Request]: "
4
+
5
+ body:
6
+ - type: textarea
7
+ attributes:
8
+ label: Is your feature request related to a problem? Please describe.
9
+ description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
10
+
11
+ - type: textarea
12
+ attributes:
13
+ label: Describe the solution you'd like
14
+ description: A clear and concise description of what you want to happen.
15
+
16
+ - type: textarea
17
+ attributes:
18
+ label: Describe alternatives you've considered
19
+ description: A clear and concise description of any alternative solutions or features you've considered.
20
+
21
+ - type: textarea
22
+ attributes:
23
+ label: Additional context
24
+ description: Add any other context or screenshots about the feature request here.
TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/ISSUE_TEMPLATE/question.yaml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Question
2
+ description: Write a question
3
+ labels:
4
+ - question
5
+
6
+ body:
7
+ - type: textarea
8
+ attributes:
9
+ label: Question
10
+ description: Please do not write bug reports or feature requests here.
TestingforfaivsixEx/content/eichellis/extensions/adetai/.github/workflows/stale.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: 'Close stale issues and PRs'
2
+ on:
3
+ schedule:
4
+ - cron: '30 1 * * *'
5
+
6
+ jobs:
7
+ stale:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/stale@v8
11
+ with:
12
+ days-before-stale: 23
13
+ days-before-close: 3
TestingforfaivsixEx/content/eichellis/extensions/adetai/.gitignore ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
2
+ # Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode
3
+
4
+ ### Python ###
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ # For a library or package, you might want to ignore these files since the code is
91
+ # intended to run in multiple environments; otherwise, check them in:
92
+ # .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # poetry
102
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
104
+ # commonly ignored for libraries.
105
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106
+ #poetry.lock
107
+
108
+ # pdm
109
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110
+ #pdm.lock
111
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112
+ # in version control.
113
+ # https://pdm.fming.dev/#use-with-ide
114
+ .pdm.toml
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
165
+
166
+ ### Python Patch ###
167
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
168
+ poetry.toml
169
+
170
+ # ruff
171
+ .ruff_cache/
172
+
173
+ # LSP config files
174
+ pyrightconfig.json
175
+
176
+ ### VisualStudioCode ###
177
+ .vscode/*
178
+ !.vscode/settings.json
179
+ !.vscode/tasks.json
180
+ !.vscode/launch.json
181
+ !.vscode/extensions.json
182
+ !.vscode/*.code-snippets
183
+
184
+ # Local History for Visual Studio Code
185
+ .history/
186
+
187
+ # Built Visual Studio Code Extensions
188
+ *.vsix
189
+
190
+ ### VisualStudioCode Patch ###
191
+ # Ignore all local history of files
192
+ .history
193
+ .ionide
194
+
195
+ # End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
196
+ *.ipynb
TestingforfaivsixEx/content/eichellis/extensions/adetai/.pre-commit-config.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.4.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ args: [--markdown-linebreak-ext=md]
7
+ - id: end-of-file-fixer
8
+ - id: mixed-line-ending
9
+
10
+ - repo: https://github.com/astral-sh/ruff-pre-commit
11
+ rev: "v0.0.287"
12
+ hooks:
13
+ - id: ruff
14
+ args: [--fix, --exit-non-zero-on-fix]
15
+
16
+ - repo: https://github.com/psf/black-pre-commit-mirror
17
+ rev: 23.9.0
18
+ hooks:
19
+ - id: black
TestingforfaivsixEx/content/eichellis/extensions/adetai/.vscode/extensions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "recommendations": [
3
+ "ms-python.black-formatter",
4
+ "kevinrose.vsc-python-indent",
5
+ "charliermarsh.ruff",
6
+ "shardulm94.trailing-spaces"
7
+ ]
8
+ }
TestingforfaivsixEx/content/eichellis/extensions/adetai/.vscode/settings.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "explorer.fileNesting.enabled": true,
3
+ "explorer.fileNesting.patterns": {
4
+ "pyproject.toml": ".env, .gitignore, .pre-commit-config.yaml, Taskfile.yml",
5
+ "README.md": "LICENSE.md, CHANGELOG.md",
6
+ "install.py": "preload.py"
7
+ }
8
+ }
TestingforfaivsixEx/content/eichellis/extensions/adetai/CHANGELOG.md ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Changelog
2
+
3
+ ## 2023-09-10
4
+
5
+ - v23.9.2
6
+ - (실험적) VAE 선택 기능
7
+
8
+ ## 2023-09-01
9
+
10
+ - v23.9.1
11
+ - webui 1.6.0에 추가된 인자를 사용해서 생긴 하위 호환 문제 수정
12
+
13
+ ## 2023-08-31
14
+
15
+ - v23.9.0
16
+ - (실험적) 체크포인트 선택기능
17
+ - 버그가 있어 리프레시 버튼은 구현에서 빠짐
18
+ - 1.6.0 업데이트에 따라 img2img에서 사용불가능한 샘플러를 선택했을 때 더이상 Euler로 변경하지 않음
19
+ - 유효하지 않은 인자가 전달되었을 때, 에러를 일으키지 않고 대신 adetailer를 비활성화함
20
+
21
+
22
+ ## 2023-08-25
23
+
24
+ - v23.8.1
25
+ - xyz grid에서 model을 `None`으로 설정한 이후에 adetailer가 비활성화 되는 문제 수정
26
+ - skip을 눌렀을 때 진행을 멈춤
27
+ - `--medvram-sdxl`을 설정했을 때에도 cpu를 사용하게 함
28
+
29
+ ## 2023-08-14
30
+
31
+ - v23.8.0
32
+ - `[PROMPT]` 키워드 추가. `ad_prompt` 또는 `ad_negative_prompt`에 사용하면 입력 프롬프트로 대체됨 (PR #243)
33
+ - Only top k largest 옵션 추가 (PR #264)
34
+ - ultralytics 버전 업데이트
35
+
36
+
37
+ ## 2023-07-31
38
+
39
+ - v23.7.11
40
+ - separate clip skip 옵션 추가
41
+ - install requirements 정리 (ultralytics 새 버전, mediapipe~=3.20)
42
+
43
+ ## 2023-07-28
44
+
45
+ - v23.7.10
46
+ - ultralytics, mediapipe import문 정리
47
+ - traceback에서 컬러를 없앰 (api 때문), 라이브러리 버전도 보여주게 설정.
48
+ - huggingface_hub, pydantic을 install.py에서 없앰
49
+ - 안쓰는 컨트롤넷 관련 코드 삭제
50
+
51
+
52
+ ## 2023-07-23
53
+
54
+ - v23.7.9
55
+ - `ultralytics.utils` ModuleNotFoundError 해결 (https://github.com/ultralytics/ultralytics/issues/3856)
56
+ - `pydantic` 2.0 이상 버전 설치안되도록 함
57
+ - `controlnet_dir` cmd args 문제 수정 (PR #107)
58
+
59
+ ## 2023-07-20
60
+
61
+ - v23.7.8
62
+ - `paste_field_names` 추가했던 것을 되돌림
63
+
64
+ ## 2023-07-19
65
+
66
+ - v23.7.7
67
+ - 인페인팅 단계에서 별도의 샘플러를 선택할 수 있게 옵션을 추가함 (xyz그리드에도 추가)
68
+ - webui 1.0.0-pre 이하 버전에서 batch index 문제 수정
69
+ - 스크립트에 `paste_field_names`을 추가함. 사용되는지는 모르겠음
70
+
71
+ ## 2023-07-16
72
+
73
+ - v23.7.6
74
+ - `ultralytics 8.0.135`에 추가된 cpuinfo 기능을 위해 `py-cpuinfo`를 미리 설치하게 함. (미리 설치 안하면 cpu나 mps사용할 때 재시작해야함)
75
+ - init_image가 RGB 모드가 아닐 때 RGB로 변경.
76
+
77
+ ## 2023-07-07
78
+
79
+ - v23.7.4
80
+ - batch count > 1일때 프롬프트의 인덱스 문제 수정
81
+
82
+ - v23.7.5
83
+ - i2i의 `cached_uc`와 `cached_c`가 p의 `cached_uc`와 `cached_c`가 다른 인스턴스가 되도록 수정
84
+
85
+ ## 2023-07-05
86
+
87
+ - v23.7.3
88
+ - 버그 수정
89
+ - `object()`가 json 직렬화 안되는 문제
90
+ - `process`를 호출함에 따라 배치 카운트가 2이상일 때, all_prompts가 고정되는 문제
91
+ - `ad-before`와 `ad-preview` 이미지 파일명이 실제 파일명과 다른 문제
92
+ - pydantic 2.0 호환성 문제
93
+
94
+ ## 2023-07-04
95
+
96
+ - v23.7.2
97
+ - `mediapipe_face_mesh_eyes_only` 모델 추가: `mediapipe_face_mesh`로 감지한 뒤 눈만 사용함.
98
+ - 매 배치 시작 전에 `scripts.postprocess`를, 후에 `scripts.process`를 호출함.
99
+ - 컨트롤넷을 사용하면 소요 시간이 조금 늘어나지만 몇몇 문제 해결에 도움이 됨.
100
+ - `lora_block_weight`를 스크립트 화이트리스트에 추가함.
101
+ - 한번이라도 ADetailer를 사용한 사람은 수동으로 추가해야함.
102
+
103
+ ## 2023-07-03
104
+
105
+ - v23.7.1
106
+ - `process_images`를 진행한 뒤 `StableDiffusionProcessing` 오브젝트의 close를 호출함
107
+ - api 호출로 사용했는지 확인하는 속성 추가
108
+ - `NansException`이 발생했을 때 중지하지 않고 남은 과정 계속 진행함
109
+
110
+ ## 2023-07-02
111
+
112
+ - v23.7.0
113
+ - `NansException`이 발생하면 로그에 표시하고 원본 이미지를 반환하게 설정
114
+ - `rich`를 사용한 에러 트레이싱
115
+ - install.py에 `rich` 추가
116
+ - 생성 중에 컴포넌트의 값을 변경하면 args의 값도 함께 변경되는 문제 수정 (issue #180)
117
+ - 터미널 로그로 ad_prompt와 ad_negative_prompt에 적용된 실제 프롬프트 확인할 수 있음 (입력과 다를 경우에만)
118
+
119
+ ## 2023-06-28
120
+
121
+ - v23.6.4
122
+ - 최대 모델 수 5 -> 10개
123
+ - ad_prompt와 ad_negative_prompt에 빈칸으로 놔두면 입력 프롬프트가 사용된다는 문구 추가
124
+ - huggingface 모델 다운로드 실패시 로깅
125
+ - 1st 모델이 `None`일 경우 나머지 입력을 무시하던 문제 수정
126
+ - `--use-cpu` 에 `adetailer` 입력 시 cpu로 yolo모델을 사용함
127
+
128
+ ## 2023-06-20
129
+
130
+ - v23.6.3
131
+ - 컨트롤넷 inpaint 모델에 대해, 3가지 모듈을 사용할 수 있도록 함
132
+ - Noise Multiplier 옵션 추가 (PR #149)
133
+ - pydantic 최소 버전 1.10.8로 설정 (Issue #146)
134
+
135
+ ## 2023-06-05
136
+
137
+ - v23.6.2
138
+ - xyz_grid에서 ADetailer를 사용할 수 있게함.
139
+ - 8가지 옵션만 1st 탭에 적용되도록 함.
140
+
141
+ ## 2023-06-01
142
+
143
+ - v23.6.1
144
+ - `inpaint, scribble, lineart, openpose, tile` 5가지 컨트롤넷 모델 지원 (PR #107)
145
+ - controlnet guidance start, end 인자 추가 (PR #107)
146
+ - `modules.extensions`를 사용하여 컨트롤넷 확장을 불러오고 경로를 알아내로록 변경
147
+ - ui에서 컨트롤넷을 별도 함수로 분리
148
+
149
+ ## 2023-05-30
150
+
151
+ - v23.6.0
152
+ - 스크립트의 이름을 `After Detailer`에서 `ADetailer`로 변경
153
+ - API 사용자는 변경 필요함
154
+ - 몇몇 설정 변경
155
+ - `ad_conf` → `ad_confidence`. 0~100 사이의 int → 0.0~1.0 사이의 float
156
+ - `ad_inpaint_full_res` → `ad_inpaint_only_masked`
157
+ - `ad_inpaint_full_res_padding` → `ad_inpaint_only_masked_padding`
158
+ - mediapipe face mesh 모델 추가
159
+ - mediapipe 최소 버전 `0.10.0`
160
+
161
+ - rich traceback 제거함
162
+ - huggingface 다운로드 실패할 때 에러가 나지 않게 하고 해당 모델을 제거함
163
+
164
+ ## 2023-05-26
165
+
166
+ - v23.5.19
167
+ - 1번째 탭에도 `None` 옵션을 추가함
168
+ - api로 ad controlnet model에 inpaint가 아닌 다른 컨트롤넷 모델을 사용하지 못하도록 막음
169
+ - adetailer 진행중에 total tqdm 진행바 업데이트를 멈춤
170
+ - state.inturrupted 상태에서 adetailer 과정을 중지함
171
+ - 컨트롤넷 process를 각 batch가 끝난 순간에만 호출하도록 변경
172
+
173
+ ### 2023-05-25
174
+
175
+ - v23.5.18
176
+ - 컨트롤넷 관련 수정
177
+ - unit의 `input_mode`를 `SIMPLE`로 모두 변경
178
+ - 컨트롤넷 유넷 훅과 하이잭 함수들을 adetailer를 실행할 때에만 되돌리는 기능 추가
179
+ - adetailer 처리가 끝난 뒤 컨트롤넷 스크립트의 process를 다시 진행함. (batch count 2 이상일때의 문제 해결)
180
+ - 기본 활성 스크립트 목록에서 컨트롤넷을 뺌
181
+
182
+ ### 2023-05-22
183
+
184
+ - v23.5.17
185
+ - 컨트롤넷 확장이 있으면 컨트롤넷 스크립트를 활성화함. (컨트롤넷 관련 문제 해결)
186
+ - 모든 컴포넌트에 elem_id 설정
187
+ - ui에 버전을 표시함
188
+
189
+
190
+ ### 2023-05-19
191
+
192
+ - v23.5.16
193
+ - 추가한 옵션
194
+ - Mask min/max ratio
195
+ - Mask merge mode
196
+ - Restore faces after ADetailer
197
+ - 옵션들을 Accordion으로 묶음
198
+
199
+ ### 2023-05-18
200
+
201
+ - v23.5.15
202
+ - 필요한 것만 임포트하도록 변경 (vae 로딩 오류 없어짐. 로딩 속도 빨라짐)
203
+
204
+ ### 2023-05-17
205
+
206
+ - v23.5.14
207
+ - `[SKIP]`으로 ad prompt 일부를 건너뛰는 기능 추가
208
+ - bbox 정렬 옵션 추가
209
+ - sd_webui 타입힌트를 만들어냄
210
+ - enable checker와 관련된 api 오류 수정?
211
+
212
+ ### 2023-05-15
213
+
214
+ - v23.5.13
215
+ - `[SEP]`으로 ad prompt를 분리하여 적용하는 기능 추가
216
+ - enable checker를 다시 pydantic으로 변경함
217
+ - ui 관련 함수를 adetailer.ui 폴더로 분리함
218
+ - controlnet을 사용할 때 모든 controlnet unit 비활성화
219
+ - adetailer 폴더가 없으면 만들게 함
220
+
221
+ ### 2023-05-13
222
+
223
+ - v23.5.12
224
+ - `ad_enable`을 제외한 입력이 dict타입으로 들어오도록 변경
225
+ - web api로 사용할 때에 특히 사용하기 쉬움
226
+ - web api breaking change
227
+ - `mask_preprocess` 인자를 넣지 않았던 오류 수정 (PR #47)
228
+ - huggingface에서 모델을 다운로드하지 않는 옵션 추가 `--ad-no-huggingface`
229
+
230
+ ### 2023-05-12
231
+
232
+ - v23.5.11
233
+ - `ultralytics` 알람 제거
234
+ - 필요없는 exif 인자 더 제거함
235
+ - `use separate steps` 옵션 추가
236
+ - ui 배치를 조정함
237
+
238
+ ### 2023-05-09
239
+
240
+ - v23.5.10
241
+ - 선택한 스크립트만 ADetailer에 적용하는 옵션 추가, 기본값 `True`. 설정 탭에서 지정가능.
242
+ - 기본값: `dynamic_prompting,dynamic_thresholding,wildcards,wildcard_recursive`
243
+ - `person_yolov8s-seg.pt` 모델 추가
244
+ - `ultralytics`의 최소 버전을 `8.0.97`로 설정 (C:\\ 문제 해결된 버전)
245
+
246
+ ### 2023-05-08
247
+
248
+ - v23.5.9
249
+ - 2가지 이상의 모델을 사용할 수 있음. 기본값: 2, 최대: 5
250
+ - segment 모델을 사용할 수 있게 함. `person_yolov8n-seg.pt` 추가
251
+
252
+ ### 2023-05-07
253
+
254
+ - v23.5.8
255
+ - 프롬프트와 네거티브 프롬프트에 방향키 지원 (PR #24)
256
+ - `mask_preprocess`를 추가함. 이전 버전과 시드값이 달라질 가능성 있음!
257
+ - 이미지 처리가 일어났을 때에만 before이미지를 저장함
258
+ - 설정창의 레이블을 ADetailer 대신 더 적절하게 수정함
259
+
260
+ ### 2023-05-06
261
+
262
+ - v23.5.7
263
+ - `ad_use_cfg_scale` 옵션 추가. cfg 스케일을 따로 사용할지 말지 결정함.
264
+ - `ad_enable` 기본값을 `True`에서 `False`로 변경
265
+ - `ad_model`의 기본값을 `None`에서 첫번째 모델로 변경
266
+ - 최소 2개의 입력(ad_enable, ad_model)만 들어오면 작동하게 변경.
267
+
268
+ - v23.5.7.post0
269
+ - `init_controlnet_ext`을 controlnet_exists == True일때에만 실행
270
+ - webui를 C드라이브 바로 밑에 설치한 사람들에게 `ultralytics` 경고 표시
271
+
272
+ ### 2023-05-05 (어린이날)
273
+
274
+ - v23.5.5
275
+ - `Save images before ADetailer` 옵션 추가
276
+ - 입력으로 들어온 인자와 ALL_ARGS의 길이가 다르면 에러메세지
277
+ - README.md에 설치방법 추가
278
+
279
+ - v23.5.6
280
+ - get_args에서 IndexError가 발생하면 자세한 에러메세지를 볼 수 있음
281
+ - AdetailerArgs에 extra_params 내장
282
+ - scripts_args를 딥카피함
283
+ - postprocess_image를 약간 분리함
284
+
285
+ - v23.5.6.post0
286
+ - `init_controlnet_ext`에서 에러메세지를 자세히 볼 수 ��음
287
+
288
+ ### 2023-05-04
289
+
290
+ - v23.5.4
291
+ - use pydantic for arguments validation
292
+ - revert: ad_model to `None` as default
293
+ - revert: `__future__` imports
294
+ - lazily import yolo and mediapipe
295
+
296
+ ### 2023-05-03
297
+
298
+ - v23.5.3.post0
299
+ - remove `__future__` imports
300
+ - change to copy scripts and scripts args
301
+
302
+ - v23.5.3.post1
303
+ - change default ad_model from `None`
304
+
305
+ ### 2023-05-02
306
+
307
+ - v23.5.3
308
+ - Remove `None` from model list and add `Enable ADetailer` checkbox.
309
+ - install.py `skip_install` fix.
TestingforfaivsixEx/content/eichellis/extensions/adetai/LICENSE.md ADDED
@@ -0,0 +1,662 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ GNU AFFERO GENERAL PUBLIC LICENSE
3
+ Version 3, 19 November 2007
4
+
5
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The GNU Affero General Public License is a free, copyleft license for
12
+ software and other kinds of works, specifically designed to ensure
13
+ cooperation with the community in the case of network server software.
14
+
15
+ The licenses for most software and other practical works are designed
16
+ to take away your freedom to share and change the works. By contrast,
17
+ our General Public Licenses are intended to guarantee your freedom to
18
+ share and change all versions of a program--to make sure it remains free
19
+ software for all its users.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ them if you wish), that you receive source code or can get it if you
25
+ want it, that you can change the software or use pieces of it in new
26
+ free programs, and that you know you can do these things.
27
+
28
+ Developers that use our General Public Licenses protect your rights
29
+ with two steps: (1) assert copyright on the software, and (2) offer
30
+ you this License which gives you legal permission to copy, distribute
31
+ and/or modify the software.
32
+
33
+ A secondary benefit of defending all users' freedom is that
34
+ improvements made in alternate versions of the program, if they
35
+ receive widespread use, become available for other developers to
36
+ incorporate. Many developers of free software are heartened and
37
+ encouraged by the resulting cooperation. However, in the case of
38
+ software used on network servers, this result may fail to come about.
39
+ The GNU General Public License permits making a modified version and
40
+ letting the public access it on a server without ever releasing its
41
+ source code to the public.
42
+
43
+ The GNU Affero General Public License is designed specifically to
44
+ ensure that, in such cases, the modified source code becomes available
45
+ to the community. It requires the operator of a network server to
46
+ provide the source code of the modified version running there to the
47
+ users of that server. Therefore, public use of a modified version, on
48
+ a publicly accessible server, gives the public access to the source
49
+ code of the modified version.
50
+
51
+ An older license, called the Affero General Public License and
52
+ published by Affero, was designed to accomplish similar goals. This is
53
+ a different license, not a version of the Affero GPL, but Affero has
54
+ released a new version of the Affero GPL which permits relicensing under
55
+ this license.
56
+
57
+ The precise terms and conditions for copying, distribution and
58
+ modification follow.
59
+
60
+ TERMS AND CONDITIONS
61
+
62
+ 0. Definitions.
63
+
64
+ "This License" refers to version 3 of the GNU Affero General Public License.
65
+
66
+ "Copyright" also means copyright-like laws that apply to other kinds of
67
+ works, such as semiconductor masks.
68
+
69
+ "The Program" refers to any copyrightable work licensed under this
70
+ License. Each licensee is addressed as "you". "Licensees" and
71
+ "recipients" may be individuals or organizations.
72
+
73
+ To "modify" a work means to copy from or adapt all or part of the work
74
+ in a fashion requiring copyright permission, other than the making of an
75
+ exact copy. The resulting work is called a "modified version" of the
76
+ earlier work or a work "based on" the earlier work.
77
+
78
+ A "covered work" means either the unmodified Program or a work based
79
+ on the Program.
80
+
81
+ To "propagate" a work means to do anything with it that, without
82
+ permission, would make you directly or secondarily liable for
83
+ infringement under applicable copyright law, except executing it on a
84
+ computer or modifying a private copy. Propagation includes copying,
85
+ distribution (with or without modification), making available to the
86
+ public, and in some countries other activities as well.
87
+
88
+ To "convey" a work means any kind of propagation that enables other
89
+ parties to make or receive copies. Mere interaction with a user through
90
+ a computer network, with no transfer of a copy, is not conveying.
91
+
92
+ An interactive user interface displays "Appropriate Legal Notices"
93
+ to the extent that it includes a convenient and prominently visible
94
+ feature that (1) displays an appropriate copyright notice, and (2)
95
+ tells the user that there is no warranty for the work (except to the
96
+ extent that warranties are provided), that licensees may convey the
97
+ work under this License, and how to view a copy of this License. If
98
+ the interface presents a list of user commands or options, such as a
99
+ menu, a prominent item in the list meets this criterion.
100
+
101
+ 1. Source Code.
102
+
103
+ The "source code" for a work means the preferred form of the work
104
+ for making modifications to it. "Object code" means any non-source
105
+ form of a work.
106
+
107
+ A "Standard Interface" means an interface that either is an official
108
+ standard defined by a recognized standards body, or, in the case of
109
+ interfaces specified for a particular programming language, one that
110
+ is widely used among developers working in that language.
111
+
112
+ The "System Libraries" of an executable work include anything, other
113
+ than the work as a whole, that (a) is included in the normal form of
114
+ packaging a Major Component, but which is not part of that Major
115
+ Component, and (b) serves only to enable use of the work with that
116
+ Major Component, or to implement a Standard Interface for which an
117
+ implementation is available to the public in source code form. A
118
+ "Major Component", in this context, means a major essential component
119
+ (kernel, window system, and so on) of the specific operating system
120
+ (if any) on which the executable work runs, or a compiler used to
121
+ produce the work, or an object code interpreter used to run it.
122
+
123
+ The "Corresponding Source" for a work in object code form means all
124
+ the source code needed to generate, install, and (for an executable
125
+ work) run the object code and to modify the work, including scripts to
126
+ control those activities. However, it does not include the work's
127
+ System Libraries, or general-purpose tools or generally available free
128
+ programs which are used unmodified in performing those activities but
129
+ which are not part of the work. For example, Corresponding Source
130
+ includes interface definition files associated with source files for
131
+ the work, and the source code for shared libraries and dynamically
132
+ linked subprograms that the work is specifically designed to require,
133
+ such as by intimate data communication or control flow between those
134
+ subprograms and other parts of the work.
135
+
136
+ The Corresponding Source need not include anything that users
137
+ can regenerate automatically from other parts of the Corresponding
138
+ Source.
139
+
140
+ The Corresponding Source for a work in source code form is that
141
+ same work.
142
+
143
+ 2. Basic Permissions.
144
+
145
+ All rights granted under this License are granted for the term of
146
+ copyright on the Program, and are irrevocable provided the stated
147
+ conditions are met. This License explicitly affirms your unlimited
148
+ permission to run the unmodified Program. The output from running a
149
+ covered work is covered by this License only if the output, given its
150
+ content, constitutes a covered work. This License acknowledges your
151
+ rights of fair use or other equivalent, as provided by copyright law.
152
+
153
+ You may make, run and propagate covered works that you do not
154
+ convey, without conditions so long as your license otherwise remains
155
+ in force. You may convey covered works to others for the sole purpose
156
+ of having them make modifications exclusively for you, or provide you
157
+ with facilities for running those works, provided that you comply with
158
+ the terms of this License in conveying all material for which you do
159
+ not control copyright. Those thus making or running the covered works
160
+ for you must do so exclusively on your behalf, under your direction
161
+ and control, on terms that prohibit them from making any copies of
162
+ your copyrighted material outside their relationship with you.
163
+
164
+ Conveying under any other circumstances is permitted solely under
165
+ the conditions stated below. Sublicensing is not allowed; section 10
166
+ makes it unnecessary.
167
+
168
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
169
+
170
+ No covered work shall be deemed part of an effective technological
171
+ measure under any applicable law fulfilling obligations under article
172
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
173
+ similar laws prohibiting or restricting circumvention of such
174
+ measures.
175
+
176
+ When you convey a covered work, you waive any legal power to forbid
177
+ circumvention of technological measures to the extent such circumvention
178
+ is effected by exercising rights under this License with respect to
179
+ the covered work, and you disclaim any intention to limit operation or
180
+ modification of the work as a means of enforcing, against the work's
181
+ users, your or third parties' legal rights to forbid circumvention of
182
+ technological measures.
183
+
184
+ 4. Conveying Verbatim Copies.
185
+
186
+ You may convey verbatim copies of the Program's source code as you
187
+ receive it, in any medium, provided that you conspicuously and
188
+ appropriately publish on each copy an appropriate copyright notice;
189
+ keep intact all notices stating that this License and any
190
+ non-permissive terms added in accord with section 7 apply to the code;
191
+ keep intact all notices of the absence of any warranty; and give all
192
+ recipients a copy of this License along with the Program.
193
+
194
+ You may charge any price or no price for each copy that you convey,
195
+ and you may offer support or warranty protection for a fee.
196
+
197
+ 5. Conveying Modified Source Versions.
198
+
199
+ You may convey a work based on the Program, or the modifications to
200
+ produce it from the Program, in the form of source code under the
201
+ terms of section 4, provided that you also meet all of these conditions:
202
+
203
+ a) The work must carry prominent notices stating that you modified
204
+ it, and giving a relevant date.
205
+
206
+ b) The work must carry prominent notices stating that it is
207
+ released under this License and any conditions added under section
208
+ 7. This requirement modifies the requirement in section 4 to
209
+ "keep intact all notices".
210
+
211
+ c) You must license the entire work, as a whole, under this
212
+ License to anyone who comes into possession of a copy. This
213
+ License will therefore apply, along with any applicable section 7
214
+ additional terms, to the whole of the work, and all its parts,
215
+ regardless of how they are packaged. This License gives no
216
+ permission to license the work in any other way, but it does not
217
+ invalidate such permission if you have separately received it.
218
+
219
+ d) If the work has interactive user interfaces, each must display
220
+ Appropriate Legal Notices; however, if the Program has interactive
221
+ interfaces that do not display Appropriate Legal Notices, your
222
+ work need not make them do so.
223
+
224
+ A compilation of a covered work with other separate and independent
225
+ works, which are not by their nature extensions of the covered work,
226
+ and which are not combined with it such as to form a larger program,
227
+ in or on a volume of a storage or distribution medium, is called an
228
+ "aggregate" if the compilation and its resulting copyright are not
229
+ used to limit the access or legal rights of the compilation's users
230
+ beyond what the individual works permit. Inclusion of a covered work
231
+ in an aggregate does not cause this License to apply to the other
232
+ parts of the aggregate.
233
+
234
+ 6. Conveying Non-Source Forms.
235
+
236
+ You may convey a covered work in object code form under the terms
237
+ of sections 4 and 5, provided that you also convey the
238
+ machine-readable Corresponding Source under the terms of this License,
239
+ in one of these ways:
240
+
241
+ a) Convey the object code in, or embodied in, a physical product
242
+ (including a physical distribution medium), accompanied by the
243
+ Corresponding Source fixed on a durable physical medium
244
+ customarily used for software interchange.
245
+
246
+ b) Convey the object code in, or embodied in, a physical product
247
+ (including a physical distribution medium), accompanied by a
248
+ written offer, valid for at least three years and valid for as
249
+ long as you offer spare parts or customer support for that product
250
+ model, to give anyone who possesses the object code either (1) a
251
+ copy of the Corresponding Source for all the software in the
252
+ product that is covered by this License, on a durable physical
253
+ medium customarily used for software interchange, for a price no
254
+ more than your reasonable cost of physically performing this
255
+ conveying of source, or (2) access to copy the
256
+ Corresponding Source from a network server at no charge.
257
+
258
+ c) Convey individual copies of the object code with a copy of the
259
+ written offer to provide the Corresponding Source. This
260
+ alternative is allowed only occasionally and noncommercially, and
261
+ only if you received the object code with such an offer, in accord
262
+ with subsection 6b.
263
+
264
+ d) Convey the object code by offering access from a designated
265
+ place (gratis or for a charge), and offer equivalent access to the
266
+ Corresponding Source in the same way through the same place at no
267
+ further charge. You need not require recipients to copy the
268
+ Corresponding Source along with the object code. If the place to
269
+ copy the object code is a network server, the Corresponding Source
270
+ may be on a different server (operated by you or a third party)
271
+ that supports equivalent copying facilities, provided you maintain
272
+ clear directions next to the object code saying where to find the
273
+ Corresponding Source. Regardless of what server hosts the
274
+ Corresponding Source, you remain obligated to ensure that it is
275
+ available for as long as needed to satisfy these requirements.
276
+
277
+ e) Convey the object code using peer-to-peer transmission, provided
278
+ you inform other peers where the object code and Corresponding
279
+ Source of the work are being offered to the general public at no
280
+ charge under subsection 6d.
281
+
282
+ A separable portion of the object code, whose source code is excluded
283
+ from the Corresponding Source as a System Library, need not be
284
+ included in conveying the object code work.
285
+
286
+ A "User Product" is either (1) a "consumer product", which means any
287
+ tangible personal property which is normally used for personal, family,
288
+ or household purposes, or (2) anything designed or sold for incorporation
289
+ into a dwelling. In determining whether a product is a consumer product,
290
+ doubtful cases shall be resolved in favor of coverage. For a particular
291
+ product received by a particular user, "normally used" refers to a
292
+ typical or common use of that class of product, regardless of the status
293
+ of the particular user or of the way in which the particular user
294
+ actually uses, or expects or is expected to use, the product. A product
295
+ is a consumer product regardless of whether the product has substantial
296
+ commercial, industrial or non-consumer uses, unless such uses represent
297
+ the only significant mode of use of the product.
298
+
299
+ "Installation Information" for a User Product means any methods,
300
+ procedures, authorization keys, or other information required to install
301
+ and execute modified versions of a covered work in that User Product from
302
+ a modified version of its Corresponding Source. The information must
303
+ suffice to ensure that the continued functioning of the modified object
304
+ code is in no case prevented or interfered with solely because
305
+ modification has been made.
306
+
307
+ If you convey an object code work under this section in, or with, or
308
+ specifically for use in, a User Product, and the conveying occurs as
309
+ part of a transaction in which the right of possession and use of the
310
+ User Product is transferred to the recipient in perpetuity or for a
311
+ fixed term (regardless of how the transaction is characterized), the
312
+ Corresponding Source conveyed under this section must be accompanied
313
+ by the Installation Information. But this requirement does not apply
314
+ if neither you nor any third party retains the ability to install
315
+ modified object code on the User Product (for example, the work has
316
+ been installed in ROM).
317
+
318
+ The requirement to provide Installation Information does not include a
319
+ requirement to continue to provide support service, warranty, or updates
320
+ for a work that has been modified or installed by the recipient, or for
321
+ the User Product in which it has been modified or installed. Access to a
322
+ network may be denied when the modification itself materially and
323
+ adversely affects the operation of the network or violates the rules and
324
+ protocols for communication across the network.
325
+
326
+ Corresponding Source conveyed, and Installation Information provided,
327
+ in accord with this section must be in a format that is publicly
328
+ documented (and with an implementation available to the public in
329
+ source code form), and must require no special password or key for
330
+ unpacking, reading or copying.
331
+
332
+ 7. Additional Terms.
333
+
334
+ "Additional permissions" are terms that supplement the terms of this
335
+ License by making exceptions from one or more of its conditions.
336
+ Additional permissions that are applicable to the entire Program shall
337
+ be treated as though they were included in this License, to the extent
338
+ that they are valid under applicable law. If additional permissions
339
+ apply only to part of the Program, that part may be used separately
340
+ under those permissions, but the entire Program remains governed by
341
+ this License without regard to the additional permissions.
342
+
343
+ When you convey a copy of a covered work, you may at your option
344
+ remove any additional permissions from that copy, or from any part of
345
+ it. (Additional permissions may be written to require their own
346
+ removal in certain cases when you modify the work.) You may place
347
+ additional permissions on material, added by you to a covered work,
348
+ for which you have or can give appropriate copyright permission.
349
+
350
+ Notwithstanding any other provision of this License, for material you
351
+ add to a covered work, you may (if authorized by the copyright holders of
352
+ that material) supplement the terms of this License with terms:
353
+
354
+ a) Disclaiming warranty or limiting liability differently from the
355
+ terms of sections 15 and 16 of this License; or
356
+
357
+ b) Requiring preservation of specified reasonable legal notices or
358
+ author attributions in that material or in the Appropriate Legal
359
+ Notices displayed by works containing it; or
360
+
361
+ c) Prohibiting misrepresentation of the origin of that material, or
362
+ requiring that modified versions of such material be marked in
363
+ reasonable ways as different from the original version; or
364
+
365
+ d) Limiting the use for publicity purposes of names of licensors or
366
+ authors of the material; or
367
+
368
+ e) Declining to grant rights under trademark law for use of some
369
+ trade names, trademarks, or service marks; or
370
+
371
+ f) Requiring indemnification of licensors and authors of that
372
+ material by anyone who conveys the material (or modified versions of
373
+ it) with contractual assumptions of liability to the recipient, for
374
+ any liability that these contractual assumptions directly impose on
375
+ those licensors and authors.
376
+
377
+ All other non-permissive additional terms are considered "further
378
+ restrictions" within the meaning of section 10. If the Program as you
379
+ received it, or any part of it, contains a notice stating that it is
380
+ governed by this License along with a term that is a further
381
+ restriction, you may remove that term. If a license document contains
382
+ a further restriction but permits relicensing or conveying under this
383
+ License, you may add to a covered work material governed by the terms
384
+ of that license document, provided that the further restriction does
385
+ not survive such relicensing or conveying.
386
+
387
+ If you add terms to a covered work in accord with this section, you
388
+ must place, in the relevant source files, a statement of the
389
+ additional terms that apply to those files, or a notice indicating
390
+ where to find the applicable terms.
391
+
392
+ Additional terms, permissive or non-permissive, may be stated in the
393
+ form of a separately written license, or stated as exceptions;
394
+ the above requirements apply either way.
395
+
396
+ 8. Termination.
397
+
398
+ You may not propagate or modify a covered work except as expressly
399
+ provided under this License. Any attempt otherwise to propagate or
400
+ modify it is void, and will automatically terminate your rights under
401
+ this License (including any patent licenses granted under the third
402
+ paragraph of section 11).
403
+
404
+ However, if you cease all violation of this License, then your
405
+ license from a particular copyright holder is reinstated (a)
406
+ provisionally, unless and until the copyright holder explicitly and
407
+ finally terminates your license, and (b) permanently, if the copyright
408
+ holder fails to notify you of the violation by some reasonable means
409
+ prior to 60 days after the cessation.
410
+
411
+ Moreover, your license from a particular copyright holder is
412
+ reinstated permanently if the copyright holder notifies you of the
413
+ violation by some reasonable means, this is the first time you have
414
+ received notice of violation of this License (for any work) from that
415
+ copyright holder, and you cure the violation prior to 30 days after
416
+ your receipt of the notice.
417
+
418
+ Termination of your rights under this section does not terminate the
419
+ licenses of parties who have received copies or rights from you under
420
+ this License. If your rights have been terminated and not permanently
421
+ reinstated, you do not qualify to receive new licenses for the same
422
+ material under section 10.
423
+
424
+ 9. Acceptance Not Required for Having Copies.
425
+
426
+ You are not required to accept this License in order to receive or
427
+ run a copy of the Program. Ancillary propagation of a covered work
428
+ occurring solely as a consequence of using peer-to-peer transmission
429
+ to receive a copy likewise does not require acceptance. However,
430
+ nothing other than this License grants you permission to propagate or
431
+ modify any covered work. These actions infringe copyright if you do
432
+ not accept this License. Therefore, by modifying or propagating a
433
+ covered work, you indicate your acceptance of this License to do so.
434
+
435
+ 10. Automatic Licensing of Downstream Recipients.
436
+
437
+ Each time you convey a covered work, the recipient automatically
438
+ receives a license from the original licensors, to run, modify and
439
+ propagate that work, subject to this License. You are not responsible
440
+ for enforcing compliance by third parties with this License.
441
+
442
+ An "entity transaction" is a transaction transferring control of an
443
+ organization, or substantially all assets of one, or subdividing an
444
+ organization, or merging organizations. If propagation of a covered
445
+ work results from an entity transaction, each party to that
446
+ transaction who receives a copy of the work also receives whatever
447
+ licenses to the work the party's predecessor in interest had or could
448
+ give under the previous paragraph, plus a right to possession of the
449
+ Corresponding Source of the work from the predecessor in interest, if
450
+ the predecessor has it or can get it with reasonable efforts.
451
+
452
+ You may not impose any further restrictions on the exercise of the
453
+ rights granted or affirmed under this License. For example, you may
454
+ not impose a license fee, royalty, or other charge for exercise of
455
+ rights granted under this License, and you may not initiate litigation
456
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
457
+ any patent claim is infringed by making, using, selling, offering for
458
+ sale, or importing the Program or any portion of it.
459
+
460
+ 11. Patents.
461
+
462
+ A "contributor" is a copyright holder who authorizes use under this
463
+ License of the Program or a work on which the Program is based. The
464
+ work thus licensed is called the contributor's "contributor version".
465
+
466
+ A contributor's "essential patent claims" are all patent claims
467
+ owned or controlled by the contributor, whether already acquired or
468
+ hereafter acquired, that would be infringed by some manner, permitted
469
+ by this License, of making, using, or selling its contributor version,
470
+ but do not include claims that would be infringed only as a
471
+ consequence of further modification of the contributor version. For
472
+ purposes of this definition, "control" includes the right to grant
473
+ patent sublicenses in a manner consistent with the requirements of
474
+ this License.
475
+
476
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
477
+ patent license under the contributor's essential patent claims, to
478
+ make, use, sell, offer for sale, import and otherwise run, modify and
479
+ propagate the contents of its contributor version.
480
+
481
+ In the following three paragraphs, a "patent license" is any express
482
+ agreement or commitment, however denominated, not to enforce a patent
483
+ (such as an express permission to practice a patent or covenant not to
484
+ sue for patent infringement). To "grant" such a patent license to a
485
+ party means to make such an agreement or commitment not to enforce a
486
+ patent against the party.
487
+
488
+ If you convey a covered work, knowingly relying on a patent license,
489
+ and the Corresponding Source of the work is not available for anyone
490
+ to copy, free of charge and under the terms of this License, through a
491
+ publicly available network server or other readily accessible means,
492
+ then you must either (1) cause the Corresponding Source to be so
493
+ available, or (2) arrange to deprive yourself of the benefit of the
494
+ patent license for this particular work, or (3) arrange, in a manner
495
+ consistent with the requirements of this License, to extend the patent
496
+ license to downstream recipients. "Knowingly relying" means you have
497
+ actual knowledge that, but for the patent license, your conveying the
498
+ covered work in a country, or your recipient's use of the covered work
499
+ in a country, would infringe one or more identifiable patents in that
500
+ country that you have reason to believe are valid.
501
+
502
+ If, pursuant to or in connection with a single transaction or
503
+ arrangement, you convey, or propagate by procuring conveyance of, a
504
+ covered work, and grant a patent license to some of the parties
505
+ receiving the covered work authorizing them to use, propagate, modify
506
+ or convey a specific copy of the covered work, then the patent license
507
+ you grant is automatically extended to all recipients of the covered
508
+ work and works based on it.
509
+
510
+ A patent license is "discriminatory" if it does not include within
511
+ the scope of its coverage, prohibits the exercise of, or is
512
+ conditioned on the non-exercise of one or more of the rights that are
513
+ specifically granted under this License. You may not convey a covered
514
+ work if you are a party to an arrangement with a third party that is
515
+ in the business of distributing software, under which you make payment
516
+ to the third party based on the extent of your activity of conveying
517
+ the work, and under which the third party grants, to any of the
518
+ parties who would receive the covered work from you, a discriminatory
519
+ patent license (a) in connection with copies of the covered work
520
+ conveyed by you (or copies made from those copies), or (b) primarily
521
+ for and in connection with specific products or compilations that
522
+ contain the covered work, unless you entered into that arrangement,
523
+ or that patent license was granted, prior to 28 March 2007.
524
+
525
+ Nothing in this License shall be construed as excluding or limiting
526
+ any implied license or other defenses to infringement that may
527
+ otherwise be available to you under applicable patent law.
528
+
529
+ 12. No Surrender of Others' Freedom.
530
+
531
+ If conditions are imposed on you (whether by court order, agreement or
532
+ otherwise) that contradict the conditions of this License, they do not
533
+ excuse you from the conditions of this License. If you cannot convey a
534
+ covered work so as to satisfy simultaneously your obligations under this
535
+ License and any other pertinent obligations, then as a consequence you may
536
+ not convey it at all. For example, if you agree to terms that obligate you
537
+ to collect a royalty for further conveying from those to whom you convey
538
+ the Program, the only way you could satisfy both those terms and this
539
+ License would be to refrain entirely from conveying the Program.
540
+
541
+ 13. Remote Network Interaction; Use with the GNU General Public License.
542
+
543
+ Notwithstanding any other provision of this License, if you modify the
544
+ Program, your modified version must prominently offer all users
545
+ interacting with it remotely through a computer network (if your version
546
+ supports such interaction) an opportunity to receive the Corresponding
547
+ Source of your version by providing access to the Corresponding Source
548
+ from a network server at no charge, through some standard or customary
549
+ means of facilitating copying of software. This Corresponding Source
550
+ shall include the Corresponding Source for any work covered by version 3
551
+ of the GNU General Public License that is incorporated pursuant to the
552
+ following paragraph.
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 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 work with which it is combined will remain governed by version
560
+ 3 of the GNU General Public License.
561
+
562
+ 14. Revised Versions of this License.
563
+
564
+ The Free Software Foundation may publish revised and/or new versions of
565
+ the GNU Affero General Public License from time to time. Such new versions
566
+ will be similar in spirit to the present version, but may differ in detail to
567
+ address new problems or concerns.
568
+
569
+ Each version is given a distinguishing version number. If the
570
+ Program specifies that a certain numbered version of the GNU Affero General
571
+ Public License "or any later version" applies to it, you have the
572
+ option of following the terms and conditions either of that numbered
573
+ version or of any later version published by the Free Software
574
+ Foundation. If the Program does not specify a version number of the
575
+ GNU Affero General Public License, you may choose any version ever published
576
+ by the Free Software Foundation.
577
+
578
+ If the Program specifies that a proxy can decide which future
579
+ versions of the GNU Affero General Public License can be used, that proxy's
580
+ public statement of acceptance of a version permanently authorizes you
581
+ to choose that version for the Program.
582
+
583
+ Later license versions may give you additional or different
584
+ permissions. However, no additional obligations are imposed on any
585
+ author or copyright holder as a result of your choosing to follow a
586
+ later version.
587
+
588
+ 15. Disclaimer of Warranty.
589
+
590
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
591
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
592
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
593
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
594
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
595
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
596
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
597
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
598
+
599
+ 16. Limitation of Liability.
600
+
601
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
602
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
603
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
604
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
605
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
606
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
607
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
608
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
609
+ SUCH DAMAGES.
610
+
611
+ 17. Interpretation of Sections 15 and 16.
612
+
613
+ If the disclaimer of warranty and limitation of liability provided
614
+ above cannot be given local legal effect according to their terms,
615
+ reviewing courts shall apply local law that most closely approximates
616
+ an absolute waiver of all civil liability in connection with the
617
+ Program, unless a warranty or assumption of liability accompanies a
618
+ copy of the Program in return for a fee.
619
+
620
+ END OF TERMS AND CONDITIONS
621
+
622
+ How to Apply These Terms to Your New Programs
623
+
624
+ If you develop a new program, and you want it to be of the greatest
625
+ possible use to the public, the best way to achieve this is to make it
626
+ free software which everyone can redistribute and change under these terms.
627
+
628
+ To do so, attach the following notices to the program. It is safest
629
+ to attach them to the start of each source file to most effectively
630
+ state the exclusion of warranty; and each file should have at least
631
+ the "copyright" line and a pointer to where the full notice is found.
632
+
633
+ <one line to give the program's name and a brief idea of what it does.>
634
+ Copyright (C) <year> <name of author>
635
+
636
+ This program is free software: you can redistribute it and/or modify
637
+ it under the terms of the GNU Affero General Public License as published
638
+ by the Free Software Foundation, either version 3 of the License, or
639
+ (at your option) any later version.
640
+
641
+ This program is distributed in the hope that it will be useful,
642
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
643
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644
+ GNU Affero General Public License for more details.
645
+
646
+ You should have received a copy of the GNU Affero General Public License
647
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
648
+
649
+ Also add information on how to contact you by electronic and paper mail.
650
+
651
+ If your software can interact with users remotely through a computer
652
+ network, you should also make sure that it provides a way for users to
653
+ get its source. For example, if your program is a web application, its
654
+ interface could display a "Source" link that leads users to an archive
655
+ of the code. There are many ways you could offer source, and different
656
+ solutions will be better for different programs; see section 13 for the
657
+ specific requirements.
658
+
659
+ You should also get your employer (if you work as a programmer) or school,
660
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
661
+ For more information on this, and how to apply and follow the GNU AGPL, see
662
+ <http://www.gnu.org/licenses/>.
TestingforfaivsixEx/content/eichellis/extensions/adetai/README.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # !After Detailer
2
+
3
+ !After Detailer is a extension for stable diffusion webui, similar to Detection Detailer, except it uses ultralytics instead of the mmdet.
4
+
5
+ ## Install
6
+
7
+ (from Mikubill/sd-webui-controlnet)
8
+
9
+ 1. Open "Extensions" tab.
10
+ 2. Open "Install from URL" tab in the tab.
11
+ 3. Enter `https://github.com/Bing-su/adetailer.git` to "URL for extension's git repository".
12
+ 4. Press "Install" button.
13
+ 5. Wait 5 seconds, and you will see the message "Installed into stable-diffusion-webui\extensions\adetailer. Use Installed tab to restart".
14
+ 6. Go to "Installed" tab, click "Check for updates", and then click "Apply and restart UI". (The next time you can also use this method to update extensions.)
15
+ 7. Completely restart A1111 webui including your terminal. (If you do not know what is a "terminal", you can reboot your computer: turn your computer off and turn it on again.)
16
+
17
+ You can now install it directly from the Extensions tab.
18
+
19
+ ![image](https://i.imgur.com/g6GdRBT.png)
20
+
21
+ You **DON'T** need to download any model from huggingface.
22
+
23
+ ## Options
24
+
25
+ | Model, Prompts | | |
26
+ | --------------------------------- | ------------------------------------- | ------------------------------------------------- |
27
+ | ADetailer model | Determine what to detect. | `None` = disable |
28
+ | ADetailer prompt, negative prompt | Prompts and negative prompts to apply | If left blank, it will use the same as the input. |
29
+
30
+ | Detection | | |
31
+ | ------------------------------------ | -------------------------------------------------------------------------------------------- | --- |
32
+ | Detection model confidence threshold | Only objects with a detection model confidence above this threshold are used for inpainting. | |
33
+ | Mask min/max ratio | Only use masks whose area is between those ratios for the area of the entire image. | |
34
+
35
+ If you want to exclude objects in the background, try setting the min ratio to around `0.01`.
36
+
37
+ | Mask Preprocessing | | |
38
+ | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
39
+ | Mask x, y offset | Moves the mask horizontally and vertically by | |
40
+ | Mask erosion (-) / dilation (+) | Enlarge or reduce the detected mask. | [opencv example](https://docs.opencv.org/4.7.0/db/df6/tutorial_erosion_dilatation.html) |
41
+ | Mask merge mode | `None`: Inpaint each mask<br/>`Merge`: Merge all masks and inpaint<br/>`Merge and Invert`: Merge all masks and Invert, then inpaint | |
42
+
43
+ Applied in this order: x, y offset → erosion/dilation → merge/invert.
44
+
45
+ #### Inpainting
46
+
47
+ Each option corresponds to a corresponding option on the inpaint tab. Therefore, please refer to the inpaint tab for usage details on how to use each option.
48
+
49
+ ## ControlNet Inpainting
50
+
51
+ You can use the ControlNet extension if you have ControlNet installed and ControlNet models.
52
+
53
+ Support `inpaint, scribble, lineart, openpose, tile` controlnet models. Once you choose a model, the preprocessor is set automatically. It works separately from the model set by the Controlnet extension.
54
+
55
+ ## Advanced Options
56
+
57
+ API request example: [wiki/API](https://github.com/Bing-su/adetailer/wiki/API)
58
+
59
+ `ui-config.json` entries: [wiki/ui-config.json](https://github.com/Bing-su/adetailer/wiki/ui-config.json)
60
+
61
+ `[SEP], [SKIP]` tokens: [wiki/Advanced](https://github.com/Bing-su/adetailer/wiki/Advanced)
62
+
63
+ ## Media
64
+
65
+ - 🎥 [どこよりも詳しいAfter Detailer (adetailer)の使い方① 【Stable Diffusion】](https://youtu.be/sF3POwPUWCE)
66
+ - 🎥 [どこよりも詳しいAfter Detailer (adetailer)の使い方② 【Stable Diffusion】](https://youtu.be/urNISRdbIEg)
67
+
68
+ ## Model
69
+
70
+ | Model | Target | mAP 50 | mAP 50-95 |
71
+ | --------------------- | --------------------- | ----------------------------- | ----------------------------- |
72
+ | face_yolov8n.pt | 2D / realistic face | 0.660 | 0.366 |
73
+ | face_yolov8s.pt | 2D / realistic face | 0.713 | 0.404 |
74
+ | hand_yolov8n.pt | 2D / realistic hand | 0.767 | 0.505 |
75
+ | person_yolov8n-seg.pt | 2D / realistic person | 0.782 (bbox)<br/>0.761 (mask) | 0.555 (bbox)<br/>0.460 (mask) |
76
+ | person_yolov8s-seg.pt | 2D / realistic person | 0.824 (bbox)<br/>0.809 (mask) | 0.605 (bbox)<br/>0.508 (mask) |
77
+ | mediapipe_face_full | realistic face | - | - |
78
+ | mediapipe_face_short | realistic face | - | - |
79
+ | mediapipe_face_mesh | realistic face | - | - |
80
+
81
+ The yolo models can be found on huggingface [Bingsu/adetailer](https://huggingface.co/Bingsu/adetailer).
82
+
83
+ ### Additional Model
84
+
85
+ Put your [ultralytics](https://github.com/ultralytics/ultralytics) yolo model in `webui/models/adetailer`. The model name should end with `.pt` or `.pth`.
86
+
87
+ It must be a bbox detection or segment model and use all label.
88
+
89
+ ## Example
90
+
91
+ ![image](https://i.imgur.com/38RSxSO.png)
92
+ ![image](https://i.imgur.com/2CYgjLx.png)
93
+
94
+ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F1L7V2N)
TestingforfaivsixEx/content/eichellis/extensions/adetai/Taskfile.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://taskfile.dev
2
+
3
+ version: "3"
4
+
5
+ dotenv:
6
+ - .env
7
+
8
+ tasks:
9
+ default:
10
+ cmds:
11
+ - echo "$PYTHON"
12
+ - echo "$WEBUI"
13
+ silent: true
14
+
15
+ launch:
16
+ dir: "{{.WEBUI}}"
17
+ cmds:
18
+ - "{{.PYTHON}} launch.py --xformers --api"
19
+ silent: true
20
+
21
+ lint:
22
+ cmds:
23
+ - pre-commit run -a
24
+
25
+ update:
26
+ cmds:
27
+ - "{{.PYTHON}} -m pip install -U ultralytics mediapipe ruff pre-commit black"
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/__init__.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .__version__ import __version__
2
+ from .args import AD_ENABLE, ALL_ARGS, ADetailerArgs, EnableChecker
3
+ from .common import PredictOutput, get_models
4
+ from .mediapipe import mediapipe_predict
5
+ from .ultralytics import ultralytics_predict
6
+
7
+ AFTER_DETAILER = "ADetailer"
8
+
9
+ __all__ = [
10
+ "__version__",
11
+ "AD_ENABLE",
12
+ "ADetailerArgs",
13
+ "AFTER_DETAILER",
14
+ "ALL_ARGS",
15
+ "EnableChecker",
16
+ "PredictOutput",
17
+ "get_models",
18
+ "mediapipe_predict",
19
+ "ultralytics_predict",
20
+ ]
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/__version__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ __version__ = "23.9.2"
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/args.py ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from collections import UserList
4
+ from functools import cached_property, partial
5
+ from typing import Any, Literal, NamedTuple, Optional, Union
6
+
7
+ import pydantic
8
+ from pydantic import (
9
+ BaseModel,
10
+ Extra,
11
+ NonNegativeFloat,
12
+ NonNegativeInt,
13
+ PositiveInt,
14
+ confloat,
15
+ conint,
16
+ constr,
17
+ root_validator,
18
+ validator,
19
+ )
20
+
21
+ cn_model_regex = r".*(inpaint|tile|scribble|lineart|openpose).*|^None$"
22
+
23
+
24
+ class Arg(NamedTuple):
25
+ attr: str
26
+ name: str
27
+
28
+
29
+ class ArgsList(UserList):
30
+ @cached_property
31
+ def attrs(self) -> tuple[str]:
32
+ return tuple(attr for attr, _ in self)
33
+
34
+ @cached_property
35
+ def names(self) -> tuple[str]:
36
+ return tuple(name for _, name in self)
37
+
38
+
39
+ class ADetailerArgs(BaseModel, extra=Extra.forbid):
40
+ ad_model: str = "None"
41
+ ad_prompt: str = ""
42
+ ad_negative_prompt: str = ""
43
+ ad_confidence: confloat(ge=0.0, le=1.0) = 0.3
44
+ ad_mask_k_largest: NonNegativeInt = 0
45
+ ad_mask_min_ratio: confloat(ge=0.0, le=1.0) = 0.0
46
+ ad_mask_max_ratio: confloat(ge=0.0, le=1.0) = 1.0
47
+ ad_dilate_erode: int = 4
48
+ ad_x_offset: int = 0
49
+ ad_y_offset: int = 0
50
+ ad_mask_merge_invert: Literal["None", "Merge", "Merge and Invert"] = "None"
51
+ ad_mask_blur: NonNegativeInt = 4
52
+ ad_denoising_strength: confloat(ge=0.0, le=1.0) = 0.4
53
+ ad_inpaint_only_masked: bool = True
54
+ ad_inpaint_only_masked_padding: NonNegativeInt = 32
55
+ ad_use_inpaint_width_height: bool = False
56
+ ad_inpaint_width: PositiveInt = 512
57
+ ad_inpaint_height: PositiveInt = 512
58
+ ad_use_steps: bool = False
59
+ ad_steps: PositiveInt = 28
60
+ ad_use_cfg_scale: bool = False
61
+ ad_cfg_scale: NonNegativeFloat = 7.0
62
+ ad_use_checkpoint: bool = False
63
+ ad_checkpoint: Optional[str] = None
64
+ ad_use_vae: bool = False
65
+ ad_vae: Optional[str] = None
66
+ ad_use_sampler: bool = False
67
+ ad_sampler: str = "DPM++ 2M Karras"
68
+ ad_use_noise_multiplier: bool = False
69
+ ad_noise_multiplier: confloat(ge=0.5, le=1.5) = 1.0
70
+ ad_use_clip_skip: bool = False
71
+ ad_clip_skip: conint(ge=1, le=12) = 1
72
+ ad_restore_face: bool = False
73
+ ad_controlnet_model: constr(regex=cn_model_regex) = "None"
74
+ ad_controlnet_module: Optional[constr(regex=r".*inpaint.*|^None$")] = None
75
+ ad_controlnet_weight: confloat(ge=0.0, le=1.0) = 1.0
76
+ ad_controlnet_guidance_start: confloat(ge=0.0, le=1.0) = 0.0
77
+ ad_controlnet_guidance_end: confloat(ge=0.0, le=1.0) = 1.0
78
+ is_api: bool = True
79
+
80
+ @root_validator(skip_on_failure=True)
81
+ def ad_controlnt_module_validator(cls, values): # noqa: N805
82
+ cn_model = values.get("ad_controlnet_model", "None")
83
+ cn_module = values.get("ad_controlnet_module", None)
84
+ if "inpaint" not in cn_model or cn_module == "None":
85
+ values["ad_controlnet_module"] = None
86
+ return values
87
+
88
+ @validator("is_api", pre=True)
89
+ def is_api_validator(cls, v: Any): # noqa: N805
90
+ "tuple is json serializable but cannot be made with json deserialize."
91
+ return type(v) is not tuple
92
+
93
+ @staticmethod
94
+ def ppop(
95
+ p: dict[str, Any],
96
+ key: str,
97
+ pops: list[str] | None = None,
98
+ cond: Any = None,
99
+ ) -> None:
100
+ if pops is None:
101
+ pops = [key]
102
+ if key not in p:
103
+ return
104
+ value = p[key]
105
+ cond = (not bool(value)) if cond is None else value == cond
106
+
107
+ if cond:
108
+ for k in pops:
109
+ p.pop(k, None)
110
+
111
+ def extra_params(self, suffix: str = "") -> dict[str, Any]:
112
+ if self.ad_model == "None":
113
+ return {}
114
+
115
+ p = {name: getattr(self, attr) for attr, name in ALL_ARGS}
116
+ ppop = partial(self.ppop, p)
117
+
118
+ ppop("ADetailer prompt")
119
+ ppop("ADetailer negative prompt")
120
+ ppop("ADetailer mask only top k largest", cond=0)
121
+ ppop("ADetailer mask min ratio", cond=0.0)
122
+ ppop("ADetailer mask max ratio", cond=1.0)
123
+ ppop("ADetailer x offset", cond=0)
124
+ ppop("ADetailer y offset", cond=0)
125
+ ppop("ADetailer mask merge/invert", cond="None")
126
+ ppop("ADetailer inpaint only masked", ["ADetailer inpaint padding"])
127
+ ppop(
128
+ "ADetailer use inpaint width/height",
129
+ [
130
+ "ADetailer use inpaint width/height",
131
+ "ADetailer inpaint width",
132
+ "ADetailer inpaint height",
133
+ ],
134
+ )
135
+ ppop(
136
+ "ADetailer use separate steps",
137
+ ["ADetailer use separate steps", "ADetailer steps"],
138
+ )
139
+ ppop(
140
+ "ADetailer use separate CFG scale",
141
+ ["ADetailer use separate CFG scale", "ADetailer CFG scale"],
142
+ )
143
+ ppop(
144
+ "ADetailer use separate checkpoint",
145
+ ["ADetailer use separate checkpoint", "ADetailer checkpoint"],
146
+ )
147
+ ppop(
148
+ "ADetailer use separate VAE",
149
+ ["ADetailer use separate VAE", "ADetailer VAE"],
150
+ )
151
+ ppop(
152
+ "ADetailer use separate sampler",
153
+ ["ADetailer use separate sampler", "ADetailer sampler"],
154
+ )
155
+ ppop(
156
+ "ADetailer use separate noise multiplier",
157
+ ["ADetailer use separate noise multiplier", "ADetailer noise multiplier"],
158
+ )
159
+
160
+ ppop(
161
+ "ADetailer use separate CLIP skip",
162
+ ["ADetailer use separate CLIP skip", "ADetailer CLIP skip"],
163
+ )
164
+
165
+ ppop("ADetailer restore face")
166
+ ppop(
167
+ "ADetailer ControlNet model",
168
+ [
169
+ "ADetailer ControlNet model",
170
+ "ADetailer ControlNet module",
171
+ "ADetailer ControlNet weight",
172
+ "ADetailer ControlNet guidance start",
173
+ "ADetailer ControlNet guidance end",
174
+ ],
175
+ cond="None",
176
+ )
177
+ ppop("ADetailer ControlNet module")
178
+ ppop("ADetailer ControlNet weight", cond=1.0)
179
+ ppop("ADetailer ControlNet guidance start", cond=0.0)
180
+ ppop("ADetailer ControlNet guidance end", cond=1.0)
181
+
182
+ if suffix:
183
+ p = {k + suffix: v for k, v in p.items()}
184
+
185
+ return p
186
+
187
+
188
+ class EnableChecker(BaseModel):
189
+ enable: bool
190
+ arg_list: list
191
+
192
+ def is_enabled(self) -> bool:
193
+ ad_model = ALL_ARGS[0].attr
194
+ if not self.enable:
195
+ return False
196
+ return any(arg.get(ad_model, "None") != "None" for arg in self.arg_list)
197
+
198
+
199
+ _all_args = [
200
+ ("ad_enable", "ADetailer enable"),
201
+ ("ad_model", "ADetailer model"),
202
+ ("ad_prompt", "ADetailer prompt"),
203
+ ("ad_negative_prompt", "ADetailer negative prompt"),
204
+ ("ad_confidence", "ADetailer confidence"),
205
+ ("ad_mask_k_largest", "ADetailer mask only top k largest"),
206
+ ("ad_mask_min_ratio", "ADetailer mask min ratio"),
207
+ ("ad_mask_max_ratio", "ADetailer mask max ratio"),
208
+ ("ad_x_offset", "ADetailer x offset"),
209
+ ("ad_y_offset", "ADetailer y offset"),
210
+ ("ad_dilate_erode", "ADetailer dilate/erode"),
211
+ ("ad_mask_merge_invert", "ADetailer mask merge/invert"),
212
+ ("ad_mask_blur", "ADetailer mask blur"),
213
+ ("ad_denoising_strength", "ADetailer denoising strength"),
214
+ ("ad_inpaint_only_masked", "ADetailer inpaint only masked"),
215
+ ("ad_inpaint_only_masked_padding", "ADetailer inpaint padding"),
216
+ ("ad_use_inpaint_width_height", "ADetailer use inpaint width/height"),
217
+ ("ad_inpaint_width", "ADetailer inpaint width"),
218
+ ("ad_inpaint_height", "ADetailer inpaint height"),
219
+ ("ad_use_steps", "ADetailer use separate steps"),
220
+ ("ad_steps", "ADetailer steps"),
221
+ ("ad_use_cfg_scale", "ADetailer use separate CFG scale"),
222
+ ("ad_cfg_scale", "ADetailer CFG scale"),
223
+ ("ad_use_checkpoint", "ADetailer use separate checkpoint"),
224
+ ("ad_checkpoint", "ADetailer checkpoint"),
225
+ ("ad_use_vae", "ADetailer use separate VAE"),
226
+ ("ad_vae", "ADetailer VAE"),
227
+ ("ad_use_sampler", "ADetailer use separate sampler"),
228
+ ("ad_sampler", "ADetailer sampler"),
229
+ ("ad_use_noise_multiplier", "ADetailer use separate noise multiplier"),
230
+ ("ad_noise_multiplier", "ADetailer noise multiplier"),
231
+ ("ad_use_clip_skip", "ADetailer use separate CLIP skip"),
232
+ ("ad_clip_skip", "ADetailer CLIP skip"),
233
+ ("ad_restore_face", "ADetailer restore face"),
234
+ ("ad_controlnet_model", "ADetailer ControlNet model"),
235
+ ("ad_controlnet_module", "ADetailer ControlNet module"),
236
+ ("ad_controlnet_weight", "ADetailer ControlNet weight"),
237
+ ("ad_controlnet_guidance_start", "ADetailer ControlNet guidance start"),
238
+ ("ad_controlnet_guidance_end", "ADetailer ControlNet guidance end"),
239
+ ]
240
+
241
+ AD_ENABLE = Arg(*_all_args[0])
242
+ _args = [Arg(*args) for args in _all_args[1:]]
243
+ ALL_ARGS = ArgsList(_args)
244
+
245
+ BBOX_SORTBY = [
246
+ "None",
247
+ "Position (left to right)",
248
+ "Position (center to edge)",
249
+ "Area (large to small)",
250
+ ]
251
+ MASK_MERGE_INVERT = ["None", "Merge", "Merge and Invert"]
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/common.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from collections import OrderedDict
4
+ from dataclasses import dataclass, field
5
+ from pathlib import Path
6
+ from typing import Optional, Union
7
+
8
+ from huggingface_hub import hf_hub_download
9
+ from PIL import Image, ImageDraw
10
+ from rich import print
11
+
12
+ repo_id = "Bingsu/adetailer"
13
+
14
+
15
+ @dataclass
16
+ class PredictOutput:
17
+ bboxes: list[list[int | float]] = field(default_factory=list)
18
+ masks: list[Image.Image] = field(default_factory=list)
19
+ preview: Optional[Image.Image] = None
20
+
21
+
22
+ def hf_download(file: str):
23
+ try:
24
+ path = hf_hub_download(repo_id, file)
25
+ except Exception:
26
+ msg = f"[-] ADetailer: Failed to load model {file!r} from huggingface"
27
+ print(msg)
28
+ path = "INVALID"
29
+ return path
30
+
31
+
32
+ def get_models(
33
+ model_dir: Union[str, Path], huggingface: bool = True
34
+ ) -> OrderedDict[str, Optional[str]]:
35
+ model_dir = Path(model_dir)
36
+ if model_dir.is_dir():
37
+ model_paths = [
38
+ p
39
+ for p in model_dir.rglob("*")
40
+ if p.is_file() and p.suffix in (".pt", ".pth")
41
+ ]
42
+ else:
43
+ model_paths = []
44
+
45
+ models = OrderedDict()
46
+ if huggingface:
47
+ models.update(
48
+ {
49
+ "face_yolov8n.pt": hf_download("face_yolov8n.pt"),
50
+ "face_yolov8s.pt": hf_download("face_yolov8s.pt"),
51
+ "hand_yolov8n.pt": hf_download("hand_yolov8n.pt"),
52
+ "person_yolov8n-seg.pt": hf_download("person_yolov8n-seg.pt"),
53
+ "person_yolov8s-seg.pt": hf_download("person_yolov8s-seg.pt"),
54
+ }
55
+ )
56
+ models.update(
57
+ {
58
+ "mediapipe_face_full": None,
59
+ "mediapipe_face_short": None,
60
+ "mediapipe_face_mesh": None,
61
+ "mediapipe_face_mesh_eyes_only": None,
62
+ }
63
+ )
64
+
65
+ invalid_keys = [k for k, v in models.items() if v == "INVALID"]
66
+ for key in invalid_keys:
67
+ models.pop(key)
68
+
69
+ for path in model_paths:
70
+ if path.name in models:
71
+ continue
72
+ models[path.name] = str(path)
73
+
74
+ return models
75
+
76
+
77
+ def create_mask_from_bbox(
78
+ bboxes: list[list[float]], shape: tuple[int, int]
79
+ ) -> list[Image.Image]:
80
+ """
81
+ Parameters
82
+ ----------
83
+ bboxes: list[list[float]]
84
+ list of [x1, y1, x2, y2]
85
+ bounding boxes
86
+ shape: tuple[int, int]
87
+ shape of the image (width, height)
88
+
89
+ Returns
90
+ -------
91
+ masks: list[Image.Image]
92
+ A list of masks
93
+
94
+ """
95
+ masks = []
96
+ for bbox in bboxes:
97
+ mask = Image.new("L", shape, 0)
98
+ mask_draw = ImageDraw.Draw(mask)
99
+ mask_draw.rectangle(bbox, fill=255)
100
+ masks.append(mask)
101
+ return masks
102
+
103
+
104
+ def create_bbox_from_mask(
105
+ masks: list[Image.Image], shape: tuple[int, int]
106
+ ) -> list[list[int]]:
107
+ """
108
+ Parameters
109
+ ----------
110
+ masks: list[Image.Image]
111
+ A list of masks
112
+ shape: tuple[int, int]
113
+ shape of the image (width, height)
114
+
115
+ Returns
116
+ -------
117
+ bboxes: list[list[float]]
118
+ A list of bounding boxes
119
+
120
+ """
121
+ bboxes = []
122
+ for mask in masks:
123
+ mask = mask.resize(shape)
124
+ bbox = mask.getbbox()
125
+ if bbox is not None:
126
+ bboxes.append(list(bbox))
127
+ return bboxes
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/mask.py ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from enum import IntEnum
4
+ from functools import partial, reduce
5
+ from math import dist
6
+
7
+ import cv2
8
+ import numpy as np
9
+ from PIL import Image, ImageChops
10
+
11
+ from adetailer.args import MASK_MERGE_INVERT
12
+ from adetailer.common import PredictOutput
13
+
14
+
15
+ class SortBy(IntEnum):
16
+ NONE = 0
17
+ LEFT_TO_RIGHT = 1
18
+ CENTER_TO_EDGE = 2
19
+ AREA = 3
20
+
21
+
22
+ class MergeInvert(IntEnum):
23
+ NONE = 0
24
+ MERGE = 1
25
+ MERGE_INVERT = 2
26
+
27
+
28
+ def _dilate(arr: np.ndarray, value: int) -> np.ndarray:
29
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (value, value))
30
+ return cv2.dilate(arr, kernel, iterations=1)
31
+
32
+
33
+ def _erode(arr: np.ndarray, value: int) -> np.ndarray:
34
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (value, value))
35
+ return cv2.erode(arr, kernel, iterations=1)
36
+
37
+
38
+ def dilate_erode(img: Image.Image, value: int) -> Image.Image:
39
+ """
40
+ The dilate_erode function takes an image and a value.
41
+ If the value is positive, it dilates the image by that amount.
42
+ If the value is negative, it erodes the image by that amount.
43
+
44
+ Parameters
45
+ ----------
46
+ img: PIL.Image.Image
47
+ the image to be processed
48
+ value: int
49
+ kernel size of dilation or erosion
50
+
51
+ Returns
52
+ -------
53
+ PIL.Image.Image
54
+ The image that has been dilated or eroded
55
+ """
56
+ if value == 0:
57
+ return img
58
+
59
+ arr = np.array(img)
60
+ arr = _dilate(arr, value) if value > 0 else _erode(arr, -value)
61
+
62
+ return Image.fromarray(arr)
63
+
64
+
65
+ def offset(img: Image.Image, x: int = 0, y: int = 0) -> Image.Image:
66
+ """
67
+ The offset function takes an image and offsets it by a given x(→) and y(↑) value.
68
+
69
+ Parameters
70
+ ----------
71
+ mask: Image.Image
72
+ Pass the mask image to the function
73
+ x: int
74
+ →
75
+ y: int
76
+ ↑
77
+
78
+ Returns
79
+ -------
80
+ PIL.Image.Image
81
+ A new image that is offset by x and y
82
+ """
83
+ return ImageChops.offset(img, x, -y)
84
+
85
+
86
+ def is_all_black(img: Image.Image) -> bool:
87
+ arr = np.array(img)
88
+ return cv2.countNonZero(arr) == 0
89
+
90
+
91
+ def bbox_area(bbox: list[float]):
92
+ return (bbox[2] - bbox[0]) * (bbox[3] - bbox[1])
93
+
94
+
95
+ def mask_preprocess(
96
+ masks: list[Image.Image],
97
+ kernel: int = 0,
98
+ x_offset: int = 0,
99
+ y_offset: int = 0,
100
+ merge_invert: int | MergeInvert | str = MergeInvert.NONE,
101
+ ) -> list[Image.Image]:
102
+ """
103
+ The mask_preprocess function takes a list of masks and preprocesses them.
104
+ It dilates and erodes the masks, and offsets them by x_offset and y_offset.
105
+
106
+ Parameters
107
+ ----------
108
+ masks: list[Image.Image]
109
+ A list of masks
110
+ kernel: int
111
+ kernel size of dilation or erosion
112
+ x_offset: int
113
+ →
114
+ y_offset: int
115
+ ↑
116
+
117
+ Returns
118
+ -------
119
+ list[Image.Image]
120
+ A list of processed masks
121
+ """
122
+ if not masks:
123
+ return []
124
+
125
+ if x_offset != 0 or y_offset != 0:
126
+ masks = [offset(m, x_offset, y_offset) for m in masks]
127
+
128
+ if kernel != 0:
129
+ masks = [dilate_erode(m, kernel) for m in masks]
130
+ masks = [m for m in masks if not is_all_black(m)]
131
+
132
+ return mask_merge_invert(masks, mode=merge_invert)
133
+
134
+
135
+ # Bbox sorting
136
+ def _key_left_to_right(bbox: list[float]) -> float:
137
+ """
138
+ Left to right
139
+
140
+ Parameters
141
+ ----------
142
+ bbox: list[float]
143
+ list of [x1, y1, x2, y2]
144
+ """
145
+ return bbox[0]
146
+
147
+
148
+ def _key_center_to_edge(bbox: list[float], *, center: tuple[float, float]) -> float:
149
+ """
150
+ Center to edge
151
+
152
+ Parameters
153
+ ----------
154
+ bbox: list[float]
155
+ list of [x1, y1, x2, y2]
156
+ image: Image.Image
157
+ the image
158
+ """
159
+ bbox_center = ((bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2)
160
+ return dist(center, bbox_center)
161
+
162
+
163
+ def _key_area(bbox: list[float]) -> float:
164
+ """
165
+ Large to small
166
+
167
+ Parameters
168
+ ----------
169
+ bbox: list[float]
170
+ list of [x1, y1, x2, y2]
171
+ """
172
+ return -bbox_area(bbox)
173
+
174
+
175
+ def sort_bboxes(
176
+ pred: PredictOutput, order: int | SortBy = SortBy.NONE
177
+ ) -> PredictOutput:
178
+ if order == SortBy.NONE or len(pred.bboxes) <= 1:
179
+ return pred
180
+
181
+ if order == SortBy.LEFT_TO_RIGHT:
182
+ key = _key_left_to_right
183
+ elif order == SortBy.CENTER_TO_EDGE:
184
+ width, height = pred.preview.size
185
+ center = (width / 2, height / 2)
186
+ key = partial(_key_center_to_edge, center=center)
187
+ elif order == SortBy.AREA:
188
+ key = _key_area
189
+ else:
190
+ raise RuntimeError
191
+
192
+ items = len(pred.bboxes)
193
+ idx = sorted(range(items), key=lambda i: key(pred.bboxes[i]))
194
+ pred.bboxes = [pred.bboxes[i] for i in idx]
195
+ pred.masks = [pred.masks[i] for i in idx]
196
+ return pred
197
+
198
+
199
+ # Filter by ratio
200
+ def is_in_ratio(bbox: list[float], low: float, high: float, orig_area: int) -> bool:
201
+ area = bbox_area(bbox)
202
+ return low <= area / orig_area <= high
203
+
204
+
205
+ def filter_by_ratio(pred: PredictOutput, low: float, high: float) -> PredictOutput:
206
+ if not pred.bboxes:
207
+ return pred
208
+
209
+ w, h = pred.preview.size
210
+ orig_area = w * h
211
+ items = len(pred.bboxes)
212
+ idx = [i for i in range(items) if is_in_ratio(pred.bboxes[i], low, high, orig_area)]
213
+ pred.bboxes = [pred.bboxes[i] for i in idx]
214
+ pred.masks = [pred.masks[i] for i in idx]
215
+ return pred
216
+
217
+
218
+ def filter_k_largest(pred: PredictOutput, k: int = 0) -> PredictOutput:
219
+ if not pred.bboxes or k == 0:
220
+ return pred
221
+ areas = [bbox_area(bbox) for bbox in pred.bboxes]
222
+ idx = np.argsort(areas)[-k:]
223
+ pred.bboxes = [pred.bboxes[i] for i in idx]
224
+ pred.masks = [pred.masks[i] for i in idx]
225
+ return pred
226
+
227
+
228
+ # Merge / Invert
229
+ def mask_merge(masks: list[Image.Image]) -> list[Image.Image]:
230
+ arrs = [np.array(m) for m in masks]
231
+ arr = reduce(cv2.bitwise_or, arrs)
232
+ return [Image.fromarray(arr)]
233
+
234
+
235
+ def mask_invert(masks: list[Image.Image]) -> list[Image.Image]:
236
+ return [ImageChops.invert(m) for m in masks]
237
+
238
+
239
+ def mask_merge_invert(
240
+ masks: list[Image.Image], mode: int | MergeInvert | str
241
+ ) -> list[Image.Image]:
242
+ if isinstance(mode, str):
243
+ mode = MASK_MERGE_INVERT.index(mode)
244
+
245
+ if mode == MergeInvert.NONE or not masks:
246
+ return masks
247
+
248
+ if mode == MergeInvert.MERGE:
249
+ return mask_merge(masks)
250
+
251
+ if mode == MergeInvert.MERGE_INVERT:
252
+ merged = mask_merge(masks)
253
+ return mask_invert(merged)
254
+
255
+ raise RuntimeError
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/mediapipe.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from functools import partial
4
+
5
+ import mediapipe as mp
6
+ import numpy as np
7
+ from PIL import Image, ImageDraw
8
+
9
+ from adetailer import PredictOutput
10
+ from adetailer.common import create_bbox_from_mask, create_mask_from_bbox
11
+
12
+
13
+ def mediapipe_predict(
14
+ model_type: str, image: Image.Image, confidence: float = 0.3
15
+ ) -> PredictOutput:
16
+ mapping = {
17
+ "mediapipe_face_short": partial(mediapipe_face_detection, 0),
18
+ "mediapipe_face_full": partial(mediapipe_face_detection, 1),
19
+ "mediapipe_face_mesh": mediapipe_face_mesh,
20
+ "mediapipe_face_mesh_eyes_only": mediapipe_face_mesh_eyes_only,
21
+ }
22
+ if model_type in mapping:
23
+ func = mapping[model_type]
24
+ return func(image, confidence)
25
+ msg = f"[-] ADetailer: Invalid mediapipe model type: {model_type}, Available: {list(mapping.keys())!r}"
26
+ raise RuntimeError(msg)
27
+
28
+
29
+ def mediapipe_face_detection(
30
+ model_type: int, image: Image.Image, confidence: float = 0.3
31
+ ) -> PredictOutput:
32
+ img_width, img_height = image.size
33
+
34
+ mp_face_detection = mp.solutions.face_detection
35
+ draw_util = mp.solutions.drawing_utils
36
+
37
+ img_array = np.array(image)
38
+
39
+ with mp_face_detection.FaceDetection(
40
+ model_selection=model_type, min_detection_confidence=confidence
41
+ ) as face_detector:
42
+ pred = face_detector.process(img_array)
43
+
44
+ if pred.detections is None:
45
+ return PredictOutput()
46
+
47
+ preview_array = img_array.copy()
48
+
49
+ bboxes = []
50
+ for detection in pred.detections:
51
+ draw_util.draw_detection(preview_array, detection)
52
+
53
+ bbox = detection.location_data.relative_bounding_box
54
+ x1 = bbox.xmin * img_width
55
+ y1 = bbox.ymin * img_height
56
+ w = bbox.width * img_width
57
+ h = bbox.height * img_height
58
+ x2 = x1 + w
59
+ y2 = y1 + h
60
+
61
+ bboxes.append([x1, y1, x2, y2])
62
+
63
+ masks = create_mask_from_bbox(bboxes, image.size)
64
+ preview = Image.fromarray(preview_array)
65
+
66
+ return PredictOutput(bboxes=bboxes, masks=masks, preview=preview)
67
+
68
+
69
+ def get_convexhull(points: np.ndarray) -> list[tuple[int, int]]:
70
+ """
71
+ Parameters
72
+ ----------
73
+ points: An ndarray of shape (n, 2) containing the 2D points.
74
+
75
+ Returns
76
+ -------
77
+ list[tuple[int, int]]: Input for the draw.polygon function
78
+ """
79
+ from scipy.spatial import ConvexHull
80
+
81
+ hull = ConvexHull(points)
82
+ vertices = hull.vertices
83
+ return list(zip(points[vertices, 0], points[vertices, 1]))
84
+
85
+
86
+ def mediapipe_face_mesh(image: Image.Image, confidence: float = 0.3) -> PredictOutput:
87
+ mp_face_mesh = mp.solutions.face_mesh
88
+ draw_util = mp.solutions.drawing_utils
89
+ drawing_styles = mp.solutions.drawing_styles
90
+
91
+ w, h = image.size
92
+
93
+ with mp_face_mesh.FaceMesh(
94
+ static_image_mode=True, max_num_faces=20, min_detection_confidence=confidence
95
+ ) as face_mesh:
96
+ arr = np.array(image)
97
+ pred = face_mesh.process(arr)
98
+
99
+ if pred.multi_face_landmarks is None:
100
+ return PredictOutput()
101
+
102
+ preview = arr.copy()
103
+ masks = []
104
+
105
+ for landmarks in pred.multi_face_landmarks:
106
+ draw_util.draw_landmarks(
107
+ image=preview,
108
+ landmark_list=landmarks,
109
+ connections=mp_face_mesh.FACEMESH_TESSELATION,
110
+ landmark_drawing_spec=None,
111
+ connection_drawing_spec=drawing_styles.get_default_face_mesh_tesselation_style(),
112
+ )
113
+
114
+ points = np.array([(land.x * w, land.y * h) for land in landmarks.landmark])
115
+ outline = get_convexhull(points)
116
+
117
+ mask = Image.new("L", image.size, "black")
118
+ draw = ImageDraw.Draw(mask)
119
+ draw.polygon(outline, fill="white")
120
+ masks.append(mask)
121
+
122
+ bboxes = create_bbox_from_mask(masks, image.size)
123
+ preview = Image.fromarray(preview)
124
+ return PredictOutput(bboxes=bboxes, masks=masks, preview=preview)
125
+
126
+
127
+ def mediapipe_face_mesh_eyes_only(
128
+ image: Image.Image, confidence: float = 0.3
129
+ ) -> PredictOutput:
130
+ mp_face_mesh = mp.solutions.face_mesh
131
+
132
+ left_idx = np.array(list(mp_face_mesh.FACEMESH_LEFT_EYE)).flatten()
133
+ right_idx = np.array(list(mp_face_mesh.FACEMESH_RIGHT_EYE)).flatten()
134
+
135
+ w, h = image.size
136
+
137
+ with mp_face_mesh.FaceMesh(
138
+ static_image_mode=True, max_num_faces=20, min_detection_confidence=confidence
139
+ ) as face_mesh:
140
+ arr = np.array(image)
141
+ pred = face_mesh.process(arr)
142
+
143
+ if pred.multi_face_landmarks is None:
144
+ return PredictOutput()
145
+
146
+ preview = image.copy()
147
+ masks = []
148
+
149
+ for landmarks in pred.multi_face_landmarks:
150
+ points = np.array([(land.x * w, land.y * h) for land in landmarks.landmark])
151
+ left_eyes = points[left_idx]
152
+ right_eyes = points[right_idx]
153
+ left_outline = get_convexhull(left_eyes)
154
+ right_outline = get_convexhull(right_eyes)
155
+
156
+ mask = Image.new("L", image.size, "black")
157
+ draw = ImageDraw.Draw(mask)
158
+ for outline in (left_outline, right_outline):
159
+ draw.polygon(outline, fill="white")
160
+ masks.append(mask)
161
+
162
+ bboxes = create_bbox_from_mask(masks, image.size)
163
+ preview = draw_preview(preview, bboxes, masks)
164
+ return PredictOutput(bboxes=bboxes, masks=masks, preview=preview)
165
+
166
+
167
+ def draw_preview(
168
+ preview: Image.Image, bboxes: list[list[int]], masks: list[Image.Image]
169
+ ) -> Image.Image:
170
+ red = Image.new("RGB", preview.size, "red")
171
+ for mask in masks:
172
+ masked = Image.composite(red, preview, mask)
173
+ preview = Image.blend(preview, masked, 0.25)
174
+
175
+ draw = ImageDraw.Draw(preview)
176
+ for bbox in bboxes:
177
+ draw.rectangle(bbox, outline="red", width=2)
178
+
179
+ return preview
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/traceback.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import platform
5
+ import sys
6
+ from importlib.metadata import version
7
+ from typing import Any, Callable
8
+
9
+ from rich.console import Console, Group
10
+ from rich.panel import Panel
11
+ from rich.table import Table
12
+ from rich.traceback import Traceback
13
+
14
+ from adetailer.__version__ import __version__
15
+
16
+
17
+ def processing(*args: Any) -> dict[str, Any]:
18
+ try:
19
+ from modules.processing import (
20
+ StableDiffusionProcessingImg2Img,
21
+ StableDiffusionProcessingTxt2Img,
22
+ )
23
+ except ImportError:
24
+ return {}
25
+
26
+ p = None
27
+ for arg in args:
28
+ if isinstance(
29
+ arg, (StableDiffusionProcessingTxt2Img, StableDiffusionProcessingImg2Img)
30
+ ):
31
+ p = arg
32
+ break
33
+
34
+ if p is None:
35
+ return {}
36
+
37
+ info = {
38
+ "prompt": p.prompt,
39
+ "negative_prompt": p.negative_prompt,
40
+ "n_iter": p.n_iter,
41
+ "batch_size": p.batch_size,
42
+ "width": p.width,
43
+ "height": p.height,
44
+ "sampler_name": p.sampler_name,
45
+ "enable_hr": getattr(p, "enable_hr", False),
46
+ "hr_upscaler": getattr(p, "hr_upscaler", ""),
47
+ }
48
+
49
+ info.update(sd_models())
50
+ return info
51
+
52
+
53
+ def sd_models() -> dict[str, str]:
54
+ try:
55
+ from modules import shared
56
+
57
+ opts = shared.opts
58
+ except Exception:
59
+ return {}
60
+
61
+ return {
62
+ "checkpoint": getattr(opts, "sd_model_checkpoint", "------"),
63
+ "vae": getattr(opts, "sd_vae", "------"),
64
+ "unet": getattr(opts, "sd_unet", "------"),
65
+ }
66
+
67
+
68
+ def ad_args(*args: Any) -> dict[str, Any]:
69
+ ad_args = [
70
+ arg
71
+ for arg in args
72
+ if isinstance(arg, dict) and arg.get("ad_model", "None") != "None"
73
+ ]
74
+ if not ad_args:
75
+ return {}
76
+
77
+ arg0 = ad_args[0]
78
+ is_api = arg0.get("is_api", True)
79
+ return {
80
+ "version": __version__,
81
+ "ad_model": arg0["ad_model"],
82
+ "ad_prompt": arg0.get("ad_prompt", ""),
83
+ "ad_negative_prompt": arg0.get("ad_negative_prompt", ""),
84
+ "ad_controlnet_model": arg0.get("ad_controlnet_model", "None"),
85
+ "is_api": type(is_api) is not tuple,
86
+ }
87
+
88
+
89
+ def library_version():
90
+ libraries = ["torch", "torchvision", "ultralytics", "mediapipe"]
91
+ d = {}
92
+ for lib in libraries:
93
+ try:
94
+ d[lib] = version(lib)
95
+ except Exception:
96
+ d[lib] = "Unknown"
97
+ return d
98
+
99
+
100
+ def sys_info() -> dict[str, Any]:
101
+ try:
102
+ import launch
103
+
104
+ version = launch.git_tag()
105
+ commit = launch.commit_hash()
106
+ except Exception:
107
+ version = "Unknown (too old or vladmandic)"
108
+ commit = "Unknown"
109
+
110
+ return {
111
+ "Platform": platform.platform(),
112
+ "Python": sys.version,
113
+ "Version": version,
114
+ "Commit": commit,
115
+ "Commandline": sys.argv,
116
+ "Libraries": library_version(),
117
+ }
118
+
119
+
120
+ def get_table(title: str, data: dict[str, Any]) -> Table:
121
+ table = Table(title=title, highlight=True)
122
+ table.add_column(" ", justify="right", style="dim")
123
+ table.add_column("Value")
124
+ for key, value in data.items():
125
+ if not isinstance(value, str):
126
+ value = repr(value)
127
+ table.add_row(key, value)
128
+
129
+ return table
130
+
131
+
132
+ def rich_traceback(func: Callable) -> Callable:
133
+ def wrapper(*args, **kwargs):
134
+ string = io.StringIO()
135
+ width = Console().width
136
+ width = width - 4 if width > 4 else None
137
+ console = Console(file=string, width=width)
138
+ try:
139
+ return func(*args, **kwargs)
140
+ except Exception as e:
141
+ tables = [
142
+ get_table(title, data)
143
+ for title, data in [
144
+ ("System info", sys_info()),
145
+ ("Inputs", processing(*args)),
146
+ ("ADetailer", ad_args(*args)),
147
+ ]
148
+ if data
149
+ ]
150
+ tables.append(Traceback())
151
+
152
+ console.print(Panel(Group(*tables)))
153
+ output = "\n" + string.getvalue()
154
+
155
+ try:
156
+ error = e.__class__(output)
157
+ except Exception:
158
+ error = RuntimeError(output)
159
+ raise error from None
160
+
161
+ return wrapper
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/ui.py ADDED
@@ -0,0 +1,605 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from functools import partial
5
+ from types import SimpleNamespace
6
+ from typing import Any, Callable
7
+
8
+ import gradio as gr
9
+
10
+ from adetailer import AFTER_DETAILER, __version__
11
+ from adetailer.args import AD_ENABLE, ALL_ARGS, MASK_MERGE_INVERT
12
+ from controlnet_ext import controlnet_exists, get_cn_models
13
+
14
+ cn_module_choices = [
15
+ "inpaint_global_harmonious",
16
+ "inpaint_only",
17
+ "inpaint_only+lama",
18
+ ]
19
+
20
+
21
+ class Widgets(SimpleNamespace):
22
+ def tolist(self):
23
+ return [getattr(self, attr) for attr in ALL_ARGS.attrs]
24
+
25
+
26
+ @dataclass
27
+ class WebuiInfo:
28
+ ad_model_list: list[str]
29
+ sampler_names: list[str]
30
+ t2i_button: gr.Button
31
+ i2i_button: gr.Button
32
+ checkpoints_list: list[str]
33
+ vae_list: list[str]
34
+
35
+
36
+ def gr_interactive(value: bool = True):
37
+ return gr.update(interactive=value)
38
+
39
+
40
+ def ordinal(n: int) -> str:
41
+ d = {1: "st", 2: "nd", 3: "rd"}
42
+ return str(n) + ("th" if 11 <= n % 100 <= 13 else d.get(n % 10, "th"))
43
+
44
+
45
+ def suffix(n: int, c: str = " ") -> str:
46
+ return "" if n == 0 else c + ordinal(n + 1)
47
+
48
+
49
+ def on_widget_change(state: dict, value: Any, *, attr: str):
50
+ state[attr] = value
51
+ return state
52
+
53
+
54
+ def on_generate_click(state: dict, *values: Any):
55
+ for attr, value in zip(ALL_ARGS.attrs, values):
56
+ state[attr] = value
57
+ state["is_api"] = ()
58
+ return state
59
+
60
+
61
+ def on_cn_model_update(cn_model: str):
62
+ if "inpaint" in cn_model:
63
+ return gr.update(
64
+ visible=True, choices=cn_module_choices, value=cn_module_choices[0]
65
+ )
66
+ return gr.update(visible=False, choices=["None"], value="None")
67
+
68
+
69
+ def elem_id(item_id: str, n: int, is_img2img: bool) -> str:
70
+ tap = "img2img" if is_img2img else "txt2img"
71
+ suf = suffix(n, "_")
72
+ return f"script_{tap}_adetailer_{item_id}{suf}"
73
+
74
+
75
+ def adui(
76
+ num_models: int,
77
+ is_img2img: bool,
78
+ webui_info: WebuiInfo,
79
+ ):
80
+ states = []
81
+ infotext_fields = []
82
+ eid = partial(elem_id, n=0, is_img2img=is_img2img)
83
+
84
+ with gr.Accordion(AFTER_DETAILER, open=False, elem_id=eid("ad_main_accordion")):
85
+ with gr.Row():
86
+ with gr.Column(scale=6):
87
+ ad_enable = gr.Checkbox(
88
+ label="Enable ADetailer",
89
+ value=False,
90
+ visible=True,
91
+ elem_id=eid("ad_enable"),
92
+ )
93
+
94
+ with gr.Column(scale=1, min_width=180):
95
+ gr.Markdown(
96
+ f"v{__version__}",
97
+ elem_id=eid("ad_version"),
98
+ )
99
+
100
+ infotext_fields.append((ad_enable, AD_ENABLE.name))
101
+
102
+ with gr.Group(), gr.Tabs():
103
+ for n in range(num_models):
104
+ with gr.Tab(ordinal(n + 1)):
105
+ state, infofields = one_ui_group(
106
+ n=n,
107
+ is_img2img=is_img2img,
108
+ webui_info=webui_info,
109
+ )
110
+
111
+ states.append(state)
112
+ infotext_fields.extend(infofields)
113
+
114
+ # components: [bool, dict, dict, ...]
115
+ components = [ad_enable, *states]
116
+ return components, infotext_fields
117
+
118
+
119
+ def one_ui_group(n: int, is_img2img: bool, webui_info: WebuiInfo):
120
+ w = Widgets()
121
+ state = gr.State({})
122
+ eid = partial(elem_id, n=n, is_img2img=is_img2img)
123
+
124
+ with gr.Row():
125
+ model_choices = (
126
+ [*webui_info.ad_model_list, "None"]
127
+ if n == 0
128
+ else ["None", *webui_info.ad_model_list]
129
+ )
130
+
131
+ w.ad_model = gr.Dropdown(
132
+ label="ADetailer model" + suffix(n),
133
+ choices=model_choices,
134
+ value=model_choices[0],
135
+ visible=True,
136
+ type="value",
137
+ elem_id=eid("ad_model"),
138
+ )
139
+
140
+ with gr.Group():
141
+ with gr.Row(elem_id=eid("ad_toprow_prompt")):
142
+ w.ad_prompt = gr.Textbox(
143
+ label="ad_prompt" + suffix(n),
144
+ show_label=False,
145
+ lines=3,
146
+ placeholder="ADetailer prompt"
147
+ + suffix(n)
148
+ + "\nIf blank, the main prompt is used.",
149
+ elem_id=eid("ad_prompt"),
150
+ )
151
+
152
+ with gr.Row(elem_id=eid("ad_toprow_negative_prompt")):
153
+ w.ad_negative_prompt = gr.Textbox(
154
+ label="ad_negative_prompt" + suffix(n),
155
+ show_label=False,
156
+ lines=2,
157
+ placeholder="ADetailer negative prompt"
158
+ + suffix(n)
159
+ + "\nIf blank, the main negative prompt is used.",
160
+ elem_id=eid("ad_negative_prompt"),
161
+ )
162
+
163
+ with gr.Group():
164
+ with gr.Accordion(
165
+ "Detection", open=False, elem_id=eid("ad_detection_accordion")
166
+ ):
167
+ detection(w, n, is_img2img)
168
+
169
+ with gr.Accordion(
170
+ "Mask Preprocessing",
171
+ open=False,
172
+ elem_id=eid("ad_mask_preprocessing_accordion"),
173
+ ):
174
+ mask_preprocessing(w, n, is_img2img)
175
+
176
+ with gr.Accordion(
177
+ "Inpainting", open=False, elem_id=eid("ad_inpainting_accordion")
178
+ ):
179
+ inpainting(w, n, is_img2img, webui_info)
180
+
181
+ with gr.Group():
182
+ controlnet(w, n, is_img2img)
183
+
184
+ all_inputs = [state, *w.tolist()]
185
+ target_button = webui_info.i2i_button if is_img2img else webui_info.t2i_button
186
+ target_button.click(
187
+ fn=on_generate_click, inputs=all_inputs, outputs=state, queue=False
188
+ )
189
+
190
+ infotext_fields = [(getattr(w, attr), name + suffix(n)) for attr, name in ALL_ARGS]
191
+
192
+ return state, infotext_fields
193
+
194
+
195
+ def detection(w: Widgets, n: int, is_img2img: bool):
196
+ eid = partial(elem_id, n=n, is_img2img=is_img2img)
197
+
198
+ with gr.Row():
199
+ with gr.Column(variant="compact"):
200
+ w.ad_confidence = gr.Slider(
201
+ label="Detection model confidence threshold" + suffix(n),
202
+ minimum=0.0,
203
+ maximum=1.0,
204
+ step=0.01,
205
+ value=0.3,
206
+ visible=True,
207
+ elem_id=eid("ad_confidence"),
208
+ )
209
+ w.ad_mask_k_largest = gr.Slider(
210
+ label="Mask only the top k largest (0 to disable)" + suffix(n),
211
+ minumum=0,
212
+ maximum=10,
213
+ step=1,
214
+ value=0,
215
+ visible=True,
216
+ elem_id=eid("ad_mask_k_largest"),
217
+ )
218
+
219
+ with gr.Column(variant="compact"):
220
+ w.ad_mask_min_ratio = gr.Slider(
221
+ label="Mask min area ratio" + suffix(n),
222
+ minimum=0.0,
223
+ maximum=1.0,
224
+ step=0.001,
225
+ value=0.0,
226
+ visible=True,
227
+ elem_id=eid("ad_mask_min_ratio"),
228
+ )
229
+ w.ad_mask_max_ratio = gr.Slider(
230
+ label="Mask max area ratio" + suffix(n),
231
+ minimum=0.0,
232
+ maximum=1.0,
233
+ step=0.001,
234
+ value=1.0,
235
+ visible=True,
236
+ elem_id=eid("ad_mask_max_ratio"),
237
+ )
238
+
239
+
240
+ def mask_preprocessing(w: Widgets, n: int, is_img2img: bool):
241
+ eid = partial(elem_id, n=n, is_img2img=is_img2img)
242
+
243
+ with gr.Group():
244
+ with gr.Row():
245
+ with gr.Column(variant="compact"):
246
+ w.ad_x_offset = gr.Slider(
247
+ label="Mask x(→) offset" + suffix(n),
248
+ minimum=-200,
249
+ maximum=200,
250
+ step=1,
251
+ value=0,
252
+ visible=True,
253
+ elem_id=eid("ad_x_offset"),
254
+ )
255
+ w.ad_y_offset = gr.Slider(
256
+ label="Mask y(↑) offset" + suffix(n),
257
+ minimum=-200,
258
+ maximum=200,
259
+ step=1,
260
+ value=0,
261
+ visible=True,
262
+ elem_id=eid("ad_y_offset"),
263
+ )
264
+
265
+ with gr.Column(variant="compact"):
266
+ w.ad_dilate_erode = gr.Slider(
267
+ label="Mask erosion (-) / dilation (+)" + suffix(n),
268
+ minimum=-128,
269
+ maximum=128,
270
+ step=4,
271
+ value=4,
272
+ visible=True,
273
+ elem_id=eid("ad_dilate_erode"),
274
+ )
275
+
276
+ with gr.Row():
277
+ w.ad_mask_merge_invert = gr.Radio(
278
+ label="Mask merge mode" + suffix(n),
279
+ choices=MASK_MERGE_INVERT,
280
+ value="None",
281
+ elem_id=eid("ad_mask_merge_invert"),
282
+ )
283
+
284
+
285
+ def inpainting(w: Widgets, n: int, is_img2img: bool, webui_info: WebuiInfo):
286
+ eid = partial(elem_id, n=n, is_img2img=is_img2img)
287
+
288
+ with gr.Group():
289
+ with gr.Row():
290
+ w.ad_mask_blur = gr.Slider(
291
+ label="Inpaint mask blur" + suffix(n),
292
+ minimum=0,
293
+ maximum=64,
294
+ step=1,
295
+ value=4,
296
+ visible=True,
297
+ elem_id=eid("ad_mask_blur"),
298
+ )
299
+
300
+ w.ad_denoising_strength = gr.Slider(
301
+ label="Inpaint denoising strength" + suffix(n),
302
+ minimum=0.0,
303
+ maximum=1.0,
304
+ step=0.01,
305
+ value=0.4,
306
+ visible=True,
307
+ elem_id=eid("ad_denoising_strength"),
308
+ )
309
+
310
+ with gr.Row():
311
+ with gr.Column(variant="compact"):
312
+ w.ad_inpaint_only_masked = gr.Checkbox(
313
+ label="Inpaint only masked" + suffix(n),
314
+ value=True,
315
+ visible=True,
316
+ elem_id=eid("ad_inpaint_only_masked"),
317
+ )
318
+ w.ad_inpaint_only_masked_padding = gr.Slider(
319
+ label="Inpaint only masked padding, pixels" + suffix(n),
320
+ minimum=0,
321
+ maximum=256,
322
+ step=4,
323
+ value=32,
324
+ visible=True,
325
+ elem_id=eid("ad_inpaint_only_masked_padding"),
326
+ )
327
+
328
+ w.ad_inpaint_only_masked.change(
329
+ gr_interactive,
330
+ inputs=w.ad_inpaint_only_masked,
331
+ outputs=w.ad_inpaint_only_masked_padding,
332
+ queue=False,
333
+ )
334
+
335
+ with gr.Column(variant="compact"):
336
+ w.ad_use_inpaint_width_height = gr.Checkbox(
337
+ label="Use separate width/height" + suffix(n),
338
+ value=False,
339
+ visible=True,
340
+ elem_id=eid("ad_use_inpaint_width_height"),
341
+ )
342
+
343
+ w.ad_inpaint_width = gr.Slider(
344
+ label="inpaint width" + suffix(n),
345
+ minimum=64,
346
+ maximum=2048,
347
+ step=4,
348
+ value=512,
349
+ visible=True,
350
+ elem_id=eid("ad_inpaint_width"),
351
+ )
352
+
353
+ w.ad_inpaint_height = gr.Slider(
354
+ label="inpaint height" + suffix(n),
355
+ minimum=64,
356
+ maximum=2048,
357
+ step=4,
358
+ value=512,
359
+ visible=True,
360
+ elem_id=eid("ad_inpaint_height"),
361
+ )
362
+
363
+ w.ad_use_inpaint_width_height.change(
364
+ lambda value: (gr_interactive(value), gr_interactive(value)),
365
+ inputs=w.ad_use_inpaint_width_height,
366
+ outputs=[w.ad_inpaint_width, w.ad_inpaint_height],
367
+ queue=False,
368
+ )
369
+
370
+ with gr.Row():
371
+ with gr.Column(variant="compact"):
372
+ w.ad_use_steps = gr.Checkbox(
373
+ label="Use separate steps" + suffix(n),
374
+ value=False,
375
+ visible=True,
376
+ elem_id=eid("ad_use_steps"),
377
+ )
378
+
379
+ w.ad_steps = gr.Slider(
380
+ label="ADetailer steps" + suffix(n),
381
+ minimum=1,
382
+ maximum=150,
383
+ step=1,
384
+ value=28,
385
+ visible=True,
386
+ elem_id=eid("ad_steps"),
387
+ )
388
+
389
+ w.ad_use_steps.change(
390
+ gr_interactive,
391
+ inputs=w.ad_use_steps,
392
+ outputs=w.ad_steps,
393
+ queue=False,
394
+ )
395
+
396
+ with gr.Column(variant="compact"):
397
+ w.ad_use_cfg_scale = gr.Checkbox(
398
+ label="Use separate CFG scale" + suffix(n),
399
+ value=False,
400
+ visible=True,
401
+ elem_id=eid("ad_use_cfg_scale"),
402
+ )
403
+
404
+ w.ad_cfg_scale = gr.Slider(
405
+ label="ADetailer CFG scale" + suffix(n),
406
+ minimum=0.0,
407
+ maximum=30.0,
408
+ step=0.5,
409
+ value=7.0,
410
+ visible=True,
411
+ elem_id=eid("ad_cfg_scale"),
412
+ )
413
+
414
+ w.ad_use_cfg_scale.change(
415
+ gr_interactive,
416
+ inputs=w.ad_use_cfg_scale,
417
+ outputs=w.ad_cfg_scale,
418
+ queue=False,
419
+ )
420
+
421
+ with gr.Row():
422
+ with gr.Column(variant="compact"):
423
+ w.ad_use_checkpoint = gr.Checkbox(
424
+ label="Use separate checkpoint (experimental)" + suffix(n),
425
+ value=False,
426
+ visible=True,
427
+ elem_id=eid("ad_use_checkpoint"),
428
+ )
429
+
430
+ ckpts = ["Use same checkpoint", *webui_info.checkpoints_list]
431
+
432
+ w.ad_checkpoint = gr.Dropdown(
433
+ label="ADetailer checkpoint" + suffix(n),
434
+ choices=ckpts,
435
+ value=ckpts[0],
436
+ visible=True,
437
+ elem_id=eid("ad_checkpoint"),
438
+ )
439
+
440
+ with gr.Column(variant="compact"):
441
+ w.ad_use_vae = gr.Checkbox(
442
+ label="Use separate VAE (experimental)" + suffix(n),
443
+ value=False,
444
+ visible=True,
445
+ elem_id=eid("ad_use_vae"),
446
+ )
447
+
448
+ vaes = ["Use same VAE", *webui_info.vae_list]
449
+
450
+ w.ad_vae = gr.Dropdown(
451
+ label="ADetailer VAE" + suffix(n),
452
+ choices=vaes,
453
+ value=vaes[0],
454
+ visible=True,
455
+ elem_id=eid("ad_vae"),
456
+ )
457
+
458
+ with gr.Row(), gr.Column(variant="compact"):
459
+ w.ad_use_sampler = gr.Checkbox(
460
+ label="Use separate sampler" + suffix(n),
461
+ value=False,
462
+ visible=True,
463
+ elem_id=eid("ad_use_sampler"),
464
+ )
465
+
466
+ w.ad_sampler = gr.Dropdown(
467
+ label="ADetailer sampler" + suffix(n),
468
+ choices=webui_info.sampler_names,
469
+ value=webui_info.sampler_names[0],
470
+ visible=True,
471
+ elem_id=eid("ad_sampler"),
472
+ )
473
+
474
+ w.ad_use_sampler.change(
475
+ gr_interactive,
476
+ inputs=w.ad_use_sampler,
477
+ outputs=w.ad_sampler,
478
+ queue=False,
479
+ )
480
+
481
+ with gr.Row():
482
+ with gr.Column(variant="compact"):
483
+ w.ad_use_noise_multiplier = gr.Checkbox(
484
+ label="Use separate noise multiplier" + suffix(n),
485
+ value=False,
486
+ visible=True,
487
+ elem_id=eid("ad_use_noise_multiplier"),
488
+ )
489
+
490
+ w.ad_noise_multiplier = gr.Slider(
491
+ label="Noise multiplier for img2img" + suffix(n),
492
+ minimum=0.5,
493
+ maximum=1.5,
494
+ step=0.01,
495
+ value=1.0,
496
+ visible=True,
497
+ elem_id=eid("ad_noise_multiplier"),
498
+ )
499
+
500
+ w.ad_use_noise_multiplier.change(
501
+ gr_interactive,
502
+ inputs=w.ad_use_noise_multiplier,
503
+ outputs=w.ad_noise_multiplier,
504
+ queue=False,
505
+ )
506
+
507
+ with gr.Column(variant="compact"):
508
+ w.ad_use_clip_skip = gr.Checkbox(
509
+ label="Use separate CLIP skip" + suffix(n),
510
+ value=False,
511
+ visible=True,
512
+ elem_id=eid("ad_use_clip_skip"),
513
+ )
514
+
515
+ w.ad_clip_skip = gr.Slider(
516
+ label="ADetailer CLIP skip" + suffix(n),
517
+ minimum=1,
518
+ maximum=12,
519
+ step=1,
520
+ value=1,
521
+ visible=True,
522
+ elem_id=eid("ad_clip_skip"),
523
+ )
524
+
525
+ w.ad_use_clip_skip.change(
526
+ gr_interactive,
527
+ inputs=w.ad_use_clip_skip,
528
+ outputs=w.ad_clip_skip,
529
+ queue=False,
530
+ )
531
+
532
+ with gr.Row(), gr.Column(variant="compact"):
533
+ w.ad_restore_face = gr.Checkbox(
534
+ label="Restore faces after ADetailer" + suffix(n),
535
+ value=False,
536
+ elem_id=eid("ad_restore_face"),
537
+ )
538
+
539
+
540
+ def controlnet(w: Widgets, n: int, is_img2img: bool):
541
+ eid = partial(elem_id, n=n, is_img2img=is_img2img)
542
+ cn_models = ["None", *get_cn_models()]
543
+
544
+ with gr.Row(variant="panel"):
545
+ with gr.Column(variant="compact"):
546
+ w.ad_controlnet_model = gr.Dropdown(
547
+ label="ControlNet model" + suffix(n),
548
+ choices=cn_models,
549
+ value="None",
550
+ visible=True,
551
+ type="value",
552
+ interactive=controlnet_exists,
553
+ elem_id=eid("ad_controlnet_model"),
554
+ )
555
+
556
+ w.ad_controlnet_module = gr.Dropdown(
557
+ label="ControlNet module" + suffix(n),
558
+ choices=cn_module_choices,
559
+ value="inpaint_global_harmonious",
560
+ visible=False,
561
+ type="value",
562
+ interactive=controlnet_exists,
563
+ elem_id=eid("ad_controlnet_module"),
564
+ )
565
+
566
+ w.ad_controlnet_weight = gr.Slider(
567
+ label="ControlNet weight" + suffix(n),
568
+ minimum=0.0,
569
+ maximum=1.0,
570
+ step=0.01,
571
+ value=1.0,
572
+ visible=True,
573
+ interactive=controlnet_exists,
574
+ elem_id=eid("ad_controlnet_weight"),
575
+ )
576
+
577
+ w.ad_controlnet_model.change(
578
+ on_cn_model_update,
579
+ inputs=w.ad_controlnet_model,
580
+ outputs=w.ad_controlnet_module,
581
+ queue=False,
582
+ )
583
+
584
+ with gr.Column(variant="compact"):
585
+ w.ad_controlnet_guidance_start = gr.Slider(
586
+ label="ControlNet guidance start" + suffix(n),
587
+ minimum=0.0,
588
+ maximum=1.0,
589
+ step=0.01,
590
+ value=0.0,
591
+ visible=True,
592
+ interactive=controlnet_exists,
593
+ elem_id=eid("ad_controlnet_guidance_start"),
594
+ )
595
+
596
+ w.ad_controlnet_guidance_end = gr.Slider(
597
+ label="ControlNet guidance end" + suffix(n),
598
+ minimum=0.0,
599
+ maximum=1.0,
600
+ step=0.01,
601
+ value=1.0,
602
+ visible=True,
603
+ interactive=controlnet_exists,
604
+ elem_id=eid("ad_controlnet_guidance_end"),
605
+ )
TestingforfaivsixEx/content/eichellis/extensions/adetai/adetailer/ultralytics.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import cv2
6
+ from PIL import Image
7
+ from torchvision.transforms.functional import to_pil_image
8
+ from ultralytics import YOLO
9
+
10
+ from adetailer import PredictOutput
11
+ from adetailer.common import create_mask_from_bbox
12
+
13
+
14
+ def ultralytics_predict(
15
+ model_path: str | Path,
16
+ image: Image.Image,
17
+ confidence: float = 0.3,
18
+ device: str = "",
19
+ ) -> PredictOutput:
20
+ model = YOLO(model_path)
21
+ pred = model(image, conf=confidence, device=device)
22
+
23
+ bboxes = pred[0].boxes.xyxy.cpu().numpy()
24
+ if bboxes.size == 0:
25
+ return PredictOutput()
26
+ bboxes = bboxes.tolist()
27
+
28
+ if pred[0].masks is None:
29
+ masks = create_mask_from_bbox(bboxes, image.size)
30
+ else:
31
+ masks = mask_to_pil(pred[0].masks.data, image.size)
32
+ preview = pred[0].plot()
33
+ preview = cv2.cvtColor(preview, cv2.COLOR_BGR2RGB)
34
+ preview = Image.fromarray(preview)
35
+
36
+ return PredictOutput(bboxes=bboxes, masks=masks, preview=preview)
37
+
38
+
39
+ def mask_to_pil(masks, shape: tuple[int, int]) -> list[Image.Image]:
40
+ """
41
+ Parameters
42
+ ----------
43
+ masks: torch.Tensor, dtype=torch.float32, shape=(N, H, W).
44
+ The device can be CUDA, but `to_pil_image` takes care of that.
45
+
46
+ shape: tuple[int, int]
47
+ (width, height) of the original image
48
+ """
49
+ n = masks.shape[0]
50
+ return [to_pil_image(masks[i], mode="L").resize(shape) for i in range(n)]
TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/__init__.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from .controlnet_ext import ControlNetExt, controlnet_exists, get_cn_models
2
+
3
+ __all__ = [
4
+ "ControlNetExt",
5
+ "controlnet_exists",
6
+ "get_cn_models",
7
+ ]
TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/controlnet_ext.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import importlib
4
+ import re
5
+ from functools import lru_cache
6
+ from pathlib import Path
7
+
8
+ from modules import extensions, sd_models, shared
9
+ from modules.paths import data_path, models_path, script_path
10
+
11
+ ext_path = Path(data_path, "extensions")
12
+ ext_builtin_path = Path(script_path, "extensions-builtin")
13
+ controlnet_exists = False
14
+ controlnet_path = None
15
+ cn_base_path = ""
16
+
17
+ for extension in extensions.active():
18
+ if not extension.enabled:
19
+ continue
20
+ # For cases like sd-webui-controlnet-master
21
+ if "sd-webui-controlnet" in extension.name:
22
+ controlnet_exists = True
23
+ controlnet_path = Path(extension.path)
24
+ cn_base_path = ".".join(controlnet_path.parts[-2:])
25
+ break
26
+
27
+ cn_model_module = {
28
+ "inpaint": "inpaint_global_harmonious",
29
+ "scribble": "t2ia_sketch_pidi",
30
+ "lineart": "lineart_coarse",
31
+ "openpose": "openpose_full",
32
+ "tile": None,
33
+ }
34
+ cn_model_regex = re.compile("|".join(cn_model_module.keys()))
35
+
36
+
37
+ class ControlNetExt:
38
+ def __init__(self):
39
+ self.cn_models = ["None"]
40
+ self.cn_available = False
41
+ self.external_cn = None
42
+
43
+ def init_controlnet(self):
44
+ import_path = cn_base_path + ".scripts.external_code"
45
+
46
+ self.external_cn = importlib.import_module(import_path, "external_code")
47
+ self.cn_available = True
48
+ models = self.external_cn.get_models()
49
+ self.cn_models.extend(m for m in models if cn_model_regex.search(m))
50
+
51
+ def update_scripts_args(
52
+ self,
53
+ p,
54
+ model: str,
55
+ module: str | None,
56
+ weight: float,
57
+ guidance_start: float,
58
+ guidance_end: float,
59
+ ):
60
+ if (not self.cn_available) or model == "None":
61
+ return
62
+
63
+ if module is None:
64
+ for m, v in cn_model_module.items():
65
+ if m in model:
66
+ module = v
67
+ break
68
+
69
+ cn_units = [
70
+ self.external_cn.ControlNetUnit(
71
+ model=model,
72
+ weight=weight,
73
+ control_mode=self.external_cn.ControlMode.BALANCED,
74
+ module=module,
75
+ guidance_start=guidance_start,
76
+ guidance_end=guidance_end,
77
+ pixel_perfect=True,
78
+ )
79
+ ]
80
+
81
+ self.external_cn.update_cn_script_in_processing(p, cn_units)
82
+
83
+
84
+ def get_cn_model_dirs() -> list[Path]:
85
+ cn_model_dir = Path(models_path, "ControlNet")
86
+ if controlnet_path is not None:
87
+ cn_model_dir_old = controlnet_path.joinpath("models")
88
+ else:
89
+ cn_model_dir_old = None
90
+ ext_dir1 = shared.opts.data.get("control_net_models_path", "")
91
+ ext_dir2 = getattr(shared.cmd_opts, "controlnet_dir", "")
92
+
93
+ dirs = [cn_model_dir]
94
+ for ext_dir in [cn_model_dir_old, ext_dir1, ext_dir2]:
95
+ if ext_dir:
96
+ dirs.append(Path(ext_dir))
97
+
98
+ return dirs
99
+
100
+
101
+ @lru_cache
102
+ def _get_cn_models() -> list[str]:
103
+ """
104
+ Since we can't import ControlNet, we use a function that does something like
105
+ controlnet's `list(global_state.cn_models_names.values())`.
106
+ """
107
+ cn_model_exts = (".pt", ".pth", ".ckpt", ".safetensors")
108
+ dirs = get_cn_model_dirs()
109
+ name_filter = shared.opts.data.get("control_net_models_name_filter", "")
110
+ name_filter = name_filter.strip(" ").lower()
111
+
112
+ model_paths = []
113
+
114
+ for base in dirs:
115
+ if not base.exists():
116
+ continue
117
+
118
+ for p in base.rglob("*"):
119
+ if (
120
+ p.is_file()
121
+ and p.suffix in cn_model_exts
122
+ and cn_model_regex.search(p.name)
123
+ ):
124
+ if name_filter and name_filter not in p.name.lower():
125
+ continue
126
+ model_paths.append(p)
127
+ model_paths.sort(key=lambda p: p.name)
128
+
129
+ models = []
130
+ for p in model_paths:
131
+ model_hash = sd_models.model_hash(p)
132
+ name = f"{p.stem} [{model_hash}]"
133
+ models.append(name)
134
+ return models
135
+
136
+
137
+ def get_cn_models() -> list[str]:
138
+ if controlnet_exists:
139
+ return _get_cn_models()
140
+ return []
TestingforfaivsixEx/content/eichellis/extensions/adetai/controlnet_ext/restore.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from contextlib import contextmanager
4
+
5
+ from modules import img2img, processing, shared
6
+
7
+
8
+ class CNHijackRestore:
9
+ def __init__(self):
10
+ self.process = hasattr(processing, "__controlnet_original_process_images_inner")
11
+ self.img2img = hasattr(img2img, "__controlnet_original_process_batch")
12
+
13
+ def __enter__(self):
14
+ if self.process:
15
+ self.orig_process = processing.process_images_inner
16
+ processing.process_images_inner = getattr(
17
+ processing, "__controlnet_original_process_images_inner"
18
+ )
19
+ if self.img2img:
20
+ self.orig_img2img = img2img.process_batch
21
+ img2img.process_batch = getattr(
22
+ img2img, "__controlnet_original_process_batch"
23
+ )
24
+
25
+ def __exit__(self, *args, **kwargs):
26
+ if self.process:
27
+ processing.process_images_inner = self.orig_process
28
+ if self.img2img:
29
+ img2img.process_batch = self.orig_img2img
30
+
31
+
32
+ @contextmanager
33
+ def cn_allow_script_control():
34
+ orig = False
35
+ if "control_net_allow_script_control" in shared.opts.data:
36
+ try:
37
+ orig = shared.opts.data["control_net_allow_script_control"]
38
+ shared.opts.data["control_net_allow_script_control"] = True
39
+ yield
40
+ finally:
41
+ shared.opts.data["control_net_allow_script_control"] = orig
42
+ else:
43
+ yield
TestingforfaivsixEx/content/eichellis/extensions/adetai/install.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+ import subprocess
5
+ import sys
6
+ from importlib.metadata import version # python >= 3.8
7
+
8
+ from packaging.version import parse
9
+
10
+ import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"}
11
+
12
+
13
+ def is_installed(
14
+ package: str, min_version: str | None = None, max_version: str | None = None
15
+ ):
16
+ name = import_name.get(package, package)
17
+ try:
18
+ spec = importlib.util.find_spec(name)
19
+ except ModuleNotFoundError:
20
+ return False
21
+
22
+ if spec is None:
23
+ return False
24
+
25
+ if not min_version and not max_version:
26
+ return True
27
+
28
+ if not min_version:
29
+ min_version = "0.0.0"
30
+ if not max_version:
31
+ max_version = "99999999.99999999.99999999"
32
+
33
+ try:
34
+ pkg_version = version(package)
35
+ return parse(min_version) <= parse(pkg_version) <= parse(max_version)
36
+ except Exception:
37
+ return False
38
+
39
+
40
+ def run_pip(*args):
41
+ subprocess.run([sys.executable, "-m", "pip", "install", *args])
42
+
43
+
44
+ def install():
45
+ deps = [
46
+ # requirements
47
+ ("ultralytics", "8.0.173", None),
48
+ ("mediapipe", "0.10.3", None),
49
+ ("rich", "13.0.0", None),
50
+ # mediapipe
51
+ ("protobuf", "3.20", "3.9999"),
52
+ ]
53
+
54
+ for pkg, low, high in deps:
55
+ if not is_installed(pkg, low, high):
56
+ if low and high:
57
+ cmd = f"{pkg}>={low},<={high}"
58
+ elif low:
59
+ cmd = f"{pkg}>={low}"
60
+ elif high:
61
+ cmd = f"{pkg}<={high}"
62
+ else:
63
+ cmd = pkg
64
+
65
+ run_pip("-U", cmd)
66
+
67
+
68
+ try:
69
+ import launch
70
+
71
+ skip_install = launch.args.skip_install
72
+ except Exception:
73
+ skip_install = False
74
+
75
+ if not skip_install:
76
+ install()
TestingforfaivsixEx/content/eichellis/extensions/adetai/preload.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+
4
+ def preload(parser: argparse.ArgumentParser):
5
+ parser.add_argument(
6
+ "--ad-no-huggingface",
7
+ action="store_true",
8
+ help="Don't use adetailer models from huggingface",
9
+ )
TestingforfaivsixEx/content/eichellis/extensions/adetai/pyproject.toml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "adetailer"
3
+ description = "An object detection and auto-mask extension for stable diffusion webui."
4
+ authors = [{ name = "dowon", email = "ks2515@naver.com" }]
5
+ requires-python = ">=3.8,<3.12"
6
+ readme = "README.md"
7
+ license = { text = "AGPL-3.0" }
8
+
9
+ [project.urls]
10
+ repository = "https://github.com/Bing-su/adetailer"
11
+
12
+ [tool.isort]
13
+ profile = "black"
14
+ known_first_party = ["launch", "modules"]
15
+
16
+ [tool.ruff]
17
+ select = [
18
+ "A",
19
+ "B",
20
+ "C4",
21
+ "C90",
22
+ "E",
23
+ "EM",
24
+ "F",
25
+ "FA",
26
+ "I001",
27
+ "ISC",
28
+ "N",
29
+ "PIE",
30
+ "PT",
31
+ "RET",
32
+ "RUF",
33
+ "SIM",
34
+ "UP",
35
+ "W",
36
+ ]
37
+ ignore = ["B008", "B905", "E501", "F401", "UP007"]
38
+
39
+ [tool.ruff.isort]
40
+ known-first-party = ["launch", "modules"]
TestingforfaivsixEx/content/eichellis/extensions/adetai/scripts/!adetailer.py ADDED
@@ -0,0 +1,834 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import platform
5
+ import re
6
+ import sys
7
+ import traceback
8
+ from contextlib import contextmanager
9
+ from copy import copy, deepcopy
10
+ from functools import partial
11
+ from pathlib import Path
12
+ from textwrap import dedent
13
+ from typing import Any
14
+
15
+ import gradio as gr
16
+ import torch
17
+ from rich import print
18
+
19
+ import modules
20
+ from adetailer import (
21
+ AFTER_DETAILER,
22
+ __version__,
23
+ get_models,
24
+ mediapipe_predict,
25
+ ultralytics_predict,
26
+ )
27
+ from adetailer.args import ALL_ARGS, BBOX_SORTBY, ADetailerArgs, EnableChecker
28
+ from adetailer.common import PredictOutput
29
+ from adetailer.mask import (
30
+ filter_by_ratio,
31
+ filter_k_largest,
32
+ mask_preprocess,
33
+ sort_bboxes,
34
+ )
35
+ from adetailer.traceback import rich_traceback
36
+ from adetailer.ui import WebuiInfo, adui, ordinal, suffix
37
+ from controlnet_ext import ControlNetExt, controlnet_exists, get_cn_models
38
+ from controlnet_ext.restore import (
39
+ CNHijackRestore,
40
+ cn_allow_script_control,
41
+ )
42
+ from modules import images, safe, script_callbacks, scripts, shared
43
+ from modules.devices import NansException
44
+ from modules.paths import data_path, models_path
45
+ from modules.processing import (
46
+ Processed,
47
+ StableDiffusionProcessingImg2Img,
48
+ create_infotext,
49
+ process_images,
50
+ )
51
+ from modules.sd_samplers import all_samplers
52
+ from modules.shared import cmd_opts, opts, state
53
+
54
+ no_huggingface = getattr(cmd_opts, "ad_no_huggingface", False)
55
+ adetailer_dir = Path(models_path, "adetailer")
56
+ model_mapping = get_models(adetailer_dir, huggingface=not no_huggingface)
57
+ txt2img_submit_button = img2img_submit_button = None
58
+ SCRIPT_DEFAULT = "dynamic_prompting,dynamic_thresholding,wildcard_recursive,wildcards,lora_block_weight"
59
+
60
+ if (
61
+ not adetailer_dir.exists()
62
+ and adetailer_dir.parent.exists()
63
+ and os.access(adetailer_dir.parent, os.W_OK)
64
+ ):
65
+ adetailer_dir.mkdir()
66
+
67
+ print(
68
+ f"[-] ADetailer initialized. version: {__version__}, num models: {len(model_mapping)}"
69
+ )
70
+
71
+
72
+ @contextmanager
73
+ def change_torch_load():
74
+ orig = torch.load
75
+ try:
76
+ torch.load = safe.unsafe_torch_load
77
+ yield
78
+ finally:
79
+ torch.load = orig
80
+
81
+
82
+ @contextmanager
83
+ def pause_total_tqdm():
84
+ orig = opts.data.get("multiple_tqdm", True)
85
+ try:
86
+ opts.data["multiple_tqdm"] = False
87
+ yield
88
+ finally:
89
+ opts.data["multiple_tqdm"] = orig
90
+
91
+
92
+ @contextmanager
93
+ def preseve_prompts(p):
94
+ all_pt = copy(p.all_prompts)
95
+ all_ng = copy(p.all_negative_prompts)
96
+ try:
97
+ yield
98
+ finally:
99
+ p.all_prompts = all_pt
100
+ p.all_negative_prompts = all_ng
101
+
102
+
103
+ class AfterDetailerScript(scripts.Script):
104
+ def __init__(self):
105
+ super().__init__()
106
+ self.ultralytics_device = self.get_ultralytics_device()
107
+
108
+ self.controlnet_ext = None
109
+
110
+ def __repr__(self):
111
+ return f"{self.__class__.__name__}(version={__version__})"
112
+
113
+ def title(self):
114
+ return AFTER_DETAILER
115
+
116
+ def show(self, is_img2img):
117
+ return scripts.AlwaysVisible
118
+
119
+ def ui(self, is_img2img):
120
+ num_models = opts.data.get("ad_max_models", 2)
121
+ ad_model_list = list(model_mapping.keys())
122
+ sampler_names = [sampler.name for sampler in all_samplers]
123
+
124
+ try:
125
+ checkpoint_list = modules.sd_models.checkpoint_tiles(use_shorts=True)
126
+ except TypeError:
127
+ checkpoint_list = modules.sd_models.checkpoint_tiles()
128
+ vae_list = modules.shared_items.sd_vae_items()
129
+
130
+ webui_info = WebuiInfo(
131
+ ad_model_list=ad_model_list,
132
+ sampler_names=sampler_names,
133
+ t2i_button=txt2img_submit_button,
134
+ i2i_button=img2img_submit_button,
135
+ checkpoints_list=checkpoint_list,
136
+ vae_list=vae_list,
137
+ )
138
+
139
+ components, infotext_fields = adui(num_models, is_img2img, webui_info)
140
+
141
+ self.infotext_fields = infotext_fields
142
+ return components
143
+
144
+ def init_controlnet_ext(self) -> None:
145
+ if self.controlnet_ext is not None:
146
+ return
147
+ self.controlnet_ext = ControlNetExt()
148
+
149
+ if controlnet_exists:
150
+ try:
151
+ self.controlnet_ext.init_controlnet()
152
+ except ImportError:
153
+ error = traceback.format_exc()
154
+ print(
155
+ f"[-] ADetailer: ControlNetExt init failed:\n{error}",
156
+ file=sys.stderr,
157
+ )
158
+
159
+ def update_controlnet_args(self, p, args: ADetailerArgs) -> None:
160
+ if self.controlnet_ext is None:
161
+ self.init_controlnet_ext()
162
+
163
+ if (
164
+ self.controlnet_ext is not None
165
+ and self.controlnet_ext.cn_available
166
+ and args.ad_controlnet_model != "None"
167
+ ):
168
+ self.controlnet_ext.update_scripts_args(
169
+ p,
170
+ model=args.ad_controlnet_model,
171
+ module=args.ad_controlnet_module,
172
+ weight=args.ad_controlnet_weight,
173
+ guidance_start=args.ad_controlnet_guidance_start,
174
+ guidance_end=args.ad_controlnet_guidance_end,
175
+ )
176
+
177
+ def is_ad_enabled(self, *args_) -> bool:
178
+ arg_list = [arg for arg in args_ if isinstance(arg, dict)]
179
+ if not args_ or not arg_list or not isinstance(args_[0], (bool, dict)):
180
+ message = f"""
181
+ [-] ADetailer: Invalid arguments passed to ADetailer.
182
+ input: {args_!r}
183
+ ADetailer disabled.
184
+ """
185
+ print(dedent(message), file=sys.stderr)
186
+ return False
187
+ enable = args_[0] if isinstance(args_[0], bool) else True
188
+ checker = EnableChecker(enable=enable, arg_list=arg_list)
189
+ return checker.is_enabled()
190
+
191
+ def get_args(self, p, *args_) -> list[ADetailerArgs]:
192
+ """
193
+ `args_` is at least 1 in length by `is_ad_enabled` immediately above
194
+ """
195
+ args = [arg for arg in args_ if isinstance(arg, dict)]
196
+
197
+ if not args:
198
+ message = f"[-] ADetailer: Invalid arguments passed to ADetailer: {args_!r}"
199
+ raise ValueError(message)
200
+
201
+ if hasattr(p, "adetailer_xyz"):
202
+ args[0] = {**args[0], **p.adetailer_xyz}
203
+
204
+ all_inputs = []
205
+
206
+ for n, arg_dict in enumerate(args, 1):
207
+ try:
208
+ inp = ADetailerArgs(**arg_dict)
209
+ except ValueError as e:
210
+ msgs = [
211
+ f"[-] ADetailer: ValidationError when validating {ordinal(n)} arguments: {e}\n"
212
+ ]
213
+ for attr in ALL_ARGS.attrs:
214
+ arg = arg_dict.get(attr)
215
+ dtype = type(arg)
216
+ arg = "DEFAULT" if arg is None else repr(arg)
217
+ msgs.append(f" {attr}: {arg} ({dtype})")
218
+ raise ValueError("\n".join(msgs)) from e
219
+
220
+ all_inputs.append(inp)
221
+
222
+ return all_inputs
223
+
224
+ def extra_params(self, arg_list: list[ADetailerArgs]) -> dict:
225
+ params = {}
226
+ for n, args in enumerate(arg_list):
227
+ params.update(args.extra_params(suffix=suffix(n)))
228
+ params["ADetailer version"] = __version__
229
+ return params
230
+
231
+ @staticmethod
232
+ def get_ultralytics_device() -> str:
233
+ if "adetailer" in shared.cmd_opts.use_cpu:
234
+ return "cpu"
235
+
236
+ if platform.system() == "Darwin":
237
+ return ""
238
+
239
+ vram_args = ["lowvram", "medvram", "medvram_sdxl"]
240
+ if any(getattr(cmd_opts, vram, False) for vram in vram_args):
241
+ return "cpu"
242
+
243
+ return ""
244
+
245
+ def prompt_blank_replacement(
246
+ self, all_prompts: list[str], i: int, default: str
247
+ ) -> str:
248
+ if not all_prompts:
249
+ return default
250
+ if i < len(all_prompts):
251
+ return all_prompts[i]
252
+ j = i % len(all_prompts)
253
+ return all_prompts[j]
254
+
255
+ def _get_prompt(
256
+ self, ad_prompt: str, all_prompts: list[str], i: int, default: str
257
+ ) -> list[str]:
258
+ prompts = re.split(r"\s*\[SEP\]\s*", ad_prompt)
259
+ blank_replacement = self.prompt_blank_replacement(all_prompts, i, default)
260
+ for n in range(len(prompts)):
261
+ if not prompts[n]:
262
+ prompts[n] = blank_replacement
263
+ elif "[PROMPT]" in prompts[n]:
264
+ prompts[n] = prompts[n].replace("[PROMPT]", f" {blank_replacement} ")
265
+ return prompts
266
+
267
+ def get_prompt(self, p, args: ADetailerArgs) -> tuple[list[str], list[str]]:
268
+ i = p._ad_idx
269
+
270
+ prompt = self._get_prompt(args.ad_prompt, p.all_prompts, i, p.prompt)
271
+ negative_prompt = self._get_prompt(
272
+ args.ad_negative_prompt, p.all_negative_prompts, i, p.negative_prompt
273
+ )
274
+
275
+ return prompt, negative_prompt
276
+
277
+ def get_seed(self, p) -> tuple[int, int]:
278
+ i = p._ad_idx
279
+
280
+ if not p.all_seeds:
281
+ seed = p.seed
282
+ elif i < len(p.all_seeds):
283
+ seed = p.all_seeds[i]
284
+ else:
285
+ j = i % len(p.all_seeds)
286
+ seed = p.all_seeds[j]
287
+
288
+ if not p.all_subseeds:
289
+ subseed = p.subseed
290
+ elif i < len(p.all_subseeds):
291
+ subseed = p.all_subseeds[i]
292
+ else:
293
+ j = i % len(p.all_subseeds)
294
+ subseed = p.all_subseeds[j]
295
+
296
+ return seed, subseed
297
+
298
+ def get_width_height(self, p, args: ADetailerArgs) -> tuple[int, int]:
299
+ if args.ad_use_inpaint_width_height:
300
+ width = args.ad_inpaint_width
301
+ height = args.ad_inpaint_height
302
+ else:
303
+ width = p.width
304
+ height = p.height
305
+
306
+ return width, height
307
+
308
+ def get_steps(self, p, args: ADetailerArgs) -> int:
309
+ return args.ad_steps if args.ad_use_steps else p.steps
310
+
311
+ def get_cfg_scale(self, p, args: ADetailerArgs) -> float:
312
+ return args.ad_cfg_scale if args.ad_use_cfg_scale else p.cfg_scale
313
+
314
+ def get_sampler(self, p, args: ADetailerArgs) -> str:
315
+ return args.ad_sampler if args.ad_use_sampler else p.sampler_name
316
+
317
+ def get_override_settings(self, p, args: ADetailerArgs) -> dict[str, Any]:
318
+ d = {}
319
+
320
+ if args.ad_use_clip_skip:
321
+ d["CLIP_stop_at_last_layers"] = args.ad_clip_skip
322
+
323
+ if (
324
+ args.ad_use_checkpoint
325
+ and args.ad_checkpoint
326
+ and args.ad_checkpoint not in ("None", "Use same checkpoint")
327
+ ):
328
+ d["sd_model_checkpoint"] = args.ad_checkpoint
329
+
330
+ if (
331
+ args.ad_use_vae
332
+ and args.ad_vae
333
+ and args.ad_vae not in ("None", "Use same VAE")
334
+ ):
335
+ d["sd_vae"] = args.ad_vae
336
+ return d
337
+
338
+ def get_initial_noise_multiplier(self, p, args: ADetailerArgs) -> float | None:
339
+ return args.ad_noise_multiplier if args.ad_use_noise_multiplier else None
340
+
341
+ @staticmethod
342
+ def infotext(p) -> str:
343
+ return create_infotext(
344
+ p, p.all_prompts, p.all_seeds, p.all_subseeds, None, 0, 0
345
+ )
346
+
347
+ def write_params_txt(self, p) -> None:
348
+ infotext = self.infotext(p)
349
+ params_txt = Path(data_path, "params.txt")
350
+ params_txt.write_text(infotext, encoding="utf-8")
351
+
352
+ def script_filter(self, p, args: ADetailerArgs):
353
+ script_runner = copy(p.scripts)
354
+ script_args = deepcopy(p.script_args)
355
+ self.disable_controlnet_units(script_args)
356
+
357
+ ad_only_seleted_scripts = opts.data.get("ad_only_seleted_scripts", True)
358
+ if not ad_only_seleted_scripts:
359
+ return script_runner, script_args
360
+
361
+ ad_script_names = opts.data.get("ad_script_names", SCRIPT_DEFAULT)
362
+ script_names_set = {
363
+ name
364
+ for script_name in ad_script_names.split(",")
365
+ for name in (script_name, script_name.strip())
366
+ }
367
+
368
+ if args.ad_controlnet_model != "None":
369
+ script_names_set.add("controlnet")
370
+
371
+ filtered_alwayson = []
372
+ for script_object in script_runner.alwayson_scripts:
373
+ filepath = script_object.filename
374
+ filename = Path(filepath).stem
375
+ if filename in script_names_set:
376
+ filtered_alwayson.append(script_object)
377
+
378
+ script_runner.alwayson_scripts = filtered_alwayson
379
+ return script_runner, script_args
380
+
381
+ def disable_controlnet_units(self, script_args: list[Any]) -> None:
382
+ for obj in script_args:
383
+ if "controlnet" in obj.__class__.__name__.lower():
384
+ if hasattr(obj, "enabled"):
385
+ obj.enabled = False
386
+ if hasattr(obj, "input_mode"):
387
+ obj.input_mode = getattr(obj.input_mode, "SIMPLE", "simple")
388
+
389
+ elif isinstance(obj, dict) and "module" in obj:
390
+ obj["enabled"] = False
391
+
392
+ def get_i2i_p(self, p, args: ADetailerArgs, image):
393
+ seed, subseed = self.get_seed(p)
394
+ width, height = self.get_width_height(p, args)
395
+ steps = self.get_steps(p, args)
396
+ cfg_scale = self.get_cfg_scale(p, args)
397
+ initial_noise_multiplier = self.get_initial_noise_multiplier(p, args)
398
+ sampler_name = self.get_sampler(p, args)
399
+ override_settings = self.get_override_settings(p, args)
400
+
401
+ i2i = StableDiffusionProcessingImg2Img(
402
+ init_images=[image],
403
+ resize_mode=0,
404
+ denoising_strength=args.ad_denoising_strength,
405
+ mask=None,
406
+ mask_blur=args.ad_mask_blur,
407
+ inpainting_fill=1,
408
+ inpaint_full_res=args.ad_inpaint_only_masked,
409
+ inpaint_full_res_padding=args.ad_inpaint_only_masked_padding,
410
+ inpainting_mask_invert=0,
411
+ initial_noise_multiplier=initial_noise_multiplier,
412
+ sd_model=p.sd_model,
413
+ outpath_samples=p.outpath_samples,
414
+ outpath_grids=p.outpath_grids,
415
+ prompt="", # replace later
416
+ negative_prompt="",
417
+ styles=p.styles,
418
+ seed=seed,
419
+ subseed=subseed,
420
+ subseed_strength=p.subseed_strength,
421
+ seed_resize_from_h=p.seed_resize_from_h,
422
+ seed_resize_from_w=p.seed_resize_from_w,
423
+ sampler_name=sampler_name,
424
+ batch_size=1,
425
+ n_iter=1,
426
+ steps=steps,
427
+ cfg_scale=cfg_scale,
428
+ width=width,
429
+ height=height,
430
+ restore_faces=args.ad_restore_face,
431
+ tiling=p.tiling,
432
+ extra_generation_params=p.extra_generation_params,
433
+ do_not_save_samples=True,
434
+ do_not_save_grid=True,
435
+ override_settings=override_settings,
436
+ )
437
+
438
+ i2i.cached_c = [None, None]
439
+ i2i.cached_uc = [None, None]
440
+ i2i.scripts, i2i.script_args = self.script_filter(p, args)
441
+ i2i._ad_disabled = True
442
+
443
+ if args.ad_controlnet_model != "None":
444
+ self.update_controlnet_args(i2i, args)
445
+ else:
446
+ i2i.control_net_enabled = False
447
+
448
+ return i2i
449
+
450
+ def save_image(self, p, image, *, condition: str, suffix: str) -> None:
451
+ i = p._ad_idx
452
+ if p.all_prompts:
453
+ i %= len(p.all_prompts)
454
+ save_prompt = p.all_prompts[i]
455
+ else:
456
+ save_prompt = p.prompt
457
+ seed, _ = self.get_seed(p)
458
+
459
+ if opts.data.get(condition, False):
460
+ images.save_image(
461
+ image=image,
462
+ path=p.outpath_samples,
463
+ basename="",
464
+ seed=seed,
465
+ prompt=save_prompt,
466
+ extension=opts.samples_format,
467
+ info=self.infotext(p),
468
+ p=p,
469
+ suffix=suffix,
470
+ )
471
+
472
+ def get_ad_model(self, name: str):
473
+ if name not in model_mapping:
474
+ msg = f"[-] ADetailer: Model {name!r} not found. Available models: {list(model_mapping.keys())}"
475
+ raise ValueError(msg)
476
+ return model_mapping[name]
477
+
478
+ def sort_bboxes(self, pred: PredictOutput) -> PredictOutput:
479
+ sortby = opts.data.get("ad_bbox_sortby", BBOX_SORTBY[0])
480
+ sortby_idx = BBOX_SORTBY.index(sortby)
481
+ return sort_bboxes(pred, sortby_idx)
482
+
483
+ def pred_preprocessing(self, pred: PredictOutput, args: ADetailerArgs):
484
+ pred = filter_by_ratio(
485
+ pred, low=args.ad_mask_min_ratio, high=args.ad_mask_max_ratio
486
+ )
487
+ pred = filter_k_largest(pred, k=args.ad_mask_k_largest)
488
+ pred = self.sort_bboxes(pred)
489
+ return mask_preprocess(
490
+ pred.masks,
491
+ kernel=args.ad_dilate_erode,
492
+ x_offset=args.ad_x_offset,
493
+ y_offset=args.ad_y_offset,
494
+ merge_invert=args.ad_mask_merge_invert,
495
+ )
496
+
497
+ @staticmethod
498
+ def ensure_rgb_image(image: Any):
499
+ if hasattr(image, "mode") and image.mode != "RGB":
500
+ image = image.convert("RGB")
501
+ return image
502
+
503
+ @staticmethod
504
+ def i2i_prompts_replace(
505
+ i2i, prompts: list[str], negative_prompts: list[str], j: int
506
+ ) -> None:
507
+ i1 = min(j, len(prompts) - 1)
508
+ i2 = min(j, len(negative_prompts) - 1)
509
+ prompt = prompts[i1]
510
+ negative_prompt = negative_prompts[i2]
511
+ i2i.prompt = prompt
512
+ i2i.negative_prompt = negative_prompt
513
+
514
+ @staticmethod
515
+ def compare_prompt(p, processed, n: int = 0):
516
+ if p.prompt != processed.all_prompts[0]:
517
+ print(
518
+ f"[-] ADetailer: applied {ordinal(n + 1)} ad_prompt: {processed.all_prompts[0]!r}"
519
+ )
520
+
521
+ if p.negative_prompt != processed.all_negative_prompts[0]:
522
+ print(
523
+ f"[-] ADetailer: applied {ordinal(n + 1)} ad_negative_prompt: {processed.all_negative_prompts[0]!r}"
524
+ )
525
+
526
+ @staticmethod
527
+ def need_call_process(p) -> bool:
528
+ i = p._ad_idx
529
+ bs = p.batch_size
530
+ return i % bs == bs - 1
531
+
532
+ @staticmethod
533
+ def need_call_postprocess(p) -> bool:
534
+ i = p._ad_idx
535
+ bs = p.batch_size
536
+ return i % bs == 0
537
+
538
+ @rich_traceback
539
+ def process(self, p, *args_):
540
+ if getattr(p, "_ad_disabled", False):
541
+ return
542
+
543
+ if self.is_ad_enabled(*args_):
544
+ arg_list = self.get_args(p, *args_)
545
+ extra_params = self.extra_params(arg_list)
546
+ p.extra_generation_params.update(extra_params)
547
+
548
+ def _postprocess_image_inner(
549
+ self, p, pp, args: ADetailerArgs, *, n: int = 0
550
+ ) -> bool:
551
+ """
552
+ Returns
553
+ -------
554
+ bool
555
+
556
+ `True` if image was processed, `False` otherwise.
557
+ """
558
+ if state.interrupted or state.skipped:
559
+ return False
560
+
561
+ i = p._ad_idx
562
+
563
+ i2i = self.get_i2i_p(p, args, pp.image)
564
+ seed, subseed = self.get_seed(p)
565
+ ad_prompts, ad_negatives = self.get_prompt(p, args)
566
+
567
+ is_mediapipe = args.ad_model.lower().startswith("mediapipe")
568
+
569
+ kwargs = {}
570
+ if is_mediapipe:
571
+ predictor = mediapipe_predict
572
+ ad_model = args.ad_model
573
+ else:
574
+ predictor = ultralytics_predict
575
+ ad_model = self.get_ad_model(args.ad_model)
576
+ kwargs["device"] = self.ultralytics_device
577
+
578
+ with change_torch_load():
579
+ pred = predictor(ad_model, pp.image, args.ad_confidence, **kwargs)
580
+
581
+ masks = self.pred_preprocessing(pred, args)
582
+
583
+ if not masks:
584
+ print(
585
+ f"[-] ADetailer: nothing detected on image {i + 1} with {ordinal(n + 1)} settings."
586
+ )
587
+ return False
588
+
589
+ self.save_image(
590
+ p,
591
+ pred.preview,
592
+ condition="ad_save_previews",
593
+ suffix="-ad-preview" + suffix(n, "-"),
594
+ )
595
+
596
+ steps = len(masks)
597
+ processed = None
598
+ state.job_count += steps
599
+
600
+ if is_mediapipe:
601
+ print(f"mediapipe: {steps} detected.")
602
+
603
+ p2 = copy(i2i)
604
+ for j in range(steps):
605
+ p2.image_mask = masks[j]
606
+ p2.init_images[0] = self.ensure_rgb_image(p2.init_images[0])
607
+ self.i2i_prompts_replace(p2, ad_prompts, ad_negatives, j)
608
+
609
+ if re.match(r"^\s*\[SKIP\]\s*$", p2.prompt):
610
+ continue
611
+
612
+ p2.seed = seed + j
613
+ p2.subseed = subseed + j
614
+
615
+ try:
616
+ processed = process_images(p2)
617
+ except NansException as e:
618
+ msg = f"[-] ADetailer: 'NansException' occurred with {ordinal(n + 1)} settings.\n{e}"
619
+ print(msg, file=sys.stderr)
620
+ continue
621
+ finally:
622
+ p2.close()
623
+
624
+ self.compare_prompt(p2, processed, n=n)
625
+ p2 = copy(i2i)
626
+ p2.init_images = [processed.images[0]]
627
+
628
+ if processed is not None:
629
+ pp.image = processed.images[0]
630
+ return True
631
+
632
+ return False
633
+
634
+ @rich_traceback
635
+ def postprocess_image(self, p, pp, *args_):
636
+ if getattr(p, "_ad_disabled", False):
637
+ return
638
+
639
+ if not self.is_ad_enabled(*args_):
640
+ return
641
+
642
+ p._ad_idx = getattr(p, "_ad_idx", -1) + 1
643
+ init_image = copy(pp.image)
644
+ arg_list = self.get_args(p, *args_)
645
+
646
+ if p.scripts is not None and self.need_call_postprocess(p):
647
+ dummy = Processed(p, [], p.seed, "")
648
+ with preseve_prompts(p):
649
+ p.scripts.postprocess(copy(p), dummy)
650
+
651
+ is_processed = False
652
+ with CNHijackRestore(), pause_total_tqdm(), cn_allow_script_control():
653
+ for n, args in enumerate(arg_list):
654
+ if args.ad_model == "None":
655
+ continue
656
+ is_processed |= self._postprocess_image_inner(p, pp, args, n=n)
657
+
658
+ if is_processed:
659
+ self.save_image(
660
+ p, init_image, condition="ad_save_images_before", suffix="-ad-before"
661
+ )
662
+
663
+ if p.scripts is not None and self.need_call_process(p):
664
+ with preseve_prompts(p):
665
+ p.scripts.process(copy(p))
666
+
667
+ try:
668
+ ia = p._ad_idx
669
+ lenp = len(p.all_prompts)
670
+ if ia % lenp == lenp - 1:
671
+ self.write_params_txt(p)
672
+ except Exception:
673
+ pass
674
+
675
+
676
+ def on_after_component(component, **_kwargs):
677
+ global txt2img_submit_button, img2img_submit_button
678
+ if getattr(component, "elem_id", None) == "txt2img_generate":
679
+ txt2img_submit_button = component
680
+ return
681
+
682
+ if getattr(component, "elem_id", None) == "img2img_generate":
683
+ img2img_submit_button = component
684
+
685
+
686
+ def on_ui_settings():
687
+ section = ("ADetailer", AFTER_DETAILER)
688
+ shared.opts.add_option(
689
+ "ad_max_models",
690
+ shared.OptionInfo(
691
+ default=2,
692
+ label="Max models",
693
+ component=gr.Slider,
694
+ component_args={"minimum": 1, "maximum": 10, "step": 1},
695
+ section=section,
696
+ ),
697
+ )
698
+
699
+ shared.opts.add_option(
700
+ "ad_save_previews",
701
+ shared.OptionInfo(False, "Save mask previews", section=section),
702
+ )
703
+
704
+ shared.opts.add_option(
705
+ "ad_save_images_before",
706
+ shared.OptionInfo(False, "Save images before ADetailer", section=section),
707
+ )
708
+
709
+ shared.opts.add_option(
710
+ "ad_only_seleted_scripts",
711
+ shared.OptionInfo(
712
+ True, "Apply only selected scripts to ADetailer", section=section
713
+ ),
714
+ )
715
+
716
+ textbox_args = {
717
+ "placeholder": "comma-separated list of script names",
718
+ "interactive": True,
719
+ }
720
+
721
+ shared.opts.add_option(
722
+ "ad_script_names",
723
+ shared.OptionInfo(
724
+ default=SCRIPT_DEFAULT,
725
+ label="Script names to apply to ADetailer (separated by comma)",
726
+ component=gr.Textbox,
727
+ component_args=textbox_args,
728
+ section=section,
729
+ ),
730
+ )
731
+
732
+ shared.opts.add_option(
733
+ "ad_bbox_sortby",
734
+ shared.OptionInfo(
735
+ default="None",
736
+ label="Sort bounding boxes by",
737
+ component=gr.Radio,
738
+ component_args={"choices": BBOX_SORTBY},
739
+ section=section,
740
+ ),
741
+ )
742
+
743
+
744
+ # xyz_grid
745
+
746
+
747
+ def make_axis_on_xyz_grid():
748
+ xyz_grid = None
749
+ for script in scripts.scripts_data:
750
+ if script.script_class.__module__ == "xyz_grid.py":
751
+ xyz_grid = script.module
752
+ break
753
+
754
+ if xyz_grid is None:
755
+ return
756
+
757
+ model_list = ["None", *model_mapping.keys()]
758
+ samplers = [sampler.name for sampler in all_samplers]
759
+
760
+ def set_value(p, x, xs, *, field: str):
761
+ if not hasattr(p, "adetailer_xyz"):
762
+ p.adetailer_xyz = {}
763
+ p.adetailer_xyz[field] = x
764
+
765
+ axis = [
766
+ xyz_grid.AxisOption(
767
+ "[ADetailer] ADetailer model 1st",
768
+ str,
769
+ partial(set_value, field="ad_model"),
770
+ choices=lambda: model_list,
771
+ ),
772
+ xyz_grid.AxisOption(
773
+ "[ADetailer] ADetailer prompt 1st",
774
+ str,
775
+ partial(set_value, field="ad_prompt"),
776
+ ),
777
+ xyz_grid.AxisOption(
778
+ "[ADetailer] ADetailer negative prompt 1st",
779
+ str,
780
+ partial(set_value, field="ad_negative_prompt"),
781
+ ),
782
+ xyz_grid.AxisOption(
783
+ "[ADetailer] Mask erosion / dilation 1st",
784
+ int,
785
+ partial(set_value, field="ad_dilate_erode"),
786
+ ),
787
+ xyz_grid.AxisOption(
788
+ "[ADetailer] Inpaint denoising strength 1st",
789
+ float,
790
+ partial(set_value, field="ad_denoising_strength"),
791
+ ),
792
+ xyz_grid.AxisOption(
793
+ "[ADetailer] Inpaint only masked 1st",
794
+ str,
795
+ partial(set_value, field="ad_inpaint_only_masked"),
796
+ choices=lambda: ["True", "False"],
797
+ ),
798
+ xyz_grid.AxisOption(
799
+ "[ADetailer] Inpaint only masked padding 1st",
800
+ int,
801
+ partial(set_value, field="ad_inpaint_only_masked_padding"),
802
+ ),
803
+ xyz_grid.AxisOption(
804
+ "[ADetailer] ADetailer sampler 1st",
805
+ str,
806
+ partial(set_value, field="ad_sampler"),
807
+ choices=lambda: samplers,
808
+ ),
809
+ xyz_grid.AxisOption(
810
+ "[ADetailer] ControlNet model 1st",
811
+ str,
812
+ partial(set_value, field="ad_controlnet_model"),
813
+ choices=lambda: ["None", *get_cn_models()],
814
+ ),
815
+ ]
816
+
817
+ if not any(x.label.startswith("[ADetailer]") for x in xyz_grid.axis_options):
818
+ xyz_grid.axis_options.extend(axis)
819
+
820
+
821
+ def on_before_ui():
822
+ try:
823
+ make_axis_on_xyz_grid()
824
+ except Exception:
825
+ error = traceback.format_exc()
826
+ print(
827
+ f"[-] ADetailer: xyz_grid error:\n{error}",
828
+ file=sys.stderr,
829
+ )
830
+
831
+
832
+ script_callbacks.on_ui_settings(on_ui_settings)
833
+ script_callbacks.on_after_component(on_after_component)
834
+ script_callbacks.on_before_ui(on_before_ui)
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.github/workflows/pytest.yml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ matrix:
14
+ python-version: ['3.11', '3.10']
15
+
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v2
19
+
20
+ - name: Set up Python ${{ matrix.python-version }}
21
+ uses: actions/setup-python@v2
22
+ with:
23
+ python-version: ${{ matrix.python-version }}
24
+
25
+ - name: Install dependencies
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ pip install tox
29
+
30
+ - name: Run tox
31
+ run: tox
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .idea
2
+ .pytest_cache
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/.pre-commit-config.yaml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.4.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: debug-statements
9
+ - id: double-quote-string-fixer
10
+ - id: name-tests-test
11
+ - repo: https://github.com/asottile/reorder_python_imports
12
+ rev: v3.9.0
13
+ hooks:
14
+ - id: reorder-python-imports
15
+ args: [--py37-plus, --add-import, "from __future__ import annotations"]
16
+ - repo: https://github.com/asottile/add-trailing-comma
17
+ rev: v2.4.0
18
+ hooks:
19
+ - id: add-trailing-comma
20
+ args: [--py36-plus]
21
+ - repo: https://github.com/asottile/pyupgrade
22
+ rev: v3.3.2
23
+ hooks:
24
+ - id: pyupgrade
25
+ args: [--py37-plus]
26
+ - repo: https://github.com/pre-commit/mirrors-autopep8
27
+ rev: v2.0.2
28
+ hooks:
29
+ - id: autopep8
30
+ - repo: https://github.com/PyCQA/flake8
31
+ rev: 6.0.0
32
+ hooks:
33
+ - id: flake8
34
+ args:
35
+ - --max-line-length=120
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Aspect Ratio Helper [![pytest](https://github.com/thomasasfk/sd-webui-aspect-ratio-helper/actions/workflows/pytest.yml/badge.svg?branch=main)](https://github.com/thomasasfk/sd-webui-aspect-ratio-helper/actions/workflows/pytest.yml)
2
+
3
+ Simple extension to easily maintain aspect ratio while changing dimensions.
4
+
5
+ Install via the extensions tab on the [AUTOMATIC1111 webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui).
6
+
7
+ ## Features
8
+
9
+ **(note this list is a little out of date, will need to find time to update it)**
10
+
11
+ - JavaScript aspect ratio controls
12
+ - Adds a dropdown of configurable aspect ratios, to which the dimensions will auto-scale
13
+ - When selected, you will only be able to modify the higher dimension
14
+ - The smaller or equivalent dimension will scale accordingly
15
+ - If "Lock/🔒" is selected, the aspect ratio of the current dimensions will be kept
16
+ - If "Image/🖼️" is selected, the aspect ratio of the current image will be kept (img2img only)
17
+ - If you click the "Swap/⇅" button, the current dimensions will swap
18
+ - Configurable aspect ratios will also flip, reducing the need for duplication of config
19
+
20
+ https://user-images.githubusercontent.com/22506439/227396634-7a63671a-fd38-419a-b734-a3d26647cc1d.mp4
21
+
22
+ <br/>
23
+
24
+ - Scale to maximum dimension
25
+ - Upon clicking, the width and height will scale according to the configured maximum value
26
+ - Aspect ratio will be retained, the smaller or equivalent dimension will be scaled to match
27
+ - Scale to aspect ratio
28
+ - Upon clicking, the current dimensions will be scaled to the given aspect ratio, using the highest width or height
29
+ - i.e `4:3 of 256x512 = 512x384` `9:16 of 512x256 = 288x512` `1:1 of 256x300 = 300x300`
30
+ - You can optionally toggle this to use the "Maximum dimension" slider value
31
+ - i.e `4:3 of 512 = 512x384` `9:16 of 512 = 288x512` `1:1 of 300 = 300x300`
32
+ - Scale by percentage
33
+ - Upon clicking, the current dimensions will be multiplied by the given percentage, with aspect ratio maintained
34
+ - i.e `-25% of 512x256 = 384x192` `+50% of 512x512 = 768x768`
35
+ - You can also change the display of these if you find it more intuitive
36
+ - i.e `75% of 512x256 = 384x192` `150% of 512x512 = 768x768`
37
+ - i.e `x0.75 of 512x256 = 384x192` `x1.5 of 512x512 = 768x768`
38
+
39
+ ![user-interface.png](docs%2Fui.png)
40
+
41
+ ## Settings
42
+
43
+ - Hide accordion by default (`False`)
44
+ - Expand accordion by default (`False`)
45
+ - Determines whether the 'Aspect Ratio Helper' accordion expands by default
46
+ - UI Component order (`MaxDimensionScaler, PredefinedAspectRatioButtons, PredefinedPercentageButtons`)
47
+ - Determines the order in which the UI components will render
48
+ - Enable JavaScript aspect ratio controls
49
+ - JavaScript aspect ratio buttons `(1:1, 4:3, 16:9, 9:16, 21:9)`
50
+ - i.e `1:1, 4:3, 16:9, 9:16, 21:9` `2:3, 1:5, 3:5`
51
+ - Show maximum dimension button (`True`)
52
+ - Maximum dimension default (`1024`)
53
+ - Show pre-defined aspect ratio buttons (`True`)
54
+ - Use "Maximum dimension" for aspect ratio buttons (`False`)
55
+ - Pre-defined aspect ratio buttons (`1:1, 4:3, 16:9, 9:16, 21:9`)
56
+ - i.e `1:1, 4:3, 16:9, 9:16, 21:9` `2:3, 1:5, 3:5`
57
+ - Show pre-defined percentage buttons (`True`)
58
+ - Pre-defined percentage buttons (`25, 50, 75, 125, 150, 175, 200`)
59
+ - i.e `25, 50, 75, 125, 150, 175, 200` `50, 125, 300`
60
+ - Pre-defined percentage display format (`Incremental/decremental percentage (-50%, +50%)`)
61
+ - `Incremental/decremental percentage (-50%, +50%)`
62
+ - `Raw percentage (50%, 150%)`
63
+ - `Multiplication (x0.5, x1.5)`
64
+
65
+ ![settings.png](docs%2Fopts.png)
66
+
67
+
68
+ JavaScript & accordion aspect ratios _might_ not play well together - I don't think many users will use both simultaneously, but we'll see.
69
+
70
+ ## Contributing
71
+
72
+ - Open an issue for suggestions
73
+ - Raise a pull request
74
+
75
+ ## Dependencies
76
+
77
+ Developed using existing [AUTOMATIC1111 webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) dependencies.
78
+
79
+ It's recommended to use the python version specified by A1111 webui.
80
+
81
+ However - for running unit tests, we use pytest.
82
+
83
+ ```bash
84
+ pip install pytest
85
+ ```
86
+
87
+ ## Testing
88
+ From the root of the repository.
89
+ ```bash
90
+ pytest
91
+ ```
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_components.py ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from abc import ABC
4
+ from abc import abstractmethod
5
+ from functools import partial
6
+ from typing import Callable
7
+
8
+ import gradio as gr
9
+
10
+ import aspect_ratio_helper._constants as _constants
11
+ import aspect_ratio_helper._settings as _settings
12
+ import aspect_ratio_helper._util as _util
13
+
14
+
15
+ class ArhUIComponent(ABC):
16
+
17
+ def __init__(self, script):
18
+ self.script = script
19
+
20
+ @abstractmethod
21
+ def render(self): ...
22
+
23
+ @staticmethod
24
+ @abstractmethod
25
+ def should_show() -> bool: ...
26
+
27
+ @staticmethod
28
+ @abstractmethod
29
+ def add_options(): ...
30
+
31
+
32
+ class MaxDimensionScaler(ArhUIComponent):
33
+
34
+ def render(self):
35
+ max_dim_default = _settings.safe_opt(
36
+ _constants.ARH_MAX_WIDTH_OR_HEIGHT_KEY,
37
+ )
38
+ self.script.max_dimension = float(max_dim_default)
39
+
40
+ inputs = outputs = [self.script.wc, self.script.hc]
41
+
42
+ with gr.Row(
43
+ visible=self.should_show(),
44
+ ):
45
+ max_dim_default = _settings.safe_opt(
46
+ _constants.ARH_MAX_WIDTH_OR_HEIGHT_KEY,
47
+ )
48
+ # todo: when using gr.Slider (not deprecated), the default value
49
+ # is somehow always 270?... can't figure out why.
50
+ # using legacy inputs.Slider for now as it doesn't have the issue.
51
+ max_dimension_slider = gr.inputs.Slider(
52
+ minimum=_constants.MIN_DIMENSION,
53
+ maximum=_constants.MAX_DIMENSION,
54
+ step=8,
55
+ default=max_dim_default,
56
+ label='Maximum dimension',
57
+ )
58
+
59
+ def _update_max_dimension(_max_dimension):
60
+ self.script.max_dimension = _max_dimension
61
+
62
+ max_dimension_slider.change(
63
+ _update_max_dimension,
64
+ inputs=[max_dimension_slider],
65
+ show_progress=False,
66
+ )
67
+
68
+ gr.Button(
69
+ value='Scale to maximum dimension',
70
+ visible=self.should_show(),
71
+ ).click(
72
+ fn=_util.scale_dimensions_to_max_dim,
73
+ inputs=[*inputs, max_dimension_slider],
74
+ outputs=outputs,
75
+ )
76
+
77
+ @staticmethod
78
+ def should_show() -> bool:
79
+ return _settings.safe_opt(_constants.ARH_SHOW_MAX_WIDTH_OR_HEIGHT_KEY)
80
+
81
+ @staticmethod
82
+ def add_options(shared):
83
+ shared.opts.add_option(
84
+ key=_constants.ARH_SHOW_MAX_WIDTH_OR_HEIGHT_KEY,
85
+ info=shared.OptionInfo(
86
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
87
+ _constants.ARH_SHOW_MAX_WIDTH_OR_HEIGHT_KEY,
88
+ ),
89
+ label='Show maximum dimension button',
90
+ section=_constants.SECTION,
91
+ ),
92
+ )
93
+ shared.opts.add_option(
94
+ key=_constants.ARH_MAX_WIDTH_OR_HEIGHT_KEY,
95
+ info=shared.OptionInfo(
96
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
97
+ _constants.ARH_MAX_WIDTH_OR_HEIGHT_KEY,
98
+ ),
99
+ label='Maximum dimension default',
100
+ component=gr.Slider,
101
+ component_args={
102
+ 'minimum': _constants.MIN_DIMENSION,
103
+ 'maximum': _constants.MAX_DIMENSION,
104
+ 'step': 8,
105
+ },
106
+ section=_constants.SECTION,
107
+ ),
108
+ )
109
+
110
+
111
+ class MinDimensionScaler(ArhUIComponent):
112
+
113
+ def render(self):
114
+ min_dim_default = _settings.safe_opt(
115
+ _constants.ARH_MIN_WIDTH_OR_HEIGHT_KEY,
116
+ )
117
+ self.script.min_dimension = float(min_dim_default)
118
+
119
+ inputs = outputs = [self.script.wc, self.script.hc]
120
+
121
+ with gr.Row(
122
+ visible=self.should_show(),
123
+ ):
124
+ min_dim_default = _settings.safe_opt(
125
+ _constants.ARH_MIN_WIDTH_OR_HEIGHT_KEY,
126
+ )
127
+ # todo: when using gr.Slider (not deprecated), the default value
128
+ # is somehow always 270?... can't figure out why.
129
+ # using legacy inputs.Slider for now as it doesn't have the issue.
130
+ min_dimension_slider = gr.inputs.Slider(
131
+ minimum=_constants.MIN_DIMENSION,
132
+ maximum=_constants.MAX_DIMENSION,
133
+ step=8,
134
+ default=min_dim_default,
135
+ label='Minimum dimension',
136
+ )
137
+
138
+ def _update_min_dimension(_min_dimension):
139
+ self.script.min_dimension = _min_dimension
140
+
141
+ min_dimension_slider.change(
142
+ _update_min_dimension,
143
+ inputs=[min_dimension_slider],
144
+ show_progress=False,
145
+ )
146
+
147
+ gr.Button(
148
+ value='Scale to minimum dimension',
149
+ visible=self.should_show(),
150
+ ).click(
151
+ fn=_util.scale_dimensions_to_min_dim,
152
+ inputs=[*inputs, min_dimension_slider],
153
+ outputs=outputs,
154
+ )
155
+
156
+ @staticmethod
157
+ def should_show() -> bool:
158
+ return _settings.safe_opt(_constants.ARH_SHOW_MIN_WIDTH_OR_HEIGHT_KEY)
159
+
160
+ @staticmethod
161
+ def add_options(shared):
162
+ shared.opts.add_option(
163
+ key=_constants.ARH_SHOW_MIN_WIDTH_OR_HEIGHT_KEY,
164
+ info=shared.OptionInfo(
165
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
166
+ _constants.ARH_SHOW_MIN_WIDTH_OR_HEIGHT_KEY,
167
+ ),
168
+ label='Show minimum dimension button',
169
+ section=_constants.SECTION,
170
+ ),
171
+ )
172
+ shared.opts.add_option(
173
+ key=_constants.ARH_MIN_WIDTH_OR_HEIGHT_KEY,
174
+ info=shared.OptionInfo(
175
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
176
+ _constants.ARH_MIN_WIDTH_OR_HEIGHT_KEY,
177
+ ),
178
+ label='Minimum dimension default',
179
+ component=gr.Slider,
180
+ component_args={
181
+ 'minimum': _constants.MIN_DIMENSION,
182
+ 'maximum': _constants.MAX_DIMENSION,
183
+ 'step': 8,
184
+ },
185
+ section=_constants.SECTION,
186
+ ),
187
+ )
188
+
189
+
190
+ class PredefinedAspectRatioButtons(ArhUIComponent):
191
+
192
+ def render(self):
193
+ use_max_dim_op = _settings.safe_opt(
194
+ _constants.ARH_PREDEFINED_ASPECT_RATIO_USE_MAX_DIM_KEY,
195
+ )
196
+ aspect_ratios = _settings.safe_opt(
197
+ _constants.ARH_PREDEFINED_ASPECT_RATIOS_KEY,
198
+ ).split(',')
199
+
200
+ with gr.Column(
201
+ variant='panel',
202
+ visible=self.should_show(),
203
+ ), gr.Row(
204
+ variant='compact',
205
+ visible=self.should_show(),
206
+ elem_classes='arh-btn-row',
207
+ ):
208
+ for ar_str in aspect_ratios:
209
+ w, h, *_ = (abs(float(d)) for d in ar_str.split(':'))
210
+
211
+ inputs = []
212
+ if use_max_dim_op:
213
+ ar_func = partial(
214
+ _util.scale_dimensions_to_max_dim_func,
215
+ width=w, height=h,
216
+ max_dim=lambda: self.script.max_dimension,
217
+ )
218
+ else:
219
+ inputs.extend([self.script.wc, self.script.hc])
220
+ ar_func = partial(
221
+ _util.scale_dimensions_to_ui_width_or_height,
222
+ arw=w, arh=h,
223
+ )
224
+
225
+ gr.Button(
226
+ value=self.display_func(ar_str) or ar_str,
227
+ visible=self.should_show(),
228
+ ).click(
229
+ fn=ar_func,
230
+ inputs=inputs,
231
+ outputs=[self.script.wc, self.script.hc],
232
+ )
233
+
234
+ @staticmethod
235
+ def should_show() -> bool:
236
+ return _settings.safe_opt(
237
+ _constants.ARH_SHOW_PREDEFINED_ASPECT_RATIOS_KEY,
238
+ )
239
+
240
+ @staticmethod
241
+ def add_options(shared):
242
+ shared.opts.add_option(
243
+ key=_constants.ARH_SHOW_PREDEFINED_ASPECT_RATIOS_KEY,
244
+ info=shared.OptionInfo(
245
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
246
+ _constants.ARH_SHOW_PREDEFINED_ASPECT_RATIOS_KEY,
247
+ ),
248
+ label='Show pre-defined aspect ratio buttons',
249
+ section=_constants.SECTION,
250
+ ),
251
+ )
252
+ shared.opts.add_option(
253
+ key=_constants.ARH_PREDEFINED_ASPECT_RATIO_USE_MAX_DIM_KEY,
254
+ info=shared.OptionInfo(
255
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
256
+ _constants.ARH_PREDEFINED_ASPECT_RATIO_USE_MAX_DIM_KEY,
257
+ ),
258
+ label='Use "Maximum dimension" for aspect ratio buttons (by '
259
+ 'default we use the max width or height)',
260
+ section=_constants.SECTION,
261
+ ),
262
+ )
263
+ shared.opts.add_option(
264
+ key=_constants.ARH_PREDEFINED_ASPECT_RATIOS_KEY,
265
+ info=shared.OptionInfo(
266
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
267
+ _constants.ARH_PREDEFINED_ASPECT_RATIOS_KEY,
268
+ ),
269
+ label='Pre-defined aspect ratio buttons '
270
+ '(1:1, 4:3, 16:9, 9:16, 21:9)',
271
+ section=_constants.SECTION,
272
+ ),
273
+ )
274
+
275
+ @property
276
+ def display_func(self) -> Callable[[str], str]:
277
+ return lambda _: None # todo: different displays for aspect ratios.
278
+
279
+
280
+ class PredefinedPercentageButtons(ArhUIComponent):
281
+
282
+ def render(self):
283
+ inputs = outputs = [self.script.wc, self.script.hc]
284
+ with gr.Column(
285
+ variant='panel',
286
+ visible=self.should_show(),
287
+ ), gr.Row(
288
+ variant='compact',
289
+ visible=self.should_show(),
290
+ elem_classes='arh-btn-row',
291
+ ):
292
+ pps = _settings.safe_opt(_constants.ARH_PREDEFINED_PERCENTAGES_KEY)
293
+ percentages = [abs(int(x)) for x in pps.split(',')]
294
+
295
+ for percentage in percentages:
296
+ display = self.display_func(percentage)
297
+ gr.Button(
298
+ value=display,
299
+ visible=self.should_show(),
300
+ ).click(
301
+ fn=partial(
302
+ _util.scale_by_percentage,
303
+ pct=percentage / 100,
304
+ ),
305
+ inputs=inputs,
306
+ outputs=outputs,
307
+ )
308
+
309
+ @staticmethod
310
+ def should_show() -> bool:
311
+ return _settings.safe_opt(
312
+ _constants.ARH_SHOW_PREDEFINED_PERCENTAGES_KEY,
313
+ )
314
+
315
+ @staticmethod
316
+ def add_options(shared):
317
+ shared.opts.add_option(
318
+ key=_constants.ARH_SHOW_PREDEFINED_PERCENTAGES_KEY,
319
+ info=shared.OptionInfo(
320
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
321
+ _constants.ARH_SHOW_PREDEFINED_PERCENTAGES_KEY,
322
+ ),
323
+ label='Show pre-defined percentage buttons',
324
+ section=_constants.SECTION,
325
+ ),
326
+ )
327
+ shared.opts.add_option(
328
+ key=_constants.ARH_PREDEFINED_PERCENTAGES_KEY,
329
+ info=shared.OptionInfo(
330
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
331
+ _constants.ARH_PREDEFINED_PERCENTAGES_KEY,
332
+ ),
333
+ label='Pre-defined percentage buttons (75, 125, 150)',
334
+ section=_constants.SECTION,
335
+ ),
336
+ )
337
+ shared.opts.add_option(
338
+ key=_constants.ARH_PREDEFINED_PERCENTAGES_DISPLAY_KEY,
339
+ info=shared.OptionInfo(
340
+ default=_settings.OPT_KEY_TO_DEFAULT_MAP.get(
341
+ _constants.ARH_PREDEFINED_PERCENTAGES_DISPLAY_KEY,
342
+ ),
343
+ label='Pre-defined percentage display format',
344
+ component=gr.Dropdown,
345
+ component_args=lambda: {
346
+ 'choices': tuple(
347
+ _settings.PREDEFINED_PERCENTAGES_DISPLAY_MAP.keys(),
348
+ ),
349
+ },
350
+ section=_constants.SECTION,
351
+ ),
352
+ )
353
+
354
+ @property
355
+ def display_func(self) -> Callable[[str], str]:
356
+ return _settings.PREDEFINED_PERCENTAGES_DISPLAY_MAP.get(
357
+ _settings.safe_opt(
358
+ _constants.ARH_PREDEFINED_PERCENTAGES_DISPLAY_KEY,
359
+ ),
360
+ )
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_constants.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ EXTENSION_NAME = 'Aspect Ratio Helper'
3
+
4
+ MAX_DIMENSION = 2048
5
+ MIN_DIMENSION = 64
6
+
7
+ ARH_EXPAND_BY_DEFAULT_KEY = 'arh_expand_by_default'
8
+ ARH_HIDE_ACCORDION_BY_DEFAULT_KEY = 'arh_hide_accordion_by_default'
9
+ ARH_UI_COMPONENT_ORDER_KEY = 'arh_ui_component_order_key'
10
+ ARH_UI_JAVASCRIPT_SELECTION_METHOD = 'arh_ui_javascript_selection_method'
11
+ ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY = 'arh_javascript_aspect_ratio_show'
12
+ ARH_JAVASCRIPT_ASPECT_RATIOS_KEY = 'arh_javascript_aspect_ratio'
13
+ ARH_SHOW_MAX_WIDTH_OR_HEIGHT_KEY = 'arh_show_max_width_or_height'
14
+ ARH_SHOW_MIN_WIDTH_OR_HEIGHT_KEY = 'arh_show_min_width_or_height'
15
+ ARH_MAX_WIDTH_OR_HEIGHT_KEY = 'arh_max_width_or_height'
16
+ ARH_MIN_WIDTH_OR_HEIGHT_KEY = 'arh_min_width_or_height'
17
+ ARH_SHOW_PREDEFINED_PERCENTAGES_KEY = 'arh_show_predefined_percentages'
18
+ ARH_PREDEFINED_PERCENTAGES_KEY = 'arh_predefined_percentages'
19
+ ARH_SHOW_PREDEFINED_ASPECT_RATIOS_KEY = 'arh_show_predefined_aspect_ratios'
20
+ ARH_PREDEFINED_ASPECT_RATIOS_KEY = 'arh_predefined_aspect_ratios'
21
+ ARH_PREDEFINED_ASPECT_RATIO_USE_MAX_DIM_KEY \
22
+ = 'arh_predefined_aspect_ratio_use_max_dim'
23
+ ARH_PREDEFINED_PERCENTAGES_DISPLAY_KEY \
24
+ = 'arh_predefined_percentages_display_key'
25
+ DEFAULT_PERCENTAGES_DISPLAY_KEY \
26
+ = 'Incremental/decremental percentage (-50%, +50%)'
27
+ SECTION = 'aspect_ratio_helper', EXTENSION_NAME
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_settings.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import itertools
4
+
5
+ import gradio as gr
6
+ from modules import shared
7
+
8
+ import aspect_ratio_helper._components as _components
9
+ import aspect_ratio_helper._constants as _constants
10
+ import aspect_ratio_helper._util as _util
11
+
12
+ PREDEFINED_PERCENTAGES_DISPLAY_MAP = {
13
+ _constants.DEFAULT_PERCENTAGES_DISPLAY_KEY: _util.display_minus_and_plus,
14
+ 'Raw percentage (50%, 150%)': _util.display_raw_percentage,
15
+ 'Multiplication (x0.5, x1.5)': _util.display_multiplication,
16
+ }
17
+
18
+ COMPONENTS = (
19
+ _components.MaxDimensionScaler,
20
+ _components.MinDimensionScaler,
21
+ _components.PredefinedAspectRatioButtons,
22
+ _components.PredefinedPercentageButtons,
23
+ )
24
+
25
+ DEFAULT_UI_COMPONENT_ORDER_KEY_LIST = [e.__name__ for e in COMPONENTS]
26
+ DEFAULT_UI_COMPONENT_ORDER_KEY = ', '.join(
27
+ DEFAULT_UI_COMPONENT_ORDER_KEY_LIST,
28
+ )
29
+ OPT_KEY_TO_DEFAULT_MAP = {
30
+ _constants.ARH_EXPAND_BY_DEFAULT_KEY: False,
31
+ _constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY: True,
32
+ _constants.ARH_UI_COMPONENT_ORDER_KEY:
33
+ DEFAULT_UI_COMPONENT_ORDER_KEY,
34
+ _constants.ARH_UI_JAVASCRIPT_SELECTION_METHOD: 'Aspect Ratios Dropdown',
35
+ _constants.ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY: True,
36
+ _constants.ARH_JAVASCRIPT_ASPECT_RATIOS_KEY:
37
+ '1:1, 3:2, 4:3, 5:4, 16:9',
38
+ _constants.ARH_SHOW_MAX_WIDTH_OR_HEIGHT_KEY: False,
39
+ _constants.ARH_MAX_WIDTH_OR_HEIGHT_KEY:
40
+ _constants.MAX_DIMENSION / 2,
41
+ _constants.ARH_SHOW_MIN_WIDTH_OR_HEIGHT_KEY: False,
42
+ _constants.ARH_MIN_WIDTH_OR_HEIGHT_KEY:
43
+ _constants.MAX_DIMENSION / 2,
44
+ _constants.ARH_SHOW_PREDEFINED_PERCENTAGES_KEY: False,
45
+ _constants.ARH_PREDEFINED_PERCENTAGES_KEY:
46
+ '25, 50, 75, 125, 150, 175, 200',
47
+ _constants.ARH_PREDEFINED_PERCENTAGES_DISPLAY_KEY:
48
+ _constants.DEFAULT_PERCENTAGES_DISPLAY_KEY,
49
+ _constants.ARH_SHOW_PREDEFINED_ASPECT_RATIOS_KEY: False,
50
+ _constants.ARH_PREDEFINED_ASPECT_RATIO_USE_MAX_DIM_KEY: False,
51
+ _constants.ARH_PREDEFINED_ASPECT_RATIOS_KEY:
52
+ '1:1, 4:3, 16:9, 9:16, 21:9',
53
+ }
54
+
55
+
56
+ def safe_opt(key):
57
+ return _util.safe_opt_util(shared.opts, key, OPT_KEY_TO_DEFAULT_MAP)
58
+
59
+
60
+ def sort_components_by_keys(
61
+ components: list[_components.ArhUIComponent],
62
+ ) -> list[_components.ArhUIComponent]:
63
+ ordered_component_keys = safe_opt(
64
+ _constants.ARH_UI_COMPONENT_ORDER_KEY,
65
+ ).split(',')
66
+
67
+ # this can happen if we add new components, but the user has old settings.
68
+ # if this happens, we find the missing components, and append them.
69
+ if len(ordered_component_keys) != len(COMPONENTS):
70
+ all_components = set(DEFAULT_UI_COMPONENT_ORDER_KEY_LIST)
71
+ missing_components = all_components - set(ordered_component_keys)
72
+ ordered_component_keys.extend(missing_components)
73
+
74
+ try:
75
+ component_key_to_order_dict = {
76
+ key: order for order, key in enumerate(
77
+ [k.strip() for k in ordered_component_keys],
78
+ )
79
+ }
80
+ return sorted(
81
+ components,
82
+ key=lambda c: component_key_to_order_dict.get(
83
+ c.__class__.__name__,
84
+ ),
85
+ )
86
+ except ValueError:
87
+ print(
88
+ f'{_constants.EXTENSION_NAME} UI component order is erroneous. '
89
+ f'Defaulting to regular order, to fix this, please use'
90
+ f'the intended syntax for the setting, i.e '
91
+ f'"{DEFAULT_UI_COMPONENT_ORDER_KEY}"',
92
+ )
93
+ return components
94
+
95
+
96
+ def on_ui_settings():
97
+ # javascript ui options
98
+ shared.opts.add_option(
99
+ key=_constants.ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY,
100
+ info=shared.OptionInfo(
101
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
102
+ _constants.ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY,
103
+ ),
104
+ label='Enable JavaScript aspect ratio controls',
105
+ section=_constants.SECTION,
106
+ ),
107
+ )
108
+ shared.opts.add_option(
109
+ key=_constants.ARH_JAVASCRIPT_ASPECT_RATIOS_KEY,
110
+ info=shared.OptionInfo(
111
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
112
+ _constants.ARH_JAVASCRIPT_ASPECT_RATIOS_KEY,
113
+ ),
114
+ label='JavaScript aspect ratio buttons'
115
+ ' (1:1, 4:3, 16:9, 9:16, 21:9)',
116
+ section=_constants.SECTION,
117
+ ),
118
+ )
119
+ shared.opts.add_option(
120
+ key=_constants.ARH_UI_JAVASCRIPT_SELECTION_METHOD,
121
+ info=shared.OptionInfo(
122
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
123
+ _constants.ARH_UI_JAVASCRIPT_SELECTION_METHOD,
124
+ ),
125
+ label='JavaScript selection method',
126
+ component=gr.Dropdown,
127
+ component_args=lambda: {
128
+ 'choices': [
129
+ 'Aspect Ratios Dropdown',
130
+ 'Default Options Button',
131
+ ],
132
+ },
133
+ section=_constants.SECTION,
134
+ ),
135
+ )
136
+
137
+ # accordion options
138
+ shared.opts.add_option(
139
+ key=_constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
140
+ info=shared.OptionInfo(
141
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
142
+ _constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
143
+ ),
144
+ label='Hide accordion by default',
145
+ section=_constants.SECTION,
146
+ ),
147
+ )
148
+ shared.opts.add_option(
149
+ key=_constants.ARH_EXPAND_BY_DEFAULT_KEY,
150
+ info=shared.OptionInfo(
151
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
152
+ _constants.ARH_EXPAND_BY_DEFAULT_KEY,
153
+ ),
154
+ label='Expand accordion by default',
155
+ section=_constants.SECTION,
156
+ ),
157
+ )
158
+ shared.opts.add_option(
159
+ key=_constants.ARH_UI_COMPONENT_ORDER_KEY,
160
+ info=shared.OptionInfo(
161
+ default=OPT_KEY_TO_DEFAULT_MAP.get(
162
+ _constants.ARH_UI_COMPONENT_ORDER_KEY,
163
+ ),
164
+ label='UI Component order',
165
+ component=gr.Dropdown,
166
+ component_args=lambda: {
167
+ 'choices': [
168
+ ', '.join(p) for p in itertools.permutations( # TODO: Rethink this, exponential growth...
169
+ DEFAULT_UI_COMPONENT_ORDER_KEY_LIST,
170
+ )
171
+ ],
172
+ },
173
+ section=_constants.SECTION,
174
+ ),
175
+ )
176
+
177
+ for component in COMPONENTS:
178
+ component.add_options(shared)
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/_util.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import contextlib
4
+
5
+ import aspect_ratio_helper._constants as _const
6
+
7
+
8
+ def safe_opt_util(shared_opts, key, default_key_map: dict[str, object]):
9
+ # attempt to retrieve key from shared options
10
+ with contextlib.suppress(AttributeError):
11
+ value = shared_opts.__getattr__(key)
12
+ if value is not None:
13
+ return value
14
+
15
+ # attempt to retrieve default, and last resort the constant default
16
+ return shared_opts.get_default(key) or default_key_map.get(key)
17
+
18
+
19
+ def display_multiplication(num) -> str:
20
+ return f'x{round(num / 100, 3)}'
21
+
22
+
23
+ def display_raw_percentage(num) -> str:
24
+ return f'{num}%'
25
+
26
+
27
+ def display_minus_and_plus(num) -> str:
28
+ num -= 100
29
+ if num > 0:
30
+ return f'+{num}%'
31
+ return f'{num}%'
32
+
33
+
34
+ def scale_by_percentage(width, height, pct) -> tuple[int, int]:
35
+ aspect_ratio = float(width) / float(height)
36
+ step = (pct - 1.0)
37
+ new_width = int(round(width * (1.0 + step)))
38
+ new_height = int(round(new_width / aspect_ratio))
39
+ return clamp_to_boundaries(new_width, new_height, aspect_ratio)
40
+
41
+
42
+ def scale_dimensions_to_ui_width_or_height(
43
+ width, height, arw, arh,
44
+ ) -> tuple[int, int]:
45
+ return scale_dimensions_to_max_dim(arw, arh, max(width, height))
46
+
47
+
48
+ def scale_dimensions_to_max_dim_func(
49
+ width, height, max_dim: callable,
50
+ ) -> tuple[int, int]:
51
+ return scale_dimensions_to_max_dim(width, height, max_dim())
52
+
53
+
54
+ def scale_dimensions_to_max_dim(
55
+ width, height, max_dim,
56
+ ) -> tuple[int, int]:
57
+ aspect_ratio = float(width) / float(height)
58
+ return scale_dimensions_to_ar(width, height, max_dim, aspect_ratio)
59
+
60
+
61
+ def scale_dimensions_to_min_dim(
62
+ width, height, min_dim,
63
+ ) -> tuple[int, int]:
64
+ aspect_ratio = float(width) / float(height)
65
+ if width >= height:
66
+ max_dim = min_dim * aspect_ratio
67
+ else:
68
+ max_dim = min_dim / aspect_ratio
69
+ return scale_dimensions_to_ar(width, height, max_dim, aspect_ratio)
70
+
71
+
72
+ def scale_dimensions_to_ar(
73
+ width, height, max_dim, aspect_ratio,
74
+ ) -> tuple[int, int]:
75
+ if width > height:
76
+ new_width = max_dim
77
+ new_height = int(round(max_dim / aspect_ratio))
78
+ else:
79
+ new_height = max_dim
80
+ new_width = int(round(max_dim * aspect_ratio))
81
+ return clamp_to_boundaries(new_width, new_height, aspect_ratio)
82
+
83
+
84
+ def round_to_multiple_of_8(value):
85
+ return int(round(value / 8.0)) * 8
86
+
87
+
88
+ def clamp_to_boundaries(owidth, oheight, aspect_ratio) -> tuple[int, int]:
89
+ width, height = owidth, oheight
90
+ if width > _const.MAX_DIMENSION:
91
+ width = _const.MAX_DIMENSION
92
+ height = int(round(width / aspect_ratio))
93
+ if height > _const.MAX_DIMENSION:
94
+ height = _const.MAX_DIMENSION
95
+ width = int(round(height * aspect_ratio))
96
+ if width < _const.MIN_DIMENSION:
97
+ width = _const.MIN_DIMENSION
98
+ height = int(round(width / aspect_ratio))
99
+ if height < _const.MIN_DIMENSION:
100
+ height = _const.MIN_DIMENSION
101
+ width = int(round(height * aspect_ratio))
102
+
103
+ width = round_to_multiple_of_8(width)
104
+ height = round_to_multiple_of_8(height)
105
+ # for insane aspect ratios we don't support... i.e 1:100
106
+ # 64:6400 when run through this function, so we clamp to 64:2048 (‾◡◝)
107
+ # also. when the user does this it breaks the "scale to max" function
108
+ # on the ui until they change to another reasonable aspect ratio.
109
+ # todo: figure out why ^ and handle it better.
110
+ if width < _const.MIN_DIMENSION:
111
+ width = _const.MIN_DIMENSION
112
+ elif width > _const.MAX_DIMENSION:
113
+ width = _const.MAX_DIMENSION
114
+ if height < _const.MIN_DIMENSION:
115
+ height = _const.MIN_DIMENSION
116
+ elif height > _const.MAX_DIMENSION:
117
+ height = _const.MAX_DIMENSION
118
+
119
+ return width, height
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/aspect_ratio_helper/main.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import gradio as gr
4
+ from modules import script_callbacks
5
+ from modules import scripts
6
+
7
+ import aspect_ratio_helper._constants as _constants
8
+ import aspect_ratio_helper._settings as _settings
9
+
10
+
11
+ class AspectRatioStepScript(scripts.Script):
12
+
13
+ def __init__(self):
14
+ self.t2i_w: gr.components.Slider | None = None
15
+ self.t2i_h: gr.components.Slider | None = None
16
+ self.i2i_w: gr.components.Slider | None = None
17
+ self.i2i_h: gr.components.Slider | None = None
18
+ self.wc: gr.components.Slider
19
+ self.hc: gr.components.Slider
20
+ self.max_dimension: float
21
+
22
+ def title(self) -> str:
23
+ return _constants.EXTENSION_NAME
24
+
25
+ def show(self, _) -> scripts.AlwaysVisible:
26
+ return scripts.AlwaysVisible
27
+
28
+ def ui(self, is_img2img):
29
+ if is_img2img:
30
+ self.wc, self.hc = self.i2i_w, self.i2i_h
31
+ else:
32
+ self.wc, self.hc = self.t2i_w, self.t2i_h # noqa
33
+
34
+ components = _settings.sort_components_by_keys(
35
+ [component(self) for component in _settings.COMPONENTS],
36
+ )
37
+
38
+ hide_accordion: bool = _settings.safe_opt(
39
+ _constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
40
+ )
41
+
42
+ if hide_accordion or not any(c.should_show() for c in components):
43
+ return # no components should render, so just return.
44
+
45
+ start_expanded: bool = _settings.safe_opt(
46
+ _constants.ARH_EXPAND_BY_DEFAULT_KEY,
47
+ )
48
+ with gr.Group(), gr.Accordion(
49
+ _constants.EXTENSION_NAME,
50
+ open=start_expanded,
51
+ ):
52
+ for component in components:
53
+ # we deliberately DON'T check component.should_show() here.
54
+ # we need to call render to instantiate the components, we use
55
+ # the visible property on each component to hide them.
56
+ component.render()
57
+
58
+ def after_component(self, component: gr.components.Component, **kwargs):
59
+ element_id = kwargs.get('elem_id')
60
+
61
+ if isinstance(component, gr.components.Slider):
62
+ if element_id == 'txt2img_width':
63
+ self.t2i_w: gr.components.Slider = component
64
+ elif element_id == 'txt2img_height':
65
+ self.t2i_h: gr.components.Slider = component
66
+ elif element_id == 'img2img_width':
67
+ self.i2i_w: gr.components.Slider = component
68
+ elif element_id == 'img2img_height':
69
+ self.i2i_h: gr.components.Slider = component
70
+
71
+
72
+ script_callbacks.on_ui_settings(_settings.on_ui_settings)
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/docs/opts.png ADDED
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/docs/ui.png ADDED
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/javascript/aspectRatioController.js ADDED
@@ -0,0 +1,474 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // constants
2
+ const _OFF = "Off"; // Don't use the functionality at all
3
+ const _LOCK = '🔒'; // Aspect ratio is "locked"
4
+ const _IMAGE = '🖼️'; // Aspect ratio is "locked" to that of the image
5
+
6
+ const _MAXIMUM_DIMENSION = 2048;
7
+ const _MINIMUM_DIMENSION = 64;
8
+
9
+ const _IMAGE_INPUT_CONTAINER_IDS = [
10
+ 'img2img_image',
11
+ 'img2img_sketch',
12
+ 'img2maskimg',
13
+ 'inpaint_sketch',
14
+ 'img_inpaint_base',
15
+ ];
16
+
17
+ const getSelectedImage2ImageTab = () => {
18
+ const selectedButton = gradioApp().getElementById('mode_img2img').querySelector('button.selected');
19
+ const allButtons = gradioApp().getElementById('mode_img2img').querySelectorAll('button');
20
+ const selectedIndex = Array.prototype.indexOf.call(allButtons, selectedButton);
21
+ return selectedIndex;
22
+ }
23
+
24
+ const getCurrentImage = () => {
25
+ const currentTabIndex = getSelectedImage2ImageTab();
26
+ const currentTabImageId = _IMAGE_INPUT_CONTAINER_IDS[currentTabIndex];
27
+ return document.getElementById(currentTabImageId).querySelector('img');
28
+ }
29
+
30
+ const roundToClosestMultiple = (num, multiple) => {
31
+ const rounded = Math.round(Number(num) / multiple) * multiple;
32
+ return rounded;
33
+ }
34
+
35
+ const aspectRatioFromStr = (ar) => {
36
+ if (!ar.includes(':')) return;
37
+ return ar.split(':').map(x => Number(x));
38
+ }
39
+
40
+ const reverseAspectRatio = (ar) => {
41
+ if (!ar.includes(':')) return;
42
+ const [width, height] = ar.split(':');
43
+ return `${height}:${width}`;
44
+ }
45
+
46
+ const clampToBoundaries = (width, height) => {
47
+ const aspectRatio = width / height;
48
+ width = Math.max(Math.min(width, _MAXIMUM_DIMENSION), _MINIMUM_DIMENSION);
49
+ height = Math.max(Math.min(height, _MAXIMUM_DIMENSION), _MINIMUM_DIMENSION);
50
+ if (width / height > aspectRatio) {
51
+ height = Math.round(width / aspectRatio);
52
+ } else if (width / height < aspectRatio) {
53
+ width = Math.round(height * aspectRatio);
54
+ }
55
+
56
+ if (width > _MAXIMUM_DIMENSION) {
57
+ width = _MAXIMUM_DIMENSION;
58
+ } else if (width < _MINIMUM_DIMENSION) {
59
+ width = _MINIMUM_DIMENSION;
60
+ }
61
+
62
+ if (height < _MINIMUM_DIMENSION) {
63
+ height = _MINIMUM_DIMENSION;
64
+ } else if (height > _MAXIMUM_DIMENSION) {
65
+ height = _MAXIMUM_DIMENSION;
66
+ }
67
+
68
+ return [width, height];
69
+ }
70
+
71
+ const getOptions = () => {
72
+ return window.opts.arh_javascript_aspect_ratio.split(',').map(o => o.trim());
73
+ }
74
+
75
+ const reverseAllOptions = () => {
76
+ const allAspectRatioOptions = Array.from(gradioApp().querySelectorAll('.ar-option'));
77
+ allAspectRatioOptions.forEach(el => {
78
+ const reversed = reverseAspectRatio(el.value);
79
+ if (reversed) {
80
+ el.value = reversed;
81
+ el.textContent = reversed;
82
+ }
83
+ });
84
+ }
85
+
86
+ class OptionPickingController {
87
+ constructor(page, defaultOptions, controller) {
88
+ this.page = page;
89
+ this.options = this.getOptions(defaultOptions);
90
+ this.switchButton = gradioApp().getElementById(page + '_res_switch_btn');
91
+
92
+ const wrapperDiv = document.createElement('div');
93
+ wrapperDiv.setAttribute("id", `${this.page}_size_toolbox`);
94
+ wrapperDiv.setAttribute("class", "flex flex-col relative col gap-4");
95
+ wrapperDiv.setAttribute("style", "min-width: min(320px, 100%); flex-grow: 0");
96
+ wrapperDiv.innerHTML = this.getElementInnerHTML();
97
+
98
+ const parent = this.switchButton.parentNode;
99
+ parent.removeChild(this.switchButton);
100
+ wrapperDiv.appendChild(this.switchButton);
101
+ parent.insertBefore(wrapperDiv, parent.lastChild.previousElementSibling);
102
+
103
+ this.getPickerElement().onchange = this.pickerChanged(controller);
104
+ this.switchButton.onclick = this.switchButtonOnclick(controller);
105
+ }
106
+
107
+ getOptions(defaultOptions) {
108
+ return [...new Set([...defaultOptions, ...getOptions()])];
109
+ }
110
+
111
+ pickerChanged(controller) {
112
+ return () => {
113
+ const picked = this.getCurrentOption();
114
+ if (_IMAGE === picked) {
115
+ // this.switchButton.disabled = true;
116
+ } else {
117
+ this.switchButton.removeAttribute('disabled')
118
+ }
119
+
120
+ controller.setAspectRatio(picked);
121
+ };
122
+ }
123
+
124
+ switchButtonOnclick(controller) {
125
+ return () => {
126
+ reverseAllOptions();
127
+ const picked = this.getCurrentOption();
128
+ if (_LOCK === picked) {
129
+ controller.setAspectRatio(`${controller.heightRatio}:${controller.widthRatio}`);
130
+ } else {
131
+ controller.setAspectRatio(picked);
132
+ }
133
+ };
134
+ }
135
+
136
+ getElementInnerHTML() {
137
+ throw new Error('Not implemented');
138
+ }
139
+
140
+ getPickerElement() {
141
+ throw new Error('Not implemented');
142
+ }
143
+
144
+ getCurrentOption() {
145
+ throw new Error('Not implemented');
146
+ }
147
+ }
148
+
149
+
150
+ class SelectOptionPickingController extends OptionPickingController {
151
+ constructor(page, defaultOptions, controller) {
152
+ super(page, defaultOptions, controller);
153
+ }
154
+
155
+ getElementInnerHTML() {
156
+ return `
157
+ <div id="${this.page}_ratio" class="gr-block gr-box relative w-full border-solid border border-gray-200 gr-padded">
158
+ <select id="${this.page}_select_aspect_ratio" class="gr-box gr-input w-full disabled:cursor-not-allowed">
159
+ ${this.options.map(r => {
160
+ return '<option class="ar-option">' + r + '</option>'
161
+ }).join('\n')}
162
+ </select>
163
+ </div>
164
+ `;
165
+ }
166
+
167
+ getPickerElement() {
168
+ return gradioApp().getElementById(`${this.page}_select_aspect_ratio`);
169
+ }
170
+
171
+ getCurrentOption() {
172
+ const selectElement = this.getPickerElement();
173
+ const options = Array.from(selectElement);
174
+ return options[selectElement.selectedIndex].value;
175
+ }
176
+ }
177
+
178
+ class DefaultOptionsButtonOptionPickingController extends OptionPickingController {
179
+ constructor(page, defaultOptions, controller) {
180
+ super(page, defaultOptions, controller);
181
+ this.currentIndex = 0;
182
+ this.getPickerElement().onclick = this.pickerChanged(controller);
183
+ }
184
+
185
+ pickerChanged(controller) {
186
+ return () => {
187
+ this.currentIndex = (this.currentIndex + 1) % this.options.length;
188
+ this.getPickerElement().querySelector('button').textContent = this.getCurrentOption();
189
+ super.pickerChanged(controller)();
190
+ }
191
+ }
192
+
193
+ getElementInnerHTML() {
194
+ const classes = Array.from(this.switchButton.classList);
195
+ return `
196
+ <div id="${this.page}_ar_default_options_button" style="margin-bottom: 10px;">
197
+ <button class="${classes.join(' ')}">
198
+ ${this.getCurrentOption()}
199
+ </button>
200
+ </div>
201
+ `;
202
+ }
203
+
204
+ getPickerElement() {
205
+ return gradioApp().getElementById(`${this.page}_ar_default_options_button`);
206
+ }
207
+
208
+ getOptions(defaultOptions) {
209
+ return defaultOptions;
210
+ }
211
+
212
+ getCurrentOption() {
213
+ return this.options[this.currentIndex || 0];
214
+ }
215
+ }
216
+
217
+
218
+ class SliderController {
219
+ constructor(element) {
220
+ this.element = element;
221
+ this.numberInput = this.element.querySelector('input[type=number]');
222
+ this.rangeInput = this.element.querySelector('input[type=range]');
223
+ this.inputs = [this.numberInput, this.rangeInput];
224
+ this.inputs.forEach(input => {
225
+ input.isWidth = element.isWidth;
226
+ });
227
+ }
228
+
229
+ getVal() {
230
+ return Number(this.numberInput.value);
231
+ }
232
+
233
+ updateVal(value) {
234
+ this.inputs.forEach(input => {
235
+ input.value = Number(value)
236
+ })
237
+ }
238
+
239
+ updateMin(value) {
240
+ this.inputs.forEach(input => {
241
+ input.min = roundToClosestMultiple(Number(value), 8);
242
+ })
243
+ }
244
+
245
+ updateMax(value) {
246
+ this.inputs.forEach(input => {
247
+ input.max = roundToClosestMultiple(Number(value), 8);
248
+ })
249
+ }
250
+
251
+ triggerEvent(event) {
252
+ this.numberInput.dispatchEvent(event)
253
+ }
254
+
255
+ setVal(value) {
256
+ value = Number(value)
257
+ const newValue = roundToClosestMultiple(value, 8)
258
+ this.updateVal(newValue);
259
+ }
260
+
261
+ }
262
+
263
+ class AspectRatioController {
264
+ constructor(page, widthContainer, heightContainer, defaultOptions) {
265
+ widthContainer.isWidth = true;
266
+ heightContainer.isWidth = false;
267
+ this.widthContainer = new SliderController(widthContainer);
268
+ this.heightContainer = new SliderController(heightContainer);
269
+ this.inputs = [...this.widthContainer.inputs, ...this.heightContainer.inputs];
270
+ this.inputs.forEach(input => {
271
+ input.addEventListener('change', (e) => {
272
+ e.preventDefault()
273
+ this.maintainAspectRatio(input);
274
+ });
275
+ })
276
+
277
+ if (window.opts.arh_ui_javascript_selection_method === 'Default Options Button') {
278
+ this.optionPickingControler = new DefaultOptionsButtonOptionPickingController(page, defaultOptions, this);
279
+ } else {
280
+ this.optionPickingControler = new SelectOptionPickingController(page, defaultOptions, this);
281
+ }
282
+
283
+ this.setAspectRatio(_OFF);
284
+ }
285
+
286
+ updateInputStates() {
287
+ if (this.isLandscapeOrSquare()) {
288
+ const AR = this.widthRatio / this.heightRatio;
289
+
290
+ const minWidthByAr = Math.round(_MINIMUM_DIMENSION * AR);
291
+ const minWidth = Math.max(minWidthByAr, _MINIMUM_DIMENSION);
292
+ this.widthContainer.updateMin(minWidth);
293
+ this.heightContainer.updateMin(_MINIMUM_DIMENSION);
294
+
295
+ const maxHeightByAr = Math.round(_MAXIMUM_DIMENSION / AR)
296
+ const maxHeight = Math.min(_MAXIMUM_DIMENSION, maxHeightByAr);
297
+ this.heightContainer.updateMax(maxHeight);
298
+ this.widthContainer.updateMax(_MAXIMUM_DIMENSION);
299
+ } else {
300
+ const AR = this.heightRatio / this.widthRatio;
301
+
302
+ const minHeightByAr = Math.round(_MINIMUM_DIMENSION * AR)
303
+ const minHeight = Math.max(minHeightByAr, _MINIMUM_DIMENSION);
304
+ this.heightContainer.updateMin(minHeight);
305
+ this.widthContainer.updateMin(_MINIMUM_DIMENSION);
306
+
307
+ const maxWidthByAr = Math.round(_MAXIMUM_DIMENSION / AR)
308
+ const maxWidth = Math.min(_MAXIMUM_DIMENSION, maxWidthByAr);
309
+ this.widthContainer.updateMax(maxWidth);
310
+ this.heightContainer.updateMax(_MAXIMUM_DIMENSION);
311
+ }
312
+ }
313
+
314
+ disable() {
315
+ this.widthContainer.updateMin(_MINIMUM_DIMENSION);
316
+ this.heightContainer.updateMin(_MINIMUM_DIMENSION);
317
+ this.widthContainer.updateMax(_MAXIMUM_DIMENSION);
318
+ this.heightContainer.updateMax(_MAXIMUM_DIMENSION);
319
+ }
320
+
321
+ isLandscapeOrSquare() {
322
+ return this.widthRatio >= this.heightRatio;
323
+ }
324
+
325
+ setAspectRatio(aspectRatio) {
326
+ this.aspectRatio = aspectRatio;
327
+
328
+ let wR, hR;
329
+ if (aspectRatio === _OFF) {
330
+ return this.disable();
331
+ } else if (aspectRatio === _IMAGE) {
332
+ const img = getCurrentImage();
333
+ wR = img && img.naturalWidth || 1;
334
+ hR = img && img.naturalHeight || 1;
335
+ } else if (aspectRatio === _LOCK) {
336
+ wR = this.widthContainer.getVal();
337
+ hR = this.heightContainer.getVal();
338
+ } else {
339
+ [wR, hR] = aspectRatioFromStr(aspectRatio);
340
+ }
341
+
342
+ [wR, hR] = clampToBoundaries(wR, hR);
343
+
344
+ this.widthRatio = wR;
345
+ this.heightRatio = hR;
346
+ this.updateInputStates();
347
+ this.maintainAspectRatio();
348
+ }
349
+
350
+ maintainAspectRatio(changedElement) {
351
+ if (this.aspectRatio === _OFF) return;
352
+ if (!changedElement) {
353
+ const allValues = Object.values(this.inputs).map(x => Number(x.value));
354
+ changedElement = {value: Math.max(...allValues)};
355
+ }
356
+
357
+ const aspectRatio = this.widthRatio / this.heightRatio;
358
+ let w, h;
359
+
360
+ if (changedElement.isWidth === undefined) {
361
+ if (this.isLandscapeOrSquare()) {
362
+ if (changedElement.isWidth) {}
363
+ w = Math.round(changedElement.value);
364
+ h = Math.round(changedElement.value / aspectRatio);
365
+ } else {
366
+ h = Math.round(changedElement.value);
367
+ w = Math.round(changedElement.value * aspectRatio);
368
+ }
369
+ } else {
370
+ if (changedElement.isWidth) {
371
+ w = Math.round(changedElement.value);
372
+ h = Math.round(changedElement.value / aspectRatio);
373
+ } else {
374
+ h = Math.round(changedElement.value);
375
+ w = Math.round(changedElement.value * aspectRatio);
376
+ }
377
+ }
378
+
379
+ const [width, height] = clampToBoundaries(w, h)
380
+
381
+ const inputEvent = new Event("input", {bubbles: true});
382
+ this.widthContainer.setVal(width);
383
+ this.widthContainer.triggerEvent(inputEvent);
384
+ this.heightContainer.setVal(height);
385
+ this.heightContainer.triggerEvent(inputEvent);
386
+ this.heightContainer.inputs.forEach(input => {
387
+ dimensionChange({target: input}, false, true);
388
+ });
389
+ this.widthContainer.inputs.forEach(input => {
390
+ dimensionChange({target: input}, true, false);
391
+ });
392
+ }
393
+
394
+ static observeStartup(key, page, defaultOptions, postSetup = (_) => {
395
+ }) {
396
+ let observer = new MutationObserver(() => {
397
+ const widthContainer = gradioApp().querySelector(`#${page}_width`);
398
+ const heightContainer = gradioApp().querySelector(`#${page}_height`);
399
+
400
+ // wait for width and height containers to exist.
401
+ if (widthContainer && heightContainer && window.opts && window.opts.arh_javascript_aspect_ratio_show !== undefined) {
402
+ observer.disconnect();
403
+ if (!window.opts.arh_javascript_aspect_ratio_show) {
404
+ return;
405
+ }
406
+
407
+ const controller = new AspectRatioController(
408
+ page,
409
+ widthContainer,
410
+ heightContainer,
411
+ defaultOptions,
412
+ );
413
+
414
+ postSetup(controller);
415
+ window[key] = controller;
416
+ }
417
+ });
418
+
419
+ observer.observe(gradioApp(), {childList: true, subtree: true});
420
+ }
421
+
422
+ }
423
+
424
+ const addImg2ImgTabSwitchClickListeners = (controller) => {
425
+ const img2imgTabButtons = Array.from(document.querySelectorAll('#img2img_settings > div > div > button:not(.selected):not(.hasTabSwitchListener)'));
426
+ img2imgTabButtons.forEach(button => {
427
+ button.addEventListener('click', (_) => {
428
+ // set aspect ratio is RECALLED to change to the image specific to the newly selected tab.
429
+ if (controller.optionPickingControler.getCurrentOption() === _IMAGE) {
430
+ controller.setAspectRatio(_IMAGE);
431
+ }
432
+
433
+ addImg2ImgTabSwitchClickListeners(controller);
434
+ });
435
+
436
+ button.classList.add('hasTabSwitchListener');
437
+ });
438
+ }
439
+
440
+ const postImageControllerSetupFunction = (controller) => {
441
+ const scaleToImg2ImgImage = (e) => {
442
+ const picked = controller.optionPickingControler.getCurrentOption();
443
+ if (picked !== _IMAGE) return;
444
+ const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
445
+ const img = new Image();
446
+ img.src = URL.createObjectURL(files[0]);
447
+ img.onload = () => {
448
+ controller.setAspectRatio(`${img.naturalWidth}:${img.naturalHeight}`)
449
+ };
450
+ }
451
+
452
+ _IMAGE_INPUT_CONTAINER_IDS.forEach(imageContainerId => {
453
+ const imageContainer = document.getElementById(imageContainerId);
454
+ const inputElement = imageContainer.querySelector('input');
455
+ inputElement.parentElement.addEventListener('drop', scaleToImg2ImgImage);
456
+ inputElement.addEventListener('change', scaleToImg2ImgImage);
457
+ })
458
+
459
+ addImg2ImgTabSwitchClickListeners(controller);
460
+ }
461
+
462
+ document.addEventListener("DOMContentLoaded", () => {
463
+ AspectRatioController.observeStartup(
464
+ "__txt2imgAspectRatioController",
465
+ "txt2img",
466
+ [_OFF, _LOCK]
467
+ );
468
+ AspectRatioController.observeStartup(
469
+ "__img2imgAspectRatioController",
470
+ "img2img",
471
+ [_OFF, _LOCK, _IMAGE],
472
+ postImageControllerSetupFunction
473
+ );
474
+ });
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/scripts/sd_webui_aspect_ratio_helper.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ from aspect_ratio_helper.main import AspectRatioStepScript
4
+
5
+ __all__ = ['AspectRatioStepScript']
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/style.css ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #txt2img_size_toolbox, #img2img_size_toolbox {
2
+ min-width: unset !important;
3
+ gap: 0;
4
+ }
5
+
6
+ #txt2img_ratio, #img2img_ratio {
7
+ padding: 0px;
8
+ min-width: unset;
9
+ max-width: fit-content;
10
+ }
11
+
12
+ #txt2img_ratio select, #img2img_ratio select {
13
+ background: var(--background-fill-primary);
14
+ border: 1px solid var(--block-border-color);
15
+ color: var(--block-label-text-color);
16
+ -webkit-appearance: none;
17
+ -moz-appearance: none;
18
+ appearance: none;
19
+ background-image: none;
20
+ tab-size: 4;
21
+ font-size: 14px;
22
+ line-height: 1.4;
23
+ box-sizing: border-box;
24
+ position: relative;
25
+ border-radius: 8px;
26
+ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
27
+ padding-right: 1px;
28
+ margin-bottom: 10px;
29
+ padding-left: 2px;
30
+ text-align: center;
31
+ min-width: 2.5em;
32
+ }
33
+
34
+ .arh-btn-row button {
35
+ min-width: fit-content;
36
+ }
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tests/__init__.py ADDED
File without changes
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tests/_util_test.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import pytest
4
+
5
+ import aspect_ratio_helper._constants as _constants
6
+ import aspect_ratio_helper._util as _util
7
+
8
+
9
+ @pytest.mark.parametrize(
10
+ 'num, expected',
11
+ [
12
+ (50, 'x0.5'),
13
+ (150, 'x1.5'),
14
+ (175, 'x1.75'),
15
+ (250, 'x2.5'),
16
+ ],
17
+ )
18
+ def test_display_multiplication(num, expected):
19
+ assert _util.display_multiplication(num) == expected
20
+
21
+
22
+ @pytest.mark.parametrize(
23
+ 'num, expected',
24
+ [
25
+ (50, '50%'),
26
+ (75, '75%'),
27
+ (100, '100%'),
28
+ (150, '150%'),
29
+ (250, '250%'),
30
+ ],
31
+ )
32
+ def test_display_raw_percentage(num, expected):
33
+ assert _util.display_raw_percentage(num) == expected
34
+
35
+
36
+ @pytest.mark.parametrize(
37
+ 'num, expected_output', [
38
+ (150, '+50%'),
39
+ (100, '0%'),
40
+ (50, '-50%'),
41
+ (0, '-100%'),
42
+ (200, '+100%'),
43
+ (75, '-25%'),
44
+ ],
45
+ )
46
+ def test_display_minus_and_plus(num, expected_output):
47
+ assert _util.display_minus_and_plus(num) == expected_output
48
+
49
+
50
+ @pytest.mark.parametrize(
51
+ 'width, height, pct, expected',
52
+ [
53
+ pytest.param(200, 400, 0.5, (96, 200), id='50_percent_scale_down'),
54
+ pytest.param(100, 200, 2.0, (200, 400), id='200_percent_scale_up'),
55
+ pytest.param(100, 200, 1.1, (112, 224), id='10_percent_scale_up'),
56
+ pytest.param(100, 200, 0.9, (88, 176), id='10_percent_scale_down'),
57
+ pytest.param(100, 200, 0.0, (64, 128), id='scale_full_down'),
58
+ pytest.param(
59
+ _constants.MIN_DIMENSION - 1,
60
+ _constants.MIN_DIMENSION - 1,
61
+ 0.5,
62
+ (_constants.MIN_DIMENSION, _constants.MIN_DIMENSION),
63
+ id='scale_belowMIN_DIMENSION',
64
+ ),
65
+ pytest.param(
66
+ _constants.MAX_DIMENSION + 1,
67
+ _constants.MAX_DIMENSION + 1,
68
+ 2.0,
69
+ (_constants.MAX_DIMENSION, _constants.MAX_DIMENSION),
70
+ id='scale_aboveMAX_DIMENSION',
71
+ ),
72
+ ],
73
+ )
74
+ def test_scale_by_percentage(
75
+ width, height, pct, expected,
76
+ ):
77
+ assert _util.scale_by_percentage(
78
+ width, height, pct,
79
+ ) == expected
80
+
81
+
82
+ @pytest.mark.parametrize(
83
+ 'width, height, max_dim, expected',
84
+ [
85
+ # pytest.param(
86
+ # 100, 200, 400, (200, 400),
87
+ # id='scale_up_to_max_dimension_horizontally',
88
+ # ),
89
+ # pytest.param(
90
+ # 200, 100, 400, (400, 200),
91
+ # id='scale_up_to_max_dimension_vertically',
92
+ # ),
93
+ # pytest.param(
94
+ # 400, 64, 400, (400, 64),
95
+ # id='no_scale_up_needed_with_max_dimension_width',
96
+ # ),
97
+ # pytest.param(
98
+ # 64, 400, 400, (64, 400),
99
+ # id='no_scale_up_needed_with_max_dimension_height',
100
+ # ),
101
+ # pytest.param(
102
+ # _constants.MIN_DIMENSION,
103
+ # _constants.MIN_DIMENSION,
104
+ # _constants.MAX_DIMENSION,
105
+ # (_constants.MAX_DIMENSION, _constants.MAX_DIMENSION),
106
+ # id='scale_from_min_to_max',
107
+ # ),
108
+ # pytest.param(
109
+ # _constants.MAX_DIMENSION,
110
+ # _constants.MAX_DIMENSION,
111
+ # _constants.MIN_DIMENSION,
112
+ # (_constants.MIN_DIMENSION, _constants.MIN_DIMENSION),
113
+ # id='scale_from_max_to_min',
114
+ # ),
115
+ pytest.param(
116
+ _constants.MIN_DIMENSION, 32, _constants.MIN_DIMENSION,
117
+ (128, _constants.MIN_DIMENSION),
118
+ id='scale_below_min_height_dimension_clamps_retains_ar',
119
+ ),
120
+ pytest.param(
121
+ 32, _constants.MIN_DIMENSION, _constants.MIN_DIMENSION,
122
+ (_constants.MIN_DIMENSION, 128),
123
+ id='scale_below_min_width_dimension_clamps_retains_ar',
124
+ ),
125
+ # pytest.param(
126
+ # _constants.MAX_DIMENSION, 4096, _constants.MAX_DIMENSION,
127
+ # (1024, _constants.MAX_DIMENSION),
128
+ # id='scale_above_max_height_dimension_clamps_retains_ar',
129
+ # ),
130
+ # pytest.param(
131
+ # 4096, _constants.MAX_DIMENSION, _constants.MAX_DIMENSION,
132
+ # (_constants.MAX_DIMENSION, 1024),
133
+ # id='scale_above_max_width_dimension_clamps_retains_ar',
134
+ # ),
135
+ # pytest.param(
136
+ # 64, 64, _constants.MIN_DIMENSION - 1,
137
+ # (_constants.MIN_DIMENSION, _constants.MIN_DIMENSION),
138
+ # id='scale_dimension_below_min_dimension_clamps_retains_ar',
139
+ # ),
140
+ # pytest.param(
141
+ # 64, 64, _constants.MAX_DIMENSION + 1,
142
+ # (_constants.MAX_DIMENSION, _constants.MAX_DIMENSION),
143
+ # id='scale_dimension_above_max_dimension_clamps_retains_ar',
144
+ # ),
145
+ ],
146
+ )
147
+ def test_scale_dimensions_to_max_dim(
148
+ width, height, max_dim, expected,
149
+ ):
150
+ assert _util.scale_dimensions_to_max_dim(
151
+ width, height, max_dim,
152
+ ) == expected
153
+
154
+
155
+ @pytest.mark.parametrize(
156
+ 'width, height, min_dim, expected',
157
+ [
158
+ pytest.param(
159
+ 100, 200, 400, (400, 800),
160
+ id='scale_up_to_min_dimension_with_ar_preservation',
161
+ ),
162
+ pytest.param(
163
+ 200, 100, 400, (800, 400),
164
+ id='scale_up_to_min_dimension_with_ar_preservation',
165
+ ),
166
+ pytest.param(
167
+ 100, 100, 400, (400, 400),
168
+ id='no_scale_up_needed_with_min_dimension',
169
+ ),
170
+ pytest.param(
171
+ _constants.MIN_DIMENSION, _constants.MIN_DIMENSION, _constants.MAX_DIMENSION,
172
+ (_constants.MAX_DIMENSION, _constants.MAX_DIMENSION),
173
+ id='scale_up_to_max_dimension_with_ar_preservation',
174
+ ),
175
+ pytest.param(
176
+ _constants.MAX_DIMENSION, _constants.MAX_DIMENSION, _constants.MIN_DIMENSION,
177
+ (_constants.MIN_DIMENSION, _constants.MIN_DIMENSION),
178
+ id='scale_down_to_min_dimension_with_ar_preservation',
179
+ ),
180
+ pytest.param(
181
+ 100, 100, _constants.MAX_DIMENSION,
182
+ (_constants.MAX_DIMENSION, _constants.MAX_DIMENSION),
183
+ id='scale_up_to_max_dimension_with_ar_preservation',
184
+ ),
185
+ ],
186
+ )
187
+ def test_scale_dimensions_to_min_dim(
188
+ width, height, min_dim, expected,
189
+ ):
190
+ assert _util.scale_dimensions_to_min_dim(
191
+ width, height, min_dim,
192
+ ) == expected
193
+
194
+
195
+ class SharedOpts:
196
+ def __init__(self, options=None, defaults=None):
197
+ self.options = options or {}
198
+ self.defaults = defaults or {}
199
+
200
+ def __getattr__(self, key):
201
+ try:
202
+ return self.options[key]
203
+ except KeyError:
204
+ raise AttributeError()
205
+
206
+ def get_default(self, key):
207
+ return self.defaults.get(key, None)
208
+
209
+
210
+ def test_safe_opt_util():
211
+ shared_opts = SharedOpts(options={'key': 'value'})
212
+ assert _util.safe_opt_util(shared_opts, 'key', {}) == 'value'
213
+
214
+
215
+ def test_safe_opt_util_none():
216
+ shared_opts = SharedOpts(options={'key': None}, defaults={'key': 'value'})
217
+ assert _util.safe_opt_util(shared_opts, 'key', {}) == 'value'
218
+
219
+
220
+ def testsafe_opt_util_default_a():
221
+ shared_opts = SharedOpts(
222
+ defaults={'key': 'default_a'},
223
+ )
224
+ assert _util.safe_opt_util(
225
+ shared_opts, 'key', {'key': 'default_b'},
226
+ ) == 'default_a'
227
+
228
+
229
+ def test_safe_opt_util_default_b():
230
+ shared_opts = SharedOpts(defaults={'key': None})
231
+ assert _util.safe_opt_util(
232
+ shared_opts, 'key', {'key': 'default_b'},
233
+ ) == 'default_b'
234
+
235
+
236
+ @pytest.mark.parametrize(
237
+ 'options', ({'key': None}, {}),
238
+ )
239
+ def test_safe_opt_safe_return_no_defaults_b(options):
240
+ shared_opts = SharedOpts(options=options)
241
+ assert _util.safe_opt_util(shared_opts, 'unknown_key', {}) is None
242
+
243
+
244
+ @pytest.mark.parametrize(
245
+ 'value, expected', [
246
+ (0, 0),
247
+ (7, 8),
248
+ (10, 8),
249
+ (16, 16),
250
+ (23, 24),
251
+ (32, 32),
252
+ (33, 32),
253
+ (100, 96),
254
+ (10.5, 8),
255
+ (15.3, 16),
256
+ (21.8, 24),
257
+ (33.9, 32),
258
+ (98.7, 96),
259
+ ],
260
+ )
261
+ def test_round_to_multiple_of_8(value, expected):
262
+ assert _util.round_to_multiple_of_8(value) == expected
263
+
264
+
265
+ @pytest.mark.parametrize(
266
+ 'width, height, aspect_ratio, expected', [
267
+ (100, 100, 1.0, (96, 96)),
268
+ (3000, 2000, 1.5, (2048, 1368)),
269
+ (500, 8000, 0.5, (1024, 2048)),
270
+ (500, 300, 2.0, (496, 304)),
271
+ (100, 200, 0.5, (96, 200)),
272
+ (500, 500, 1.2, (496, 496)),
273
+ (2048, 2048, 1.0, (2048, 2048)),
274
+ (2049, 2048, 1.0, (2048, 2048)),
275
+ (2048, 2049, 1.0, (2048, 2048)),
276
+ (2049, 2049, 1.0, (2048, 2048)),
277
+ (63, 63, 1.0, (64, 64)),
278
+ (2050, 2050, 1.0, (2048, 2048)),
279
+ (63, 64, 1.0, (64, 64)),
280
+ (64, 63, 1.0, (64, 64)),
281
+ (64, 64, 1.0, (64, 64)),
282
+ (63, 63, 1.0, (64, 64)),
283
+ (2050, 63, 1.0, (2048, 2048)),
284
+ (63, 2050, 1.0, (2048, 2048)),
285
+ (2050, 2050, 0.01, (64, 2048)),
286
+ (100.5, 100.5, 1.0, (104, 104)),
287
+ (200.3, 100.7, 0.5, (200, 104)),
288
+ ],
289
+ )
290
+ def test_clamp_to_boundaries(width, height, aspect_ratio, expected):
291
+ assert _util.clamp_to_boundaries(width, height, aspect_ratio) == expected
TestingforfaivsixEx/content/eichellis/extensions/aspect-ratio/tox.ini ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [tox]
2
+ envlist = py310, py311
3
+
4
+ [testenv]
5
+ deps = pytest
6
+ commands = pytest
TestingforfaivsixEx/content/eichellis/extensions/batch-link/.github/CODEOWNERS ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Global rule:
2
+ * @etherealxx
TestingforfaivsixEx/content/eichellis/extensions/batch-link/.gitignore ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bak
2
+ *.backup
3
+ imageratio.*
4
+ *.lnk
5
+ tempCodeRunnerFile.python
6
+ .DS_Store
7
+ gradiovenv/
8
+
9
+ # Byte-compiled / optimized / DLL files
10
+ __pycache__/
11
+ *.py[cod]
12
+ *$py.class
13
+
14
+ # C extensions
15
+ *.so
16
+
17
+ # Distribution / packaging
18
+ .Python
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ wheels/
31
+ share/python-wheels/
32
+ *.egg-info/
33
+ .installed.cfg
34
+ *.egg
35
+ MANIFEST
36
+
37
+ # PyInstaller
38
+ # Usually these files are written by a python script from a template
39
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
40
+ *.manifest
41
+ *.spec
42
+
43
+ # Installer logs
44
+ pip-log.txt
45
+ pip-delete-this-directory.txt
46
+
47
+ # Unit test / coverage reports
48
+ htmlcov/
49
+ .tox/
50
+ .nox/
51
+ .coverage
52
+ .coverage.*
53
+ .cache
54
+ nosetests.xml
55
+ coverage.xml
56
+ *.cover
57
+ *.py,cover
58
+ .hypothesis/
59
+ .pytest_cache/
60
+ cover/
61
+
62
+ # Translations
63
+ *.mo
64
+ *.pot
65
+
66
+ # Django stuff:
67
+ *.log
68
+ local_settings.py
69
+ db.sqlite3
70
+ db.sqlite3-journal
71
+
72
+ # Flask stuff:
73
+ instance/
74
+ .webassets-cache
75
+
76
+ # Scrapy stuff:
77
+ .scrapy
78
+
79
+ # Sphinx documentation
80
+ docs/_build/
81
+
82
+ # PyBuilder
83
+ .pybuilder/
84
+ target/
85
+
86
+ # Jupyter Notebook
87
+ .ipynb_checkpoints
88
+
89
+ # IPython
90
+ profile_default/
91
+ ipython_config.py
92
+
93
+ # pyenv
94
+ # For a library or package, you might want to ignore these files since the code is
95
+ # intended to run in multiple environments; otherwise, check them in:
96
+ # .python-version
97
+
98
+ # pipenv
99
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
100
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
101
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
102
+ # install all needed dependencies.
103
+ #Pipfile.lock
104
+
105
+ # poetry
106
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
107
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
108
+ # commonly ignored for libraries.
109
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
110
+ #poetry.lock
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ #pdm.lock
115
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
116
+ # in version control.
117
+ # https://pdm.fming.dev/#use-with-ide
118
+ .pdm.toml
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
TestingforfaivsixEx/content/eichellis/extensions/batch-link/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Etherealxx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
TestingforfaivsixEx/content/eichellis/extensions/batch-link/README.md ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <br />
2
+
3
+ <div align="center">
4
+ <a href="https://github.com/etherealxx/batchlinks-downloader">
5
+ <img src="images/batchlinks_logo.png" alt="Logo" width="528">
6
+ </a>
7
+
8
+ <h3 align="center">BatchLinks Downloader</h3>
9
+
10
+ <p align="center">
11
+ Batch-downloading models and stuff in stable-diffusion-webui colab made simple and fast.
12
+ <br />
13
+ <a href="https://github.com/etherealxx/batchlinks-downloader"><strong></strong></a>
14
+ <br />
15
+ <a href="https://github.com/etherealxx/batchlinks-downloader/issues">Report Bug</a>
16
+ ·
17
+ <a href="https://github.com/etherealxx/batchlinks-downloader/discussions/new?category=ideas">Request Feature</a>
18
+ </p>
19
+
20
+ </div>
21
+
22
+ <!-- TOC -->
23
+ <!-- - [Installation](#installation)
24
+ - [About](#about)
25
+ - [Example](#example)
26
+ - [Syntax](#syntax)
27
+ - [Hashtag](#hashtag)
28
+ - [Links](#links)
29
+ - [Double Hashtag](#double-hashtag)
30
+ - [Others](#others)
31
+ - [Valid Hashtags](#valid-hashtags)
32
+ - [How to get the direct links (Important!)](#how-to-get-the-direct-links-important)
33
+ - [Huggingface's download method](#huggingfaces-download-method)
34
+ - [Additional Syntax](#additional-syntax)
35
+ - [Rename Downloaded Files](#rename-downloaded-files)
36
+ - [Running Shell Commands](#running-shell-commands)
37
+ - [Extract Everyting (`@extract`)](#extract-everyting-extract)
38
+ - [Custom Hashtag Path (`@new`)](#custom-hashtag-path-new)
39
+ - [Custom Direct Link Download with `aria2` (`@aria2`)](#custom-direct-link-download-with-aria2-aria2)
40
+ - [Gradio Queue](#gradio-queue)
41
+ - [Logging](#logging)
42
+ - [Cancel](#cancel)
43
+ - [Progress Bar](#progress-bar)
44
+ - [Changes if `--gradio-queue` is off](#changes-if---gradio-queue-is-off)
45
+ - [Other Features](#other-features)
46
+ - [Notification](#notification)
47
+ - [Copy From Pastebin](#copy-from-pastebin)
48
+ - [SDless mode](#sdless-mode)
49
+ - [Local Installation Support](#local-installation-support)
50
+ - [Debug Mode (Developer only)](#debug-mode-developer-only)
51
+ - [Release Notes](#release-notes)
52
+ - [Roadmap](#roadmap)
53
+ - [Known Bugs](#known-bugs)
54
+ - [Known Fixed Bugs](#known-fixed-bugs)
55
+ - [Contributing](#contributing)
56
+ - [Contact](#contact)
57
+ - [Acknowledgments](#acknowledgments) -->
58
+ <!-- /TOC -->
59
+
60
+ <details>
61
+ <summary>Table of Contents</summary>
62
+ <ol>
63
+ <li><a href="#installation">Installation</a></li>
64
+ <li><a href="#about">About</a></li>
65
+ <li><a href="#example">Example</a></li>
66
+ <li><a href="#syntax">Syntax</a></li>
67
+ <ul><li><a href="#hashtag">Hashtag</a></li></ul>
68
+ <ul><li><a href="#links">Links</a></li></ul>
69
+ <ul><li><a href="#double-hashtag">Double Hashtag</a></li></ul>
70
+ <ul><li><a href="#others">Others</a></li></ul>
71
+ <ul><li><a href="#valid-hashtags">Valid Hashtags</a></li></ul>
72
+ <ul><li><a href="#how-to-get-the-direct-links-important">How to get the direct links (Important!)</a></li></ul>
73
+ <ul><li><a href="#huggingfaces-download-method">Huggingface's download method</a></li></ul>
74
+ <li><a href="#additional-syntax">Additional Syntax</a></li>
75
+ <ul><li><a href="#rename-downloaded-files">Rename Downloaded Files</a></li></ul>
76
+ <ul><li><a href="#running-shell-commands">Running Shell Commands</a></li></ul>
77
+ <ul><li><a href="#extract-everyting-extract">Extract Everyting (`@extract`)</a></li></ul>
78
+ <ul><li><a href="#custom-hashtag-path-new">Custom Hashtag Path (`@new`)</a></li></ul>
79
+ <ul><li><a href="#custom-direct-link-download-with-aria2-aria2">Custom Direct Link Download with `aria2` (`@aria2`)</a></li></ul>
80
+ <li><a href="#gradio-queue">Gradio Queue</a></li>
81
+ <ul><li><a href="#logging">Logging</a></li></ul>
82
+ <ul><li><a href="#cancel">Cancel</a></li></ul>
83
+ <ul><li><a href="#progress-bar">Progress Bar</a></li></ul>
84
+ <ul><li><a href="#changes-if---gradio-queue-is-off">Changes if `--gradio-queue` is off</a></li></ul>
85
+ <li><a href="#other-features">Other Features</a></li>
86
+ <ul><li><a href="#notification">Notification</a></li></ul>
87
+ <ul><li><a href="#copy-from-pastebin">Copy From Pastebin</a></li></ul>
88
+ <ul><li><a href="#sdless-mode">SDless mode</a></li></ul>
89
+ <ul><li><a href="#local-installation-support">Local Installation Support</a></li></ul>
90
+ <ul><li><a href="#debug-mode-developer-only">Debug Mode (Developer only)</a></li></ul>
91
+ <li><a href="#release-notes">Release Notes</a></li>
92
+ <li><a href="#roadmap">Roadmap</a></li>
93
+ <li><a href="#known-bugs">Known Bugs</a></li>
94
+ <ul><li><a href="#known-fixed-bugs">Known Fixed Bugs</a></li></ul>
95
+ <li><a href="#contributing">Contributing</a></li>
96
+ <li><a href="#contact">Contact</a></li>
97
+ <li><a href="#acknowledgments">Acknowledgments</a></li>
98
+ </li>
99
+ </ol>
100
+ </details>
101
+
102
+ [does this repo still maintained?](https://github.com/etherealxx/batchlinks-webui/blob/main/regardingthisrepo.md)
103
+
104
+ ## Installation
105
+
106
+ Copy this line into your colab installation cell. Or into a new cell if you already launched the webui.
107
+
108
+ ```
109
+ !git clone https://github.com/etherealxx/batchlinks-webui /content/stable-diffusion-webui/extensions/batchlinks-webui
110
+ ```
111
+
112
+ or, you can copy the url of this repo and install it via webui and restart the UI.<br/>
113
+ <img src="images/ext_installer.jpg" alt="Logo" width="362"><br/>
114
+ (If `gradio no interface is running` or `bad gateway` shows up when restarting the UI, that means you need to restart the cell anyway 😅)
115
+
116
+ <!--
117
+ or, if your colab use the newer version of webui (gradio version above 3.16.0) you can use this instead (it adds a little progress bar)
118
+
119
+ ```
120
+ !git clone -b gradio-v3-16-2 https://github.com/etherealxx/batchlinks-webui /content/stable-diffusion-webui/extensions/batchlinks-webui
121
+ ```
122
+ -->
123
+
124
+ Using `--gradio-queue` on the launch.py argument is highly recommended, as it enables this extension to show download progress bar on the UI and a cancel button. The option itself has no negative effect on the webui. [Read more here.](https://github.com/etherealxx/batchlinks-webui#gradio-queue)<br/>
125
+ <img src="images/queue.jpg" alt="Logo" width="300"><br/>
126
+
127
+ You can also run this extension in [SDless mode](https://github.com/etherealxx/batchlinks-webui#sdless-mode) btw.
128
+
129
+ While it's not recommended to use this extension on your local installation, you can use this extension on Windows. [More here.](https://github.com/etherealxx/batchlinks-webui#local-installation-support)
130
+
131
+ ## About
132
+
133
+ This extension will streamline your downloads on your [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) colab session. Paste the links you need to download (or you can upload a txt file containing the links), use the hashstag syntax to choose the download location (see below), and hit the `Download All` button to download them!
134
+
135
+ ## Example
136
+
137
+ Look at this example<br/>
138
+ <img src="images/example.jpg" alt="Logo" width="738"><br/>
139
+
140
+ ```
141
+ #model
142
+ https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix3/AOM3_orangemixs.safetensors
143
+ #vae
144
+ https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt
145
+ #embed
146
+ https://huggingface.co/datasets/Nerfgun3/bad_prompt/resolve/main/bad_prompt_version2.pt
147
+ https://huggingface.co/etherealxx/whoseisthis/resolve/main/bad_artist.pt
148
+ #lora
149
+ https://civitai.com/api/download/models/8840 ##1-mb-lora-trained-in-5-mins-that-does-the-same-thing-as-25-gb-model-but-better
150
+ https://civitai.com/api/download/models/6891 ##sans undertale
151
+ https://mega.nz/file/gAxTWBAI#uL7EZay-OND5G6ELJlGfUNG0s7Q4TynZKqFdvs0v0tc ##agent8-finetune
152
+ https://mega.nz/file/oU43FSTY#vwAfsAb7RKJ4xtsSP7uzrKpWhh1y8BdpIBFurwsVP2o ##agent8-dreambooth
153
+ #hypernet
154
+ https://cdn.discordapp.com/attachments/1070489470127841381/1070489471964954684/MomopocoV3.pt
155
+ ```
156
+
157
+ This piece of lines will be read from top to bottom. Every hashtag, it will change the current output directory to said directory (see below). So what this example do is it will download `AOM3` model to the model folder, then it will download the vae and put it to the Vae folder. Next it will download two embed, `bad prompt` and `bad artist`. Next it will download several LoRAs from CivitAI and MEGA, and put it to the Lora folder. Lastly, it changes the directory to hypernet directory, then
158
+
159
+ You can also copy that example and paste it to a `.txt` file to use later. You can load a `.txt` file containing that piece of lines directly from the UI.
160
+
161
+ When the items is downloading, you can inspect the running code on the colab cell, or just take a coffee and chill☕. If you activate logging, you can inspect the download progress from the UI, more [here](https://github.com/etherealxx/batchlinks-webui#logging)
162
+
163
+ When the download is complete, the downloaded file will be listed<br/>
164
+ <img src="images/downloaded.jpg" alt="Logo" width="745"><br/>
165
+
166
+ ## Syntax
167
+
168
+ #### Hashtag
169
+ - Hashtag means change current output directory to this directory. `#model` means every links below this hashtag, will be downloaded to _/content/stable-diffusion-webui/models/Stable-diffusion_, until it hits another hashtag, which will change the output directory again. See [below](https://github.com/etherealxx/batchlinks-webui#valid-hashtags) for valid hashtags.
170
+
171
+ Note: If you use some colab that purposefully uses `sd-webui-additional-networks` extension to load Lora, use `#addnetlora` instead of `#lora`. It will download the lora to where it supposed to be.
172
+
173
+ #### Links
174
+ - Links are the main things you wants to be downloaded. Current supported links are from:
175
+ - Huggingface (https://huggingface.co/)
176
+ - MEGA (https://mega.nz/) {using `mega-cmd`}
177
+ - CivitAI (https://civitai.com/)
178
+ - Discord attachments (https://cdn.discordapp.com/attachments/)
179
+ - catbox (https://files.catbox.moe)
180
+ - Github (https://github.com or https://raw.githubusercontent.com)
181
+ - Google Drive (https://drive.google.com) {using `gdown`}
182
+ - Pixeldrain (https://pixeldrain.com/u/)
183
+ - Mediafire (https://www.mediafire.com/file) {using `mediafire-dl`}
184
+ - anonfiles (https://anonfiles.com)
185
+
186
+ Every links other than that will be ignored. Keep in mind the only supported links are direct download links (see [here](https://github.com/etherealxx/batchlinks-downloader/blob/main/howtogetthedirectlinks.md)). For Huggingface, Civitai (model page link method), Discord attachments, catbox, pixeldrain, and anonfiles, there will be four different method of downloading offered (see [below](https://github.com/etherealxx/batchlinks-webui#huggingfaces-download-method)). For MEGA, it will use `mega-cmd` to download. For Github, if, the link is a raw file, it will download the file. Else, it will use `git clone`, useful to clone extension repo into the webui extension folder.
187
+
188
+ More about CivitAI download method [here](https://github.com/etherealxx/batchlinks-webui#civitais-download-method).
189
+
190
+ #### Double Hashtag
191
+ - Double hashtag means comment. You can put double hashtag in the same line of the link and it will be ignored (keep in mind to put the link first then the double hashtag)
192
+
193
+ #### Others
194
+ - Other texts will be ignored.
195
+
196
+ ### Valid Hashtags
197
+
198
+ `#model`, `#models`, `#checkpoint`, or `#checkpoints` will put the downloaded file to _/content/stable-diffusion-webui/models/Stable-diffusion_
199
+
200
+ `#embedding`, `#embeddings`, `#embed`, `#embeds`, `#textualinversion`, or `#ti` will put the downloaded file to _/content/stable-diffusion-webui/embeddings_
201
+
202
+ `#vae` or `#vaes` will put the downloaded file to _/content/stable-diffusion-webui/models/VAE_
203
+
204
+ `#hypernetwork`, `#hypernetworks`, `#hypernet`, `#hypernets`, `#hynet`, or `#hynets` will put the downloaded file to _/content/stable-diffusion-webui/models/hypernetworks_
205
+
206
+ `#lora` or `#loras` will put the downloaded file to _/content/stable-diffusion-webui/models/Lora_
207
+
208
+ `#addnetlora`, `#loraaddnet`, `#additionalnetworks`, or `#addnet` will put the downloaded file to _/content/stable-diffusion-webui/extensions/sd-webui-additional-networks/models/lora_
209
+
210
+ `#aestheticembedding` or `#aestheticembed` will put the downloaded file to _content/stable-diffusion-webui/extensions/stable-diffusion-webui-aesthetic-gradients/aesthetic_embeddings_
211
+
212
+ `#controlnet` or `#cnet` will put the downloaded file to _/content/stable-diffusion-webui/extensions/sd-webui-controlnet/models_
213
+
214
+ `#upscale` or `#upscaler` will put the downloaded file to _/content/stable-diffusion-webui/models/ESRGAN_
215
+
216
+ `#lycoris`, `#locon`, or `#loha` will put the downloaded file to _/content/stable-diffusion-webui/extensions/sd-webui-additional-networks/models/lora/lycoris_
217
+
218
+ `#altmodel` or `#altmodels` will put the downloaded file to the path you choose when using `--ckptdir` argument on `launch.py` line. If you didn't use that argument, this hashtag will points to the same directory as `#model`
219
+
220
+ _Lycoris/Locon/Loha_ will works just fine if you use `#addnetlora` instead, as long as you have both [addnet extension](https://github.com/kohya-ss/sd-webui-additional-networks) and [locon extension](https://github.com/KohakuBlueleaf/a1111-sd-webui-locon) installed. It's unclear if it's can be loaded by native auto1111 lora. (Tell me if you know more about this.)
221
+
222
+ Github links (if it does not contain `/raw/` or `/release/download/` in it) doesn't need hashtag. It will always considered as webui extension, and the repository will be cloned to _/content/stable-diffusion-webui/extensions/(reponame)_
223
+
224
+ ### How to get the direct links (Important!)
225
+
226
+ See [here](https://github.com/etherealxx/batchlinks-downloader/blob/main/howtogetthedirectlinks.md)
227
+
228
+ ### Huggingface's download method
229
+
230
+ So there's four supported method: `gdown`, `wget`, `curl` and `aria2`. Use whatever, really. The difference between them are actually little. Myself love using `gdown` since the output is cleaner than the others. `aria2` has the fastest download speed though.
231
+
232
+ <!-- ### Civitai's download method
233
+
234
+ There are two ways to download links from Civit. The `model page link` method, and the `direct link` method.
235
+
236
+ The `model page link` method **will automatically** choose the directory of the saved model without even using hashtag. It will download the default model of a model page. The advantage of this method is you will also get the model preview images that can shows up on the latest version of [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui). This method will also uses the same download protocol as huggingface's (see above). <br/>The `model page link` method's link starts with **https://civitai.com/models/**
237
+
238
+ The `direct link` method is the old method, which needs hashtag for the downloaded model to be properly placed, and uses `request` module to download. The advantage of this method is you can choose what model variation you want to download by grabbing the right url. See [here](https://github.com/etherealxx/batchlinks-downloader/blob/main/howtogetthedirectlinks.md) for more.<br/>The `direct link` method's link starts with **https://civitai.com/api/download/models/**
239
+
240
+ Here's the difference of syntax between two methods:
241
+
242
+ Model page link:
243
+ ```
244
+ https://civitai.com/models/4823/deliberate
245
+ ```
246
+ Direct link:
247
+ ```
248
+ #model
249
+ https://civitai.com/api/download/models/5616
250
+ ```
251
+
252
+ Check [this page](https://github.com/etherealxx/batchlinks-downloader/blob/main/howtogetthedirectlinks.md) to learn more on how to get the links for each methods. -->
253
+
254
+ ## Additional Syntax
255
+ ### Rename Downloaded Files
256
+ Using `>` symbol, you can rename files. Take this for example<br/>
257
+ <img src="images/rename.jpg" alt="Log" width="407"><br/>
258
+ Mostly catbox file has random name, by using `>` symbol after the link, you can type the desired name on the right. (Don't forget the extension)
259
+
260
+ ### Running Shell Commands
261
+ You can run shell commands by using `!` in front of the command you want, just like in google colab cells. Then press the `Download All!` button. (Sure, it doesn't download anything, but, well😅)<br/>
262
+ <img src="images/shell1.jpg" alt="Log" width="200">
263
+ <img src="images/shell2.jpg" alt="Log" width="200"><br/>
264
+ You can run many lines at once too!
265
+
266
+ ### Extract Everyting (`@extract`)
267
+ You can use `@extract` to extract every `*.7z`, `*.rar`, and `*.zip` on current directory).
268
+ ```
269
+ #lora
270
+ <example lora .zip link>
271
+ @extract
272
+ #embed
273
+ ```
274
+ This will extract everything on Lora folder, since the code runs from top to bottom, and when the `@extract` executes, the current directory is still on Lora folder.
275
+
276
+ ### Custom Hashtag Path (`@new`)
277
+ You can use `@new <hashtagname> <directory>` to make a new usable hashtag and assign a directory path to it.<br/>For example, you type this and press the `Download All!` button:
278
+ ```
279
+ @new #private /content/stable-diffusion-webui/outputs
280
+ #private
281
+ <example model link>
282
+ ```
283
+ This will make a new hashtag `#private`, make it points to _/content/stable-diffusion-webui/outputs_, set `#private` as current directory, then download whatever into it. You can check if the new hashtag is assigned successfully by looking at the hashtag table on the right/bottom of the screen.
284
+
285
+ ### Custom Direct Link Download with `aria2` (`@aria2`)
286
+ If there are other direct links that isn't supported by Batchlinks, you can use `@aria` or `@aria2` custom command to download it. The main syntax is:
287
+ ```
288
+ @aria2 {link} {path/hashtag} > {filename}
289
+ ```
290
+ You can change `@aria2` with `@aria`, both works. Both the `path/hashtag` and `filename` is optional. This command was made to avoid hassle writing this:
291
+ ```
292
+ aria2c --summary-interval=1 --console-log-level=error -c -x 16 -s 16 -k 1M {link} -d {path} -o {filename}
293
+ ```
294
+ There are several ways to use it. Here i use a [20MB download test file](http://212.183.159.230/20MB.zip) as an example.
295
+ ```
296
+ @aria2 http://212.183.159.230/20MB.zip
297
+ ```
298
+ ☝️ This will download the file into the current directory (where the hashtags points to). So if before that line you use `#vae`, it will be downloaded to the vae directory. If there are no hashtags before, it'll be sent to the default `#model` directory. The filename will be the last part of the link (`512MB.zip`).
299
+ ```
300
+ @aria2 http://212.183.159.230/20MB.zip #vae
301
+ ```
302
+ ☝️ This will download the file into where `#vae` points to (which is the vae directory). You can use custom hashtag here as well.
303
+ ```
304
+ @aria2 http://212.183.159.230/20MB.zip /content/stable-diffusion-webui
305
+ ```
306
+ ☝️ This will download the file into the written path, which is _/content/stable-diffusion-webui_. Make sure it is a folder path, not a file path.
307
+ ```
308
+ @aria2 http://212.183.159.230/20MB.zip /content/stable-diffusion-webui > 20megabytes.zip
309
+ ```
310
+ ☝️ This will download the file into the written path and rename the file into `20megabytes.zip`. Remember to make sure to write the extension too.
311
+
312
+ ## Gradio Queue
313
+
314
+ If you use --gradio-queue argument on `launch.py`, some feature will be activated.
315
+
316
+ ### Logging
317
+
318
+ <!-- If you use latest version of [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui), or webui forks that supports `--gradio-queue` args on launch.py, use it and you will be able to -->
319
+ Enable logging by pressing the `Turn On Logging` radio button, and wait till `Logging activated` shows up and the box is blinking with orange border. Logging will tell you what are you actually downloading right now on the webui. After your download session is completed, it's recommended to turn back off the feature.<br/>
320
+ <img src="images/logging.jpg" alt="Log" width="407"><br/>
321
+
322
+ ### Cancel
323
+ Pressing `cancel` button while download in progress will stops the current session. Useful when at one time the download speeds is too slow. If you're currently downloading a single item, that item will be cancelled, but the other downloaded one will remain intact.<br/>
324
+ <img src="images/cancel.jpg" alt="Log" width="500"><br/>
325
+
326
+ ### Progress Bar
327
+ There will be an additional progress bar that tells you the current activities.<br/>
328
+ <img src="images/progress.jpg" alt="Log" width="500"><br/>
329
+
330
+ ### Changes if `--gradio-queue` is off
331
+ Feature listed above will dissapear, and your only option for download is just `aria2` (speed is priority).<br/>Note that when you pressed the `Download All!` button, **nothing will shows up on the UI**. You need to check the colab console.<br/>
332
+ <img src="images/checkconsole1.jpg" alt="check" width="407"><img src="images/checkconsole2.jpg" alt="off" width="407"><br/>
333
+ Another thing to note is your download session will always be cutted every 70 seconds (to prevent hangs/desync).<br/>
334
+ <img src="images/gradiooff1.jpg" alt="off" width="407"><br/>
335
+ Don't worry, you can continue your session by pressing the `Resume Download` button. It will refresh the links with the one you haven't downloaded yet, then pressing `Download All!` will download the remaining links.<br/>
336
+ <img src="images/gradiooff2.jpg" alt="off" width="407"><br/>
337
+
338
+ ## Other Features
339
+
340
+ ### Notification
341
+
342
+ This extension will play sound effect when the download process is completed. It's somewhat buggy at the moment though.
343
+
344
+ ### Copy From Pastebin
345
+
346
+ You can put your links on pastebin (write it the way you wrote on Batchlinks), put the pastebin link (https://pastebin.com/xxxx) on the link input, and press the 'Copy from Pastebin' button. It will copy all the the links on the pastebin to the UI. Useful to avoid hassle copy and pasting a bunch of text while on mobile.<br/>
347
+ <img src="images/pastebin.png" alt="off" width="400"><br/>
348
+
349
+ ### SDless mode
350
+ This mode will run the extension without the need of stable-diffusion-webui. Good for my own purpose of debugging it😁.<br/>
351
+ <img src="images/sdless.png" alt="off" width="450"><br/>
352
+
353
+ Copy-paste this on a new colab cell then run it:
354
+ ```
355
+ from IPython.display import clear_output
356
+ !pip3 show virtualenv >/dev/null || pip install -q virtualenv
357
+ ![ -d gradiovenv ] || virtualenv gradiovenv
358
+ !git clone https://github.com/etherealxx/batchlinks-webui \
359
+ /content/stable-diffusion-webui/extensions/batchlinks-webui
360
+ pip3 show gradio >/dev/null || pip install -q gradio==3.16.2; \
361
+ pip3 show tqdm >/dev/null || pip3 install -q tqdm
362
+ clear_output(wait=True)
363
+ !source gradiovenv/bin/activate; \
364
+ python /content/stable-diffusion-webui/extensions/batchlinks-webui/scripts/batchlinks-downloader.py
365
+ ```
366
+ or here's the quicker version without venv:
367
+ ```
368
+ !pip install gradio==3.16.2
369
+ !git clone https://github.com/etherealxx/batchlinks-webui /content/stable-diffusion-webui/extensions/batchlinks-webui
370
+ !python /content/stable-diffusion-webui/extensions/batchlinks-webui/scripts/batchlinks-downloader.py
371
+ ```
372
+
373
+ For Windows, run the sdless-windows.bat. Make sure you have `python3` and `gradio` package version 3.16.2 or above. It won't use venv.
374
+
375
+ This one for MacOS. Tested on Mojave. Create a shell script and give execute access to it.
376
+ ```
377
+ #!/usr/bin/env bash
378
+ pip3 show virtualenv >/dev/null || pip3 install virtualenv
379
+ [ -d gradiovenv ] || virtualenv gradiovenv
380
+ git clone https://github.com/etherealxx/batchlinks-webui \
381
+ $HOME/Downloads/stable-diffusion-webui/extensions/batchlinks-webui
382
+ source gradiovenv/bin/activate; \
383
+ pip3 show gradio >/dev/null || pip3 install gradio==3.16.2; \
384
+ pip3 show tqdm >/dev/null || pip3 install -q tqdm
385
+ source gradiovenv/bin/activate; \
386
+ python3 $HOME/Downloads/stable-diffusion-webui/extensions/batchlinks-webui/scripts/batchlinks-downloader.py
387
+ ```
388
+
389
+ ### Local Installation Support
390
+
391
+ This extension was tested to work on Windows 11. But ultimately, the number one priority for me is colab use, so there's might be bugs on Windows 11 one. Maybe also works on Debian-based linux (but you better inspect the source code first).
392
+ On Windows, this extension will install [MEGAcmd](https://github.com/meganz/MEGAcmd) for MEGA file download, [wget-windows](https://github.com/webfolderio/wget-windows) for download using `wget`, [aria2-static-builds](https://github.com/q3aql/aria2-static-builds) for download using `aria2`, [7zr and 7z](https://www.7-zip.org) for extracting `aria2` installation, and for `@extract` command.
393
+ MacOS is just partially supported.
394
+
395
+ Also remember, in order for this extension to work properly, you need make sure that you tick that `add Python 3.10 to PATH` checkbox when you installed Python (Which is already recommended when installing stable-diffusion-webui)<br/>
396
+ <img src="images/python.png" alt="python" width="400"><br/>
397
+
398
+ ### Debug Mode (Developer only)
399
+
400
+ By manually switching `globaldebug = False` to `True` on the source code, or using `--debug` argument when running the sdless mode, the Debug Mode will be activated. It shows every `print` calls i use to track variables. It will also tracks every files on the models (etc.) paths into a `snapshot.txt` file (if there isn't one).
401
+
402
+ There are some batchlinks syntax features that only available on debug mode (putting it on the textbox and click `Download All!`):
403
+
404
+ `@debugresetdownload` - This command will check every model (etc.) directory, and remove every file that isn't on `snapshot.txt`. Useful for me to removes file quickly when testing. **Be careful using this on your local installation.**
405
+
406
+ `@debugresetdownload` - This command is (supposed to) download a single link with every method available (gdown, curl, wget, aria2), but now i rarely use this command, and haven't updated since. Might be buggy.
407
+
408
+ ## Release Notes
409
+ Moved [here](https://github.com/etherealxx/batchlinks-webui/blob/main/releasenotes.md). Check it out for latest features & bug fixes.
410
+
411
+ ## Roadmap
412
+
413
+ - [ ] Add checker for downloaded models (so that it won't download again after the model is downloaded)
414
+ - [ ] Different UI for mobile
415
+ - [ ] Gradio progress bar
416
+ - [ ] Integrating refresh button (`create_refresh_button`) to refresh models etc. all at once
417
+ - [ ] Logo change
418
+ - [ ] Moving most of the content of this `Readme.md` to Wiki instead
419
+ - [ ] Other download sites (s-ul.eu, gitgud, bunkr.ru, icedrive)
420
+ - [ ] Separate 'download' and 'run command' function with a subtab
421
+ - [ ] Support download MEGA and Google Drive folder
422
+ - [ ] Using `yield` instead of gradio's `every`
423
+ - [ ] Youtube video (Tutorial)
424
+ - [ ] (Crawler) Download every sd-webui related file from a huggingface repo
425
+ - [ ] (Crawler) Download every model from a civitai user page
426
+ <br/>_
427
+ - [x] aria2 for huggingface download method
428
+ - [x] Cleaning the code from unnecesarry comments
429
+ - [x] Completed download will use the webui's notification.mp3
430
+ - [x] Support customizable hashtag from the UI
431
+ - [x] Supports Windows local installation
432
+ - [x] UI overhaul
433
+ - [x] Using threading/subprocess instead of os.system to download files
434
+ - [x] (Windows) wget & aria2 support
435
+
436
+ ## Known Bugs
437
+
438
+ - Progress bar (the yellow bar) doesn't progress as expected
439
+ - Sometimes notification sound doesn't play when downloading same file twice in a row
440
+ - Sometimes notification sound shows up when starting download, instead of when the download process is completed.
441
+ - There's still a chance that the UI of non `--gradio-queue` session and/or onedotsix freezes after a download session
442
+ - Windows: The delay between file is downloaded and the output shows is pretty long, and even sometimes the notification comes at the wrong time.
443
+ <br/>
444
+
445
+ ### Known Fixed Bugs
446
+
447
+ <details>
448
+ <summary>👈Fixed Bugs</summary>
449
+ <ol>
450
+ <ul>
451
+ <li><s>Links that has bracket in it needs to be 'escaped' (For example, <code>Baka-DiffusionV1(Fp16).safetensors</code> must be typed <code>Baka-DiffusionV1\(Fp16\).safetensors</code>)</s><br/>☝️Fixed in <a href="dbb2adb3d07e41654244076b8ef4e851c3bb1f0c">v2.0.0</a>
452
+ <li><s>The delay between file is downloaded and the output shows is really long (1min+) on <a href="https://github.com/camenduru/stable-diffusion-webui-colab">camenduru's v1.6 colab</a> (Gradio related?)</s><br/>☝️Seems like fixed in <a href="fe6feafc07fbbe3efd2883b33855f8d66b5f89ea">v1.1.0</a>
453
+ <li><s>File downloaded from MEGA will not listed on the output, as it use different download method. There is some delay between the transfare() function complete until it writes the file. I don't know how long the delay is.</s><br/>☝️Fixed in <a href="fe6feafc07fbbe3efd2883b33855f8d66b5f89ea">v1.1.0</a>
454
+ <li><s>Sometimes colab cannot be shut down with a single click on the stop button. Hitting the button several times will raise a KeyboardInterrupt and forcely stopping the cell.</s><br/>☝️Seems like fixed somewhere on <a href="0acffad539179b9f6cf4b76581818b62c93a8551">v3.0.0</a> and after
455
+ </ul>
456
+ </ol>
457
+ </details>
458
+
459
+ ## Contributing
460
+
461
+ <!-- I just learned python few months ago, by just looking at other peoples project and sometimes asking ChatGPT. Gradio is new for me. I literally just learn it in one day to make this extension, so expect some bugs. -->
462
+
463
+ [I no longer actively maintain this project](https://github.com/etherealxx/batchlinks-webui/blob/main/regardingthisrepo.md). if you have a suggestion or code-fixing that would make this better, please notify me in the issue tab, fork the repo and create a pull request. <br/>
464
+ But still, a star on this project would be nice. Thanks again.
465
+
466
+ <!--
467
+ 1. Fork the Project
468
+ 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
469
+ 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
470
+ 4. Push to the Branch (`git push origin feature/AmazingFeature`)
471
+ 5. Open a Pull Request
472
+
473
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
474
+ -->
475
+
476
+ ## Contact
477
+
478
+ My Email - gwathon3@gmail.com <br/>
479
+ My Youtube - [MJ Devlog](https://www.youtube.com/@mjdevlog)
480
+
481
+ ## Acknowledgments
482
+
483
+ - [Camenduru's Webui Huggingface](https://github.com/camenduru/stable-diffusion-webui-huggingface) - I use his extension as my base (my gradio skill sucks T.T)
484
+ - [SD Civitai Browser](https://github.com/Vetchems/sd-civitai-browser) - Civit download script
485
+ - [Mega-to-Google-Drive](https://github.com/menukaonline/Mega-to-Google-Drive) - MEGA download script
486
+ - [MEGAcmd](https://github.com/meganz/MEGAcmd)
487
+ - [mediafire-dl](https://github.com/Juvenal-Yescas/mediafire-dl)
488
+ - [Pixeldrain downloader](https://github.com/FayasNoushad/Pixeldrain) - Inspiration for Pixeldrain download method
489
+ - [wget-windows](https://github.com/webfolderio/wget-windows)
490
+ - [aria2-static-builds](https://github.com/q3aql/aria2-static-builds)
491
+ - [7zr, 7z](https://www.7-zip.org)
TestingforfaivsixEx/content/eichellis/extensions/batch-link/howtogetthedirectlinks.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # How to get the direct links
2
+
3
+ Jump to: [Huggingface](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#huggingface) - [Civit AI](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#civit-ai) - [MEGA](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#mega) - [Discord](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#discord-attachments) - [Github (Extension)](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#webui-extension-github-repo-link) - [Github (Raw File)](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#raw-file-from-github) - [Github (Release File)](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#release-file-from-github) - [Google Drive](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#google-drive) - [Pixeldrain](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#pixeldrain) - - [Mediafire](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#mediafire) - [Anonfiles](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#anonfiles) - [Dropbox](https://github.com/etherealxx/batchlinks-webui/blob/main/howtogetthedirectlinks.md#dropbox)
4
+
5
+ ## Huggingface
6
+
7
+ Locate the model page, click on `files` tab.<br/><br/>
8
+ <img src="images/huggingface1.jpg" alt="hg1" height="600" width="966"><br/><br/>
9
+ choose the model you want, **right click** the arrow button beside the LFS logo, then click `copy link address`.<br/><br/>
10
+ <img src="images/huggingface2.jpg" alt="hg2" height="600" width="970"><br/><br/>
11
+
12
+ ## Civit AI
13
+
14
+ There are two ways to download links from Civit. The model page link method, and the direct link method. The model page link method **will automatically** choose the directory of the saved model without even using hashtag, **except** if you want to put Lora into `#addnetlora` directory, you can use that hashtag. You still need to define the output directory when using the direct link method.
15
+
16
+ ### Model Page Link Method
17
+
18
+ Locate the desired model on the main page of Civitai, **right click** the model thumbnail, then click `copy link address`.<br/><br/>
19
+ <img src="images/civitnew1.jpg" alt="cv" height="600" width="737"><br/><br/>
20
+ You can also click the thumbnail first then copy the link.<br/><br/>
21
+ <img src="images/civitnew2.jpg" alt="cv" height="600" width="754"><br/><br/>
22
+ The advantage of this method is you will also get the model preview images that can shows up on the latest version of [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui).
23
+
24
+ ### Direct Link Method
25
+
26
+ Locate the model page, **right click** the huge blue button, then click `copy link address`.<br/><br/>
27
+ <img src="images/civit1.jpg" alt="cv" height="600" width="967"><br/><br/>
28
+ With this method, you can also choose model variation, by clicking the dropdown icon on the blue button, then **right click** the desired model an.<br/><br/>
29
+ <img src="images/civit2.jpg" alt="cv" height="600" width="842"> <br/><br/>
30
+
31
+ ## MEGA
32
+
33
+ Locate the model you wanted, **right click** the item, click `copy link address`.<br/><br/>
34
+ <img src="images/mega1.jpg" alt="mg1" height="600" width="987"><br/><br/>
35
+ Click the huge green copy button.<br/><br/>
36
+ <img src="images/mega2.jpg" alt="mg2" height="600" width="963"><br/><br/>
37
+
38
+ ## Discord attachments
39
+
40
+ Locate the file you wanted, **right click** the download icon, then click `get link`.<br/><br/>
41
+ <img src="images/discord1.jpg" alt="mg1" height="600" width="930"><br/><br/>
42
+ Then click `copy link`.<br/><br/>
43
+ <img src="images/discord2.jpg" alt="mg2" height="600" width="963"><br/><br/>
44
+
45
+ ## webui Extension (Github repo link)
46
+
47
+ Locate the extension's repository, then copy the repository link.<br/><br/>
48
+ <img src="images/github.jpg" alt="mg1" height="600" width="831"><br/><br/>
49
+
50
+ Extension **will automatically** cloned/downloaded on `extensions` directory of webui without the need of hashtag.
51
+
52
+ ## Raw file from Github
53
+
54
+ Locate the file's repository, then click the desired file.<br/><br/>
55
+ <img src="images/githubdirect1.png" alt="mg1" width="831"><br/><br/>
56
+ Then **right click** the text that says `raw` **or** `download`, and click `copy link address`<br/><br/>
57
+ <img src="images/githubdirect2.png" alt="mg1" width="831"><br/><br/>
58
+ <img src="images/githubdirect3.png" alt="mg1" width="831"><br/><br/>
59
+
60
+ ## Release file from Github
61
+
62
+ Locate the file's repository, then click release section.<br/><br/>
63
+ <img src="images/githubrelease1.png" alt="mg1" width="831"><br/><br/>
64
+ Then **right click** the desired assets (the blue text), and click `copy link address`<br/><br/>
65
+ <img src="images/githubrelease2.png" alt="mg1" width="831"><br/><br/>
66
+
67
+ ## Google Drive
68
+
69
+ Whether you own the file or not, make sure the file is public. If you owns the file, right click on the file on Google Drive, then click `get link` (or `share`).<br/><br/>
70
+ <img src="images/drive1.png" alt="mg1" width="400"><br/><br/>
71
+ Then change the access to `anyone with thelink`, and copy the link by clicking the button<br/><br/>
72
+ <img src="images/drive2.png" alt="mg1" width="831"><br/><br/>
73
+
74
+ These are some valid google drive link patterns that works:
75
+ ```
76
+ https://drive.google.com/file/d/1-UbwFtSzKTQkvjdPiKLCejH0Ztq9UJFO/view
77
+ https://drive.google.com/file/d/1-UbwFtSzKTQkvjdPiKLCejH0Ztq9UJFO/view?usp=share_link
78
+ https://drive.google.com/u/0/uc?id=1-UbwFtSzKTQkvjdPiKLCejH0Ztq9UJFO&export=download
79
+ https://drive.google.com/u/0/uc?id=1-UbwFtSzKTQkvjdPiKLCejH0Ztq9UJFO&export=download&confirm=t
80
+ ```
81
+ ## Pixeldrain
82
+
83
+ Just click the `copy link` button, or just copy the link.<br/><br/>
84
+ <img src="images/pixeldrain.png" alt="mg1" width="800"><br/><br/>
85
+
86
+ ## Anonfiles
87
+
88
+ **Don't** right click the download button. Instead, copy the link on the url bar<br/><br/>
89
+ <img src="images/anonfiles.png" alt="mg1" width="800"><br/><br/>
90
+
91
+ ## Mediafire
92
+
93
+ When you arrived on this page, click the chain link icon to copy link, or just copy the link above<br/><br/>
94
+ <img src="images/mediafire.png" alt="mg1" width="800"><br/><br/>
95
+
96
+ Don't forget that when being pasted, the link must starts with `https://www.mediafire.com/file/` (notice the triple W)
97
+
98
+ ## Dropbox
99
+
100
+ When the item is yours, go to the homepage, and click copy link, the link will be copied to your clipboard<br/><br/>
101
+ <img src="images/dropbox1.png" alt="mg1" width="600"><br/><br/>
102
+
103
+ Or, if you got into this screen, just copy the link above, with the link ends with either `?dl=0` or `?dl=1`<br/><br/>
104
+ <img src="images/dropbox2.png" alt="mg1" width="500"><br/><br/>