Spaces:
Sleeping
Sleeping
Duplicate from DeepFloyd/IF
Browse filesCo-authored-by: hysts <hysts@users.noreply.huggingface.co>
- .gitattributes +35 -0
- .gitignore +162 -0
- .pre-commit-config.yaml +38 -0
- .style.yapf +5 -0
- README.md +15 -0
- app.py +673 -0
- model.py +309 -0
- requirements.txt +16 -0
- settings.py +57 -0
- share_btn.py +69 -0
- style.css +238 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio_cached_examples/
|
2 |
+
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
*.py[cod]
|
6 |
+
*$py.class
|
7 |
+
|
8 |
+
# C extensions
|
9 |
+
*.so
|
10 |
+
|
11 |
+
# Distribution / packaging
|
12 |
+
.Python
|
13 |
+
build/
|
14 |
+
develop-eggs/
|
15 |
+
dist/
|
16 |
+
downloads/
|
17 |
+
eggs/
|
18 |
+
.eggs/
|
19 |
+
lib/
|
20 |
+
lib64/
|
21 |
+
parts/
|
22 |
+
sdist/
|
23 |
+
var/
|
24 |
+
wheels/
|
25 |
+
share/python-wheels/
|
26 |
+
*.egg-info/
|
27 |
+
.installed.cfg
|
28 |
+
*.egg
|
29 |
+
MANIFEST
|
30 |
+
|
31 |
+
# PyInstaller
|
32 |
+
# Usually these files are written by a python script from a template
|
33 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
34 |
+
*.manifest
|
35 |
+
*.spec
|
36 |
+
|
37 |
+
# Installer logs
|
38 |
+
pip-log.txt
|
39 |
+
pip-delete-this-directory.txt
|
40 |
+
|
41 |
+
# Unit test / coverage reports
|
42 |
+
htmlcov/
|
43 |
+
.tox/
|
44 |
+
.nox/
|
45 |
+
.coverage
|
46 |
+
.coverage.*
|
47 |
+
.cache
|
48 |
+
nosetests.xml
|
49 |
+
coverage.xml
|
50 |
+
*.cover
|
51 |
+
*.py,cover
|
52 |
+
.hypothesis/
|
53 |
+
.pytest_cache/
|
54 |
+
cover/
|
55 |
+
|
56 |
+
# Translations
|
57 |
+
*.mo
|
58 |
+
*.pot
|
59 |
+
|
60 |
+
# Django stuff:
|
61 |
+
*.log
|
62 |
+
local_settings.py
|
63 |
+
db.sqlite3
|
64 |
+
db.sqlite3-journal
|
65 |
+
|
66 |
+
# Flask stuff:
|
67 |
+
instance/
|
68 |
+
.webassets-cache
|
69 |
+
|
70 |
+
# Scrapy stuff:
|
71 |
+
.scrapy
|
72 |
+
|
73 |
+
# Sphinx documentation
|
74 |
+
docs/_build/
|
75 |
+
|
76 |
+
# PyBuilder
|
77 |
+
.pybuilder/
|
78 |
+
target/
|
79 |
+
|
80 |
+
# Jupyter Notebook
|
81 |
+
.ipynb_checkpoints
|
82 |
+
|
83 |
+
# IPython
|
84 |
+
profile_default/
|
85 |
+
ipython_config.py
|
86 |
+
|
87 |
+
# pyenv
|
88 |
+
# For a library or package, you might want to ignore these files since the code is
|
89 |
+
# intended to run in multiple environments; otherwise, check them in:
|
90 |
+
# .python-version
|
91 |
+
|
92 |
+
# pipenv
|
93 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
94 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
95 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
96 |
+
# install all needed dependencies.
|
97 |
+
#Pipfile.lock
|
98 |
+
|
99 |
+
# poetry
|
100 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
101 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
102 |
+
# commonly ignored for libraries.
|
103 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
104 |
+
#poetry.lock
|
105 |
+
|
106 |
+
# pdm
|
107 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
108 |
+
#pdm.lock
|
109 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
110 |
+
# in version control.
|
111 |
+
# https://pdm.fming.dev/#use-with-ide
|
112 |
+
.pdm.toml
|
113 |
+
|
114 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
115 |
+
__pypackages__/
|
116 |
+
|
117 |
+
# Celery stuff
|
118 |
+
celerybeat-schedule
|
119 |
+
celerybeat.pid
|
120 |
+
|
121 |
+
# SageMath parsed files
|
122 |
+
*.sage.py
|
123 |
+
|
124 |
+
# Environments
|
125 |
+
.env
|
126 |
+
.venv
|
127 |
+
env/
|
128 |
+
venv/
|
129 |
+
ENV/
|
130 |
+
env.bak/
|
131 |
+
venv.bak/
|
132 |
+
|
133 |
+
# Spyder project settings
|
134 |
+
.spyderproject
|
135 |
+
.spyproject
|
136 |
+
|
137 |
+
# Rope project settings
|
138 |
+
.ropeproject
|
139 |
+
|
140 |
+
# mkdocs documentation
|
141 |
+
/site
|
142 |
+
|
143 |
+
# mypy
|
144 |
+
.mypy_cache/
|
145 |
+
.dmypy.json
|
146 |
+
dmypy.json
|
147 |
+
|
148 |
+
# Pyre type checker
|
149 |
+
.pyre/
|
150 |
+
|
151 |
+
# pytype static type analyzer
|
152 |
+
.pytype/
|
153 |
+
|
154 |
+
# Cython debug symbols
|
155 |
+
cython_debug/
|
156 |
+
|
157 |
+
# PyCharm
|
158 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
159 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
160 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
+
#.idea/
|
.pre-commit-config.yaml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
exclude: diffusers-private
|
2 |
+
repos:
|
3 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
4 |
+
rev: v4.2.0
|
5 |
+
hooks:
|
6 |
+
- id: check-executables-have-shebangs
|
7 |
+
- id: check-json
|
8 |
+
- id: check-merge-conflict
|
9 |
+
- id: check-shebang-scripts-are-executable
|
10 |
+
- id: check-toml
|
11 |
+
- id: check-yaml
|
12 |
+
- id: double-quote-string-fixer
|
13 |
+
- id: end-of-file-fixer
|
14 |
+
- id: mixed-line-ending
|
15 |
+
args: ['--fix=lf']
|
16 |
+
- id: requirements-txt-fixer
|
17 |
+
- id: trailing-whitespace
|
18 |
+
- repo: https://github.com/myint/docformatter
|
19 |
+
rev: v1.4
|
20 |
+
hooks:
|
21 |
+
- id: docformatter
|
22 |
+
args: ['--in-place']
|
23 |
+
- repo: https://github.com/pycqa/isort
|
24 |
+
rev: 5.12.0
|
25 |
+
hooks:
|
26 |
+
- id: isort
|
27 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
28 |
+
rev: v0.991
|
29 |
+
hooks:
|
30 |
+
- id: mypy
|
31 |
+
args: ['--ignore-missing-imports']
|
32 |
+
additional_dependencies: ['types-python-slugify']
|
33 |
+
files: ^diffusers-private
|
34 |
+
- repo: https://github.com/google/yapf
|
35 |
+
rev: v0.32.0
|
36 |
+
hooks:
|
37 |
+
- id: yapf
|
38 |
+
args: ['--parallel', '--in-place']
|
.style.yapf
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[style]
|
2 |
+
based_on_style = pep8
|
3 |
+
blank_line_before_nested_class_or_def = false
|
4 |
+
spaces_before_comment = 2
|
5 |
+
split_before_logical_operator = true
|
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: IF
|
3 |
+
emoji: 🔥
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.27.0
|
8 |
+
python_version: 3.10.11
|
9 |
+
app_file: app.py
|
10 |
+
pinned: false
|
11 |
+
license: other
|
12 |
+
duplicated_from: DeepFloyd/IF
|
13 |
+
---
|
14 |
+
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,673 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import datetime
|
4 |
+
import hashlib
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
import random
|
8 |
+
import tempfile
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
import torch
|
12 |
+
from huggingface_hub import HfApi
|
13 |
+
from share_btn import community_icon_html, loading_icon_html, share_js
|
14 |
+
|
15 |
+
# isort: off
|
16 |
+
from model import Model
|
17 |
+
from settings import (
|
18 |
+
DEBUG,
|
19 |
+
DEFAULT_CUSTOM_TIMESTEPS_1,
|
20 |
+
DEFAULT_CUSTOM_TIMESTEPS_2,
|
21 |
+
DEFAULT_NUM_IMAGES,
|
22 |
+
DEFAULT_NUM_STEPS_3,
|
23 |
+
DISABLE_SD_X4_UPSCALER,
|
24 |
+
GALLERY_COLUMN_NUM,
|
25 |
+
HF_TOKEN,
|
26 |
+
MAX_NUM_IMAGES,
|
27 |
+
MAX_NUM_STEPS,
|
28 |
+
MAX_QUEUE_SIZE,
|
29 |
+
MAX_SEED,
|
30 |
+
SHOW_ADVANCED_OPTIONS,
|
31 |
+
SHOW_CUSTOM_TIMESTEPS_1,
|
32 |
+
SHOW_CUSTOM_TIMESTEPS_2,
|
33 |
+
SHOW_DEVICE_WARNING,
|
34 |
+
SHOW_DUPLICATE_BUTTON,
|
35 |
+
SHOW_NUM_IMAGES,
|
36 |
+
SHOW_NUM_STEPS_1,
|
37 |
+
SHOW_NUM_STEPS_2,
|
38 |
+
SHOW_NUM_STEPS_3,
|
39 |
+
SHOW_UPSCALE_TO_256_BUTTON,
|
40 |
+
UPLOAD_REPO_ID,
|
41 |
+
UPLOAD_RESULT_IMAGE,
|
42 |
+
)
|
43 |
+
# isort: on
|
44 |
+
|
45 |
+
TITLE = '# [DeepFloyd IF](https://github.com/deep-floyd/IF)'
|
46 |
+
DESCRIPTION = 'The DeepFloyd IF model has been initially released as a non-commercial research-only model. Please make sure you read and abide to the [LICENSE](https://huggingface.co/spaces/DeepFloyd/deepfloyd-if-license) before using it.'
|
47 |
+
DISCLAIMER = 'In this demo, the DeepFloyd team may collect prompts, and user preferences (which of the images the user chose to upscale) for improving future models'
|
48 |
+
FOOTER = """<div class="footer">
|
49 |
+
<p>Model by <a href="https://huggingface.co/DeepFloyd" style="text-decoration: underline;" target="_blank">DeepFloyd</a> supported by <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">Stability AI</a>
|
50 |
+
</p>
|
51 |
+
</div>
|
52 |
+
<div class="acknowledgments">
|
53 |
+
<p><h4>LICENSE</h4>
|
54 |
+
The model is licensed with a bespoke non-commercial research-only license <a href="https://huggingface.co/spaces/DeepFloyd/deepfloyd-if-license" style="text-decoration: underline;" target="_blank">DeepFloyd IF Research License Agreement</a> license. The license forbids you from sharing any content for commercial use, or that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/DeepFloyd/deepfloyd-if-license" style="text-decoration: underline;" target="_blank">read the license</a></p>
|
55 |
+
<p><h4>Biases and content acknowledgment</h4>
|
56 |
+
Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, explicit content and violence. The model was trained on a subset of the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a> and is meant for research purposes. You can read more in the <a href="https://huggingface.co/DeepFloyd/IF-I-IF-v1.0" style="text-decoration: underline;" target="_blank">model card</a></p>
|
57 |
+
</div>
|
58 |
+
"""
|
59 |
+
if SHOW_DUPLICATE_BUTTON:
|
60 |
+
SPACE_ID = os.getenv('SPACE_ID')
|
61 |
+
DESCRIPTION += f'\n<p><a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space%20to%20skip%20the%20queue-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></p>'
|
62 |
+
|
63 |
+
if SHOW_DEVICE_WARNING and not torch.cuda.is_available():
|
64 |
+
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
|
65 |
+
|
66 |
+
model = Model()
|
67 |
+
|
68 |
+
|
69 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
70 |
+
if randomize_seed:
|
71 |
+
seed = random.randint(0, MAX_SEED)
|
72 |
+
return seed
|
73 |
+
|
74 |
+
|
75 |
+
def get_stage2_index(evt: gr.SelectData) -> int:
|
76 |
+
return evt.index
|
77 |
+
|
78 |
+
|
79 |
+
def check_if_stage2_selected(index: int) -> None:
|
80 |
+
if index == -1:
|
81 |
+
raise gr.Error(
|
82 |
+
'You need to select the image you would like to upscale from the Stage 1 results by clicking.'
|
83 |
+
)
|
84 |
+
|
85 |
+
|
86 |
+
hf_api = HfApi(token=HF_TOKEN)
|
87 |
+
if UPLOAD_REPO_ID:
|
88 |
+
hf_api.create_repo(repo_id=UPLOAD_REPO_ID,
|
89 |
+
private=True,
|
90 |
+
repo_type='dataset',
|
91 |
+
exist_ok=True)
|
92 |
+
|
93 |
+
|
94 |
+
def get_param_file_hash_name(param_filepath: str) -> str:
|
95 |
+
if not UPLOAD_REPO_ID:
|
96 |
+
return ''
|
97 |
+
with open(param_filepath, 'rb') as f:
|
98 |
+
md5 = hashlib.md5(f.read()).hexdigest()
|
99 |
+
utcnow = datetime.datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S-%f')
|
100 |
+
return f'{utcnow}-{md5}'
|
101 |
+
|
102 |
+
|
103 |
+
def upload_stage1_result(stage1_param_path: str, stage1_result_path: str,
|
104 |
+
save_name: str) -> None:
|
105 |
+
if not UPLOAD_REPO_ID:
|
106 |
+
return
|
107 |
+
try:
|
108 |
+
random_folder = random.randint(0,1000)
|
109 |
+
hf_api.upload_file(path_or_fileobj=stage1_param_path,
|
110 |
+
path_in_repo=f'stage1_params/{random_folder}/{save_name}.json',
|
111 |
+
repo_id=UPLOAD_REPO_ID,
|
112 |
+
repo_type='dataset')
|
113 |
+
hf_api.upload_file(path_or_fileobj=stage1_result_path,
|
114 |
+
path_in_repo=f'stage1_results/{random_folder}/{save_name}.pth',
|
115 |
+
repo_id=UPLOAD_REPO_ID,
|
116 |
+
repo_type='dataset')
|
117 |
+
except Exception as e:
|
118 |
+
print(e)
|
119 |
+
|
120 |
+
|
121 |
+
def upload_stage2_info(stage1_param_file_hash_name: str,
|
122 |
+
stage2_output_path: str,
|
123 |
+
selected_index_for_upscale: int, seed_2: int,
|
124 |
+
guidance_scale_2: float, custom_timesteps_2: str,
|
125 |
+
num_inference_steps_2: int) -> None:
|
126 |
+
if not UPLOAD_REPO_ID:
|
127 |
+
return
|
128 |
+
if not stage1_param_file_hash_name:
|
129 |
+
raise ValueError
|
130 |
+
|
131 |
+
stage2_params = {
|
132 |
+
'stage1_param_file_hash_name': stage1_param_file_hash_name,
|
133 |
+
'selected_index_for_upscale': selected_index_for_upscale,
|
134 |
+
'seed_2': seed_2,
|
135 |
+
'guidance_scale_2': guidance_scale_2,
|
136 |
+
'custom_timesteps_2': custom_timesteps_2,
|
137 |
+
'num_inference_steps_2': num_inference_steps_2,
|
138 |
+
}
|
139 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as param_file:
|
140 |
+
param_file.write(json.dumps(stage2_params))
|
141 |
+
stage2_param_file_hash_name = get_param_file_hash_name(param_file.name)
|
142 |
+
save_name = f'{stage1_param_file_hash_name}_{stage2_param_file_hash_name}'
|
143 |
+
|
144 |
+
try:
|
145 |
+
random_folder = random.randint(0,1000)
|
146 |
+
hf_api.upload_file(path_or_fileobj=param_file.name,
|
147 |
+
path_in_repo=f'stage2_params/{random_folder}/{save_name}.json',
|
148 |
+
repo_id=UPLOAD_REPO_ID,
|
149 |
+
repo_type='dataset')
|
150 |
+
if UPLOAD_RESULT_IMAGE:
|
151 |
+
hf_api.upload_file(path_or_fileobj=stage2_output_path,
|
152 |
+
path_in_repo=f'stage2_results/{random_folder}/{save_name}.png',
|
153 |
+
repo_id=UPLOAD_REPO_ID,
|
154 |
+
repo_type='dataset')
|
155 |
+
except Exception as e:
|
156 |
+
print(e)
|
157 |
+
|
158 |
+
|
159 |
+
def upload_stage2_3_info(stage1_param_file_hash_name: str,
|
160 |
+
stage2_3_output_path: str,
|
161 |
+
selected_index_for_upscale: int, seed_2: int,
|
162 |
+
guidance_scale_2: float, custom_timesteps_2: str,
|
163 |
+
num_inference_steps_2: int, prompt: str,
|
164 |
+
negative_prompt: str, seed_3: int,
|
165 |
+
guidance_scale_3: float,
|
166 |
+
num_inference_steps_3: int) -> None:
|
167 |
+
if not UPLOAD_REPO_ID:
|
168 |
+
return
|
169 |
+
if not stage1_param_file_hash_name:
|
170 |
+
raise ValueError
|
171 |
+
|
172 |
+
stage2_3_params = {
|
173 |
+
'stage1_param_file_hash_name': stage1_param_file_hash_name,
|
174 |
+
'selected_index_for_upscale': selected_index_for_upscale,
|
175 |
+
'seed_2': seed_2,
|
176 |
+
'guidance_scale_2': guidance_scale_2,
|
177 |
+
'custom_timesteps_2': custom_timesteps_2,
|
178 |
+
'num_inference_steps_2': num_inference_steps_2,
|
179 |
+
'prompt': prompt,
|
180 |
+
'negative_prompt': negative_prompt,
|
181 |
+
'seed_3': seed_3,
|
182 |
+
'guidance_scale_3': guidance_scale_3,
|
183 |
+
'num_inference_steps_3': num_inference_steps_3,
|
184 |
+
}
|
185 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as param_file:
|
186 |
+
param_file.write(json.dumps(stage2_3_params))
|
187 |
+
stage2_3_param_file_hash_name = get_param_file_hash_name(param_file.name)
|
188 |
+
save_name = f'{stage1_param_file_hash_name}_{stage2_3_param_file_hash_name}'
|
189 |
+
|
190 |
+
try:
|
191 |
+
random_folder = random.randint(0,1000)
|
192 |
+
hf_api.upload_file(path_or_fileobj=param_file.name,
|
193 |
+
path_in_repo=f'stage2_3_params/{random_folder}/{save_name}.json',
|
194 |
+
repo_id=UPLOAD_REPO_ID,
|
195 |
+
repo_type='dataset')
|
196 |
+
if UPLOAD_RESULT_IMAGE:
|
197 |
+
hf_api.upload_file(
|
198 |
+
path_or_fileobj=stage2_3_output_path,
|
199 |
+
path_in_repo=f'stage2_3_results/{random_folder}/{save_name}.png',
|
200 |
+
repo_id=UPLOAD_REPO_ID,
|
201 |
+
repo_type='dataset')
|
202 |
+
except Exception as e:
|
203 |
+
print(e)
|
204 |
+
|
205 |
+
|
206 |
+
def update_upscale_button(selected_index: int) -> tuple[dict, dict]:
|
207 |
+
if selected_index == -1:
|
208 |
+
return gr.update(interactive=False), gr.update(interactive=False)
|
209 |
+
else:
|
210 |
+
return gr.update(interactive=True), gr.update(interactive=True)
|
211 |
+
|
212 |
+
|
213 |
+
def _update_result_view(show_gallery: bool) -> tuple[dict, dict]:
|
214 |
+
return gr.update(visible=show_gallery), gr.update(visible=not show_gallery)
|
215 |
+
|
216 |
+
|
217 |
+
def show_gallery_view() -> tuple[dict, dict]:
|
218 |
+
return _update_result_view(True)
|
219 |
+
|
220 |
+
|
221 |
+
def show_upscaled_view() -> tuple[dict, dict]:
|
222 |
+
return _update_result_view(False)
|
223 |
+
|
224 |
+
|
225 |
+
examples = [
|
226 |
+
'high quality dslr photo, a photo product of a lemon inspired by natural and organic materials, wooden accents, intricately decorated with glowing vines of led lights, inspired by baroque luxury',
|
227 |
+
'paper quilling, extremely detailed, paper quilling of a nordic mountain landscape, 8k rendering',
|
228 |
+
'letters made of candy on a plate that says "diet"',
|
229 |
+
'a photo of a violet baseball cap with yellow text: "deep floyd". 50mm lens, photo realism, cine lens. violet baseball cap says "deep floyd". reflections, render. yellow stitch text "deep floyd"',
|
230 |
+
'ultra close-up color photo portrait of rainbow owl with deer horns in the woods',
|
231 |
+
'a cloth embroidered with the text "laion" and an embroidered cute baby lion face',
|
232 |
+
'product image of a crochet Cthulhu the great old one emerging from a spacetime wormhole made of wool',
|
233 |
+
'a little green budgie parrot driving small red toy car in new york street, photo',
|
234 |
+
'origami dancer in white paper, 3d render, ultra-detailed, on white background, studio shot.',
|
235 |
+
'glowing mushrooms in a natural environment with smoke in the frame',
|
236 |
+
'a subway train\'s digital sign saying "open source", vsco preset, 35mm photo, film grain, in a dim subway station',
|
237 |
+
'a bowl full of few adorable golden doodle puppies, the doodles dusted in powdered sugar and look delicious, bokeh, cannon. professional macro photo, super detailed. cute sweet golden doodle confectionery, baking puppies in powdered sugar in the bowl',
|
238 |
+
'a face of a woman made completely out of foliage, twigs, leaves and flowers, side view'
|
239 |
+
]
|
240 |
+
|
241 |
+
with gr.Blocks(css='style.css') as demo:
|
242 |
+
gr.Markdown(TITLE)
|
243 |
+
gr.Markdown(DESCRIPTION)
|
244 |
+
with gr.Box():
|
245 |
+
with gr.Row(elem_id='prompt-container').style(equal_height=True):
|
246 |
+
with gr.Column():
|
247 |
+
prompt = gr.Text(
|
248 |
+
label='Prompt',
|
249 |
+
show_label=False,
|
250 |
+
max_lines=1,
|
251 |
+
placeholder='Enter your prompt',
|
252 |
+
elem_id='prompt-text-input',
|
253 |
+
).style(container=False)
|
254 |
+
negative_prompt = gr.Text(
|
255 |
+
label='Negative prompt',
|
256 |
+
show_label=False,
|
257 |
+
max_lines=1,
|
258 |
+
placeholder='Enter a negative prompt',
|
259 |
+
elem_id='negative-prompt-text-input',
|
260 |
+
).style(container=False)
|
261 |
+
generate_button = gr.Button('Generate').style(full_width=False)
|
262 |
+
|
263 |
+
with gr.Column() as gallery_view:
|
264 |
+
gallery = gr.Gallery(label='Stage 1 results',
|
265 |
+
show_label=False,
|
266 |
+
elem_id='gallery').style(
|
267 |
+
columns=GALLERY_COLUMN_NUM,
|
268 |
+
object_fit='contain')
|
269 |
+
gr.Markdown('Pick your favorite generation to upscale.')
|
270 |
+
with gr.Row():
|
271 |
+
upscale_to_256_button = gr.Button(
|
272 |
+
'Upscale to 256px',
|
273 |
+
visible=SHOW_UPSCALE_TO_256_BUTTON
|
274 |
+
or DISABLE_SD_X4_UPSCALER,
|
275 |
+
interactive=False)
|
276 |
+
upscale_button = gr.Button('Upscale',
|
277 |
+
interactive=False,
|
278 |
+
visible=not DISABLE_SD_X4_UPSCALER)
|
279 |
+
with gr.Column(visible=False) as upscale_view:
|
280 |
+
result = gr.Image(label='Result',
|
281 |
+
show_label=False,
|
282 |
+
type='filepath',
|
283 |
+
interactive=False,
|
284 |
+
elem_id='upscaled-image').style(height=640)
|
285 |
+
back_to_selection_button = gr.Button('Back to selection')
|
286 |
+
with gr.Group(elem_id="share-btn-container"):
|
287 |
+
community_icon = gr.HTML(community_icon_html)
|
288 |
+
loading_icon = gr.HTML(loading_icon_html)
|
289 |
+
share_button = gr.Button(
|
290 |
+
"Share to community", elem_id="share-btn")
|
291 |
+
share_button.click(None, [], [], _js=share_js)
|
292 |
+
with gr.Accordion('Advanced options',
|
293 |
+
open=False,
|
294 |
+
visible=SHOW_ADVANCED_OPTIONS):
|
295 |
+
with gr.Tabs():
|
296 |
+
with gr.Tab(label='Generation'):
|
297 |
+
seed_1 = gr.Slider(label='Seed',
|
298 |
+
minimum=0,
|
299 |
+
maximum=MAX_SEED,
|
300 |
+
step=1,
|
301 |
+
value=0)
|
302 |
+
randomize_seed_1 = gr.Checkbox(label='Randomize seed',
|
303 |
+
value=True)
|
304 |
+
guidance_scale_1 = gr.Slider(label='Guidance scale',
|
305 |
+
minimum=1,
|
306 |
+
maximum=20,
|
307 |
+
step=0.1,
|
308 |
+
value=7.0)
|
309 |
+
custom_timesteps_1 = gr.Dropdown(
|
310 |
+
label='Custom timesteps 1',
|
311 |
+
choices=[
|
312 |
+
'none',
|
313 |
+
'fast27',
|
314 |
+
'smart27',
|
315 |
+
'smart50',
|
316 |
+
'smart100',
|
317 |
+
'smart185',
|
318 |
+
],
|
319 |
+
value=DEFAULT_CUSTOM_TIMESTEPS_1,
|
320 |
+
visible=SHOW_CUSTOM_TIMESTEPS_1)
|
321 |
+
num_inference_steps_1 = gr.Slider(
|
322 |
+
label='Number of inference steps',
|
323 |
+
minimum=1,
|
324 |
+
maximum=MAX_NUM_STEPS,
|
325 |
+
step=1,
|
326 |
+
value=100,
|
327 |
+
visible=SHOW_NUM_STEPS_1)
|
328 |
+
num_images = gr.Slider(label='Number of images',
|
329 |
+
minimum=1,
|
330 |
+
maximum=MAX_NUM_IMAGES,
|
331 |
+
step=1,
|
332 |
+
value=DEFAULT_NUM_IMAGES,
|
333 |
+
visible=SHOW_NUM_IMAGES)
|
334 |
+
with gr.Tab(label='Super-resolution 1'):
|
335 |
+
seed_2 = gr.Slider(label='Seed',
|
336 |
+
minimum=0,
|
337 |
+
maximum=MAX_SEED,
|
338 |
+
step=1,
|
339 |
+
value=0)
|
340 |
+
randomize_seed_2 = gr.Checkbox(label='Randomize seed',
|
341 |
+
value=True)
|
342 |
+
guidance_scale_2 = gr.Slider(label='Guidance scale',
|
343 |
+
minimum=1,
|
344 |
+
maximum=20,
|
345 |
+
step=0.1,
|
346 |
+
value=4.0)
|
347 |
+
custom_timesteps_2 = gr.Dropdown(
|
348 |
+
label='Custom timesteps 2',
|
349 |
+
choices=[
|
350 |
+
'none',
|
351 |
+
'fast27',
|
352 |
+
'smart27',
|
353 |
+
'smart50',
|
354 |
+
'smart100',
|
355 |
+
'smart185',
|
356 |
+
],
|
357 |
+
value=DEFAULT_CUSTOM_TIMESTEPS_2,
|
358 |
+
visible=SHOW_CUSTOM_TIMESTEPS_2)
|
359 |
+
num_inference_steps_2 = gr.Slider(
|
360 |
+
label='Number of inference steps',
|
361 |
+
minimum=1,
|
362 |
+
maximum=MAX_NUM_STEPS,
|
363 |
+
step=1,
|
364 |
+
value=50,
|
365 |
+
visible=SHOW_NUM_STEPS_2)
|
366 |
+
with gr.Tab(label='Super-resolution 2'):
|
367 |
+
seed_3 = gr.Slider(label='Seed',
|
368 |
+
minimum=0,
|
369 |
+
maximum=MAX_SEED,
|
370 |
+
step=1,
|
371 |
+
value=0)
|
372 |
+
randomize_seed_3 = gr.Checkbox(label='Randomize seed',
|
373 |
+
value=True)
|
374 |
+
guidance_scale_3 = gr.Slider(label='Guidance scale',
|
375 |
+
minimum=1,
|
376 |
+
maximum=20,
|
377 |
+
step=0.1,
|
378 |
+
value=9.0)
|
379 |
+
num_inference_steps_3 = gr.Slider(
|
380 |
+
label='Number of inference steps',
|
381 |
+
minimum=1,
|
382 |
+
maximum=MAX_NUM_STEPS,
|
383 |
+
step=1,
|
384 |
+
value=DEFAULT_NUM_STEPS_3,
|
385 |
+
visible=SHOW_NUM_STEPS_3)
|
386 |
+
|
387 |
+
gr.Examples(examples=examples, inputs=prompt, examples_per_page=4)
|
388 |
+
|
389 |
+
with gr.Box(visible=DEBUG):
|
390 |
+
with gr.Row():
|
391 |
+
with gr.Accordion(label='Hidden params'):
|
392 |
+
stage1_param_path = gr.Text(label='Stage 1 param path')
|
393 |
+
stage1_result_path = gr.Text(label='Stage 1 result path')
|
394 |
+
stage1_param_file_hash_name = gr.Text(
|
395 |
+
label='Stage 1 param file hash name')
|
396 |
+
selected_index_for_stage2 = gr.Number(
|
397 |
+
label='Selected index for Stage 2', value=-1, precision=0)
|
398 |
+
gr.Markdown(DISCLAIMER)
|
399 |
+
gr.HTML(FOOTER)
|
400 |
+
stage1_inputs = [
|
401 |
+
prompt,
|
402 |
+
negative_prompt,
|
403 |
+
seed_1,
|
404 |
+
num_images,
|
405 |
+
guidance_scale_1,
|
406 |
+
custom_timesteps_1,
|
407 |
+
num_inference_steps_1,
|
408 |
+
]
|
409 |
+
stage1_outputs = [
|
410 |
+
gallery,
|
411 |
+
stage1_param_path,
|
412 |
+
stage1_result_path,
|
413 |
+
]
|
414 |
+
|
415 |
+
prompt.submit(
|
416 |
+
fn=randomize_seed_fn,
|
417 |
+
inputs=[seed_1, randomize_seed_1],
|
418 |
+
outputs=seed_1,
|
419 |
+
queue=False,
|
420 |
+
).then(
|
421 |
+
fn=lambda: -1,
|
422 |
+
outputs=selected_index_for_stage2,
|
423 |
+
queue=False,
|
424 |
+
).then(
|
425 |
+
fn=show_gallery_view,
|
426 |
+
outputs=[
|
427 |
+
gallery_view,
|
428 |
+
upscale_view,
|
429 |
+
],
|
430 |
+
queue=False,
|
431 |
+
).then(
|
432 |
+
fn=update_upscale_button,
|
433 |
+
inputs=selected_index_for_stage2,
|
434 |
+
outputs=[
|
435 |
+
upscale_button,
|
436 |
+
upscale_to_256_button,
|
437 |
+
],
|
438 |
+
queue=False,
|
439 |
+
).then(
|
440 |
+
fn=model.run_stage1,
|
441 |
+
inputs=stage1_inputs,
|
442 |
+
outputs=stage1_outputs,
|
443 |
+
).success(
|
444 |
+
fn=get_param_file_hash_name,
|
445 |
+
inputs=stage1_param_path,
|
446 |
+
outputs=stage1_param_file_hash_name,
|
447 |
+
queue=False,
|
448 |
+
).then(
|
449 |
+
fn=upload_stage1_result,
|
450 |
+
inputs=[
|
451 |
+
stage1_param_path,
|
452 |
+
stage1_result_path,
|
453 |
+
stage1_param_file_hash_name,
|
454 |
+
],
|
455 |
+
queue=False,
|
456 |
+
)
|
457 |
+
|
458 |
+
negative_prompt.submit(
|
459 |
+
fn=randomize_seed_fn,
|
460 |
+
inputs=[seed_1, randomize_seed_1],
|
461 |
+
outputs=seed_1,
|
462 |
+
queue=False,
|
463 |
+
).then(
|
464 |
+
fn=lambda: -1,
|
465 |
+
outputs=selected_index_for_stage2,
|
466 |
+
queue=False,
|
467 |
+
).then(
|
468 |
+
fn=show_gallery_view,
|
469 |
+
outputs=[
|
470 |
+
gallery_view,
|
471 |
+
upscale_view,
|
472 |
+
],
|
473 |
+
queue=False,
|
474 |
+
).then(
|
475 |
+
fn=update_upscale_button,
|
476 |
+
inputs=selected_index_for_stage2,
|
477 |
+
outputs=[
|
478 |
+
upscale_button,
|
479 |
+
upscale_to_256_button,
|
480 |
+
],
|
481 |
+
queue=False,
|
482 |
+
).then(
|
483 |
+
fn=model.run_stage1,
|
484 |
+
inputs=stage1_inputs,
|
485 |
+
outputs=stage1_outputs,
|
486 |
+
).success(
|
487 |
+
fn=get_param_file_hash_name,
|
488 |
+
inputs=stage1_param_path,
|
489 |
+
outputs=stage1_param_file_hash_name,
|
490 |
+
queue=False,
|
491 |
+
).then(
|
492 |
+
fn=upload_stage1_result,
|
493 |
+
inputs=[
|
494 |
+
stage1_param_path,
|
495 |
+
stage1_result_path,
|
496 |
+
stage1_param_file_hash_name,
|
497 |
+
],
|
498 |
+
queue=False,
|
499 |
+
)
|
500 |
+
|
501 |
+
generate_button.click(
|
502 |
+
fn=randomize_seed_fn,
|
503 |
+
inputs=[seed_1, randomize_seed_1],
|
504 |
+
outputs=seed_1,
|
505 |
+
queue=False,
|
506 |
+
).then(
|
507 |
+
fn=lambda: -1,
|
508 |
+
outputs=selected_index_for_stage2,
|
509 |
+
queue=False,
|
510 |
+
).then(
|
511 |
+
fn=show_gallery_view,
|
512 |
+
outputs=[
|
513 |
+
gallery_view,
|
514 |
+
upscale_view,
|
515 |
+
],
|
516 |
+
queue=False,
|
517 |
+
).then(
|
518 |
+
fn=update_upscale_button,
|
519 |
+
inputs=selected_index_for_stage2,
|
520 |
+
outputs=[
|
521 |
+
upscale_button,
|
522 |
+
upscale_to_256_button,
|
523 |
+
],
|
524 |
+
queue=False,
|
525 |
+
).then(
|
526 |
+
fn=model.run_stage1,
|
527 |
+
inputs=stage1_inputs,
|
528 |
+
outputs=stage1_outputs,
|
529 |
+
api_name='generate64',
|
530 |
+
).success(
|
531 |
+
fn=get_param_file_hash_name,
|
532 |
+
inputs=stage1_param_path,
|
533 |
+
outputs=stage1_param_file_hash_name,
|
534 |
+
queue=False,
|
535 |
+
).then(
|
536 |
+
fn=upload_stage1_result,
|
537 |
+
inputs=[
|
538 |
+
stage1_param_path,
|
539 |
+
stage1_result_path,
|
540 |
+
stage1_param_file_hash_name,
|
541 |
+
],
|
542 |
+
queue=False,
|
543 |
+
)
|
544 |
+
|
545 |
+
gallery.select(
|
546 |
+
fn=get_stage2_index,
|
547 |
+
outputs=selected_index_for_stage2,
|
548 |
+
queue=False,
|
549 |
+
)
|
550 |
+
|
551 |
+
selected_index_for_stage2.change(
|
552 |
+
fn=update_upscale_button,
|
553 |
+
inputs=selected_index_for_stage2,
|
554 |
+
outputs=[
|
555 |
+
upscale_button,
|
556 |
+
upscale_to_256_button,
|
557 |
+
],
|
558 |
+
queue=False,
|
559 |
+
)
|
560 |
+
|
561 |
+
stage2_inputs = [
|
562 |
+
stage1_result_path,
|
563 |
+
selected_index_for_stage2,
|
564 |
+
seed_2,
|
565 |
+
guidance_scale_2,
|
566 |
+
custom_timesteps_2,
|
567 |
+
num_inference_steps_2,
|
568 |
+
]
|
569 |
+
|
570 |
+
upscale_to_256_button.click(
|
571 |
+
fn=check_if_stage2_selected,
|
572 |
+
inputs=selected_index_for_stage2,
|
573 |
+
queue=False,
|
574 |
+
).then(
|
575 |
+
fn=randomize_seed_fn,
|
576 |
+
inputs=[seed_2, randomize_seed_2],
|
577 |
+
outputs=seed_2,
|
578 |
+
queue=False,
|
579 |
+
).then(
|
580 |
+
fn=show_upscaled_view,
|
581 |
+
outputs=[
|
582 |
+
gallery_view,
|
583 |
+
upscale_view,
|
584 |
+
],
|
585 |
+
queue=False,
|
586 |
+
).then(
|
587 |
+
fn=model.run_stage2,
|
588 |
+
inputs=stage2_inputs,
|
589 |
+
outputs=result,
|
590 |
+
api_name='upscale256',
|
591 |
+
).success(
|
592 |
+
fn=upload_stage2_info,
|
593 |
+
inputs=[
|
594 |
+
stage1_param_file_hash_name,
|
595 |
+
result,
|
596 |
+
selected_index_for_stage2,
|
597 |
+
seed_2,
|
598 |
+
guidance_scale_2,
|
599 |
+
custom_timesteps_2,
|
600 |
+
num_inference_steps_2,
|
601 |
+
],
|
602 |
+
queue=False,
|
603 |
+
)
|
604 |
+
|
605 |
+
stage2_3_inputs = [
|
606 |
+
stage1_result_path,
|
607 |
+
selected_index_for_stage2,
|
608 |
+
seed_2,
|
609 |
+
guidance_scale_2,
|
610 |
+
custom_timesteps_2,
|
611 |
+
num_inference_steps_2,
|
612 |
+
prompt,
|
613 |
+
negative_prompt,
|
614 |
+
seed_3,
|
615 |
+
guidance_scale_3,
|
616 |
+
num_inference_steps_3,
|
617 |
+
]
|
618 |
+
|
619 |
+
upscale_button.click(
|
620 |
+
fn=check_if_stage2_selected,
|
621 |
+
inputs=selected_index_for_stage2,
|
622 |
+
queue=False,
|
623 |
+
).then(
|
624 |
+
fn=randomize_seed_fn,
|
625 |
+
inputs=[seed_2, randomize_seed_2],
|
626 |
+
outputs=seed_2,
|
627 |
+
queue=False,
|
628 |
+
).then(
|
629 |
+
fn=randomize_seed_fn,
|
630 |
+
inputs=[seed_3, randomize_seed_3],
|
631 |
+
outputs=seed_3,
|
632 |
+
queue=False,
|
633 |
+
).then(
|
634 |
+
fn=show_upscaled_view,
|
635 |
+
outputs=[
|
636 |
+
gallery_view,
|
637 |
+
upscale_view,
|
638 |
+
],
|
639 |
+
queue=False,
|
640 |
+
).then(
|
641 |
+
fn=model.run_stage2_3,
|
642 |
+
inputs=stage2_3_inputs,
|
643 |
+
outputs=result,
|
644 |
+
api_name='upscale1024',
|
645 |
+
).success(
|
646 |
+
fn=upload_stage2_3_info,
|
647 |
+
inputs=[
|
648 |
+
stage1_param_file_hash_name,
|
649 |
+
result,
|
650 |
+
selected_index_for_stage2,
|
651 |
+
seed_2,
|
652 |
+
guidance_scale_2,
|
653 |
+
custom_timesteps_2,
|
654 |
+
num_inference_steps_2,
|
655 |
+
prompt,
|
656 |
+
negative_prompt,
|
657 |
+
seed_3,
|
658 |
+
guidance_scale_3,
|
659 |
+
num_inference_steps_3,
|
660 |
+
],
|
661 |
+
queue=False,
|
662 |
+
)
|
663 |
+
|
664 |
+
back_to_selection_button.click(
|
665 |
+
fn=show_gallery_view,
|
666 |
+
outputs=[
|
667 |
+
gallery_view,
|
668 |
+
upscale_view,
|
669 |
+
],
|
670 |
+
queue=False,
|
671 |
+
)
|
672 |
+
|
673 |
+
demo.queue(api_open=False, max_size=MAX_QUEUE_SIZE).launch(debug=DEBUG)
|
model.py
ADDED
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import gc
|
4 |
+
import json
|
5 |
+
import tempfile
|
6 |
+
from typing import Generator
|
7 |
+
|
8 |
+
import numpy as np
|
9 |
+
import PIL.Image
|
10 |
+
import torch
|
11 |
+
from diffusers import DiffusionPipeline, StableDiffusionUpscalePipeline
|
12 |
+
from diffusers.pipelines.deepfloyd_if import (fast27_timesteps,
|
13 |
+
smart27_timesteps,
|
14 |
+
smart50_timesteps,
|
15 |
+
smart100_timesteps,
|
16 |
+
smart185_timesteps)
|
17 |
+
|
18 |
+
from settings import (DISABLE_AUTOMATIC_CPU_OFFLOAD, DISABLE_SD_X4_UPSCALER,
|
19 |
+
HF_TOKEN, MAX_NUM_IMAGES, MAX_NUM_STEPS, MAX_SEED,
|
20 |
+
RUN_GARBAGE_COLLECTION)
|
21 |
+
|
22 |
+
|
23 |
+
class Model:
|
24 |
+
def __init__(self):
|
25 |
+
self.device = torch.device(
|
26 |
+
'cuda:0' if torch.cuda.is_available() else 'cpu')
|
27 |
+
self.pipe = None
|
28 |
+
self.super_res_1_pipe = None
|
29 |
+
self.super_res_2_pipe = None
|
30 |
+
self.watermark_image = None
|
31 |
+
|
32 |
+
if torch.cuda.is_available():
|
33 |
+
self.load_weights()
|
34 |
+
self.watermark_image = PIL.Image.fromarray(
|
35 |
+
self.pipe.watermarker.watermark_image.to(
|
36 |
+
torch.uint8).cpu().numpy(),
|
37 |
+
mode='RGBA')
|
38 |
+
|
39 |
+
def load_weights(self) -> None:
|
40 |
+
self.pipe = DiffusionPipeline.from_pretrained(
|
41 |
+
'DeepFloyd/IF-I-XL-v1.0',
|
42 |
+
torch_dtype=torch.float16,
|
43 |
+
variant='fp16',
|
44 |
+
use_safetensors=True,
|
45 |
+
use_auth_token=HF_TOKEN)
|
46 |
+
self.super_res_1_pipe = DiffusionPipeline.from_pretrained(
|
47 |
+
'DeepFloyd/IF-II-L-v1.0',
|
48 |
+
text_encoder=None,
|
49 |
+
torch_dtype=torch.float16,
|
50 |
+
variant='fp16',
|
51 |
+
use_safetensors=True,
|
52 |
+
use_auth_token=HF_TOKEN)
|
53 |
+
|
54 |
+
if not DISABLE_SD_X4_UPSCALER:
|
55 |
+
self.super_res_2_pipe = StableDiffusionUpscalePipeline.from_pretrained(
|
56 |
+
'stabilityai/stable-diffusion-x4-upscaler',
|
57 |
+
torch_dtype=torch.float16)
|
58 |
+
|
59 |
+
if DISABLE_AUTOMATIC_CPU_OFFLOAD:
|
60 |
+
self.pipe.to(self.device)
|
61 |
+
self.super_res_1_pipe.to(self.device)
|
62 |
+
if not DISABLE_SD_X4_UPSCALER:
|
63 |
+
self.super_res_2_pipe.to(self.device)
|
64 |
+
else:
|
65 |
+
self.pipe.enable_model_cpu_offload()
|
66 |
+
self.super_res_1_pipe.enable_model_cpu_offload()
|
67 |
+
if not DISABLE_SD_X4_UPSCALER:
|
68 |
+
self.super_res_2_pipe.enable_model_cpu_offload()
|
69 |
+
|
70 |
+
def apply_watermark_to_sd_x4_upscaler_results(
|
71 |
+
self, images: list[PIL.Image.Image]) -> None:
|
72 |
+
w, h = images[0].size
|
73 |
+
|
74 |
+
stability_x4_upscaler_sample_size = 128
|
75 |
+
|
76 |
+
coef = min(h / stability_x4_upscaler_sample_size,
|
77 |
+
w / stability_x4_upscaler_sample_size)
|
78 |
+
img_h, img_w = (int(h / coef), int(w / coef)) if coef < 1 else (h, w)
|
79 |
+
|
80 |
+
S1, S2 = 1024**2, img_w * img_h
|
81 |
+
K = (S2 / S1)**0.5
|
82 |
+
watermark_size = int(K * 62)
|
83 |
+
watermark_x = img_w - int(14 * K)
|
84 |
+
watermark_y = img_h - int(14 * K)
|
85 |
+
|
86 |
+
watermark_image = self.watermark_image.copy().resize(
|
87 |
+
(watermark_size, watermark_size),
|
88 |
+
PIL.Image.Resampling.BICUBIC,
|
89 |
+
reducing_gap=None)
|
90 |
+
|
91 |
+
for image in images:
|
92 |
+
image.paste(watermark_image,
|
93 |
+
box=(
|
94 |
+
watermark_x - watermark_size,
|
95 |
+
watermark_y - watermark_size,
|
96 |
+
watermark_x,
|
97 |
+
watermark_y,
|
98 |
+
),
|
99 |
+
mask=watermark_image.split()[-1])
|
100 |
+
|
101 |
+
@staticmethod
|
102 |
+
def to_pil_images(images: torch.Tensor) -> list[PIL.Image.Image]:
|
103 |
+
images = (images / 2 + 0.5).clamp(0, 1)
|
104 |
+
images = images.cpu().permute(0, 2, 3, 1).float().numpy()
|
105 |
+
images = np.round(images * 255).astype(np.uint8)
|
106 |
+
return [PIL.Image.fromarray(image) for image in images]
|
107 |
+
|
108 |
+
@staticmethod
|
109 |
+
def check_seed(seed: int) -> None:
|
110 |
+
if not 0 <= seed <= MAX_SEED:
|
111 |
+
raise ValueError
|
112 |
+
|
113 |
+
@staticmethod
|
114 |
+
def check_num_images(num_images: int) -> None:
|
115 |
+
if not 1 <= num_images <= MAX_NUM_IMAGES:
|
116 |
+
raise ValueError
|
117 |
+
|
118 |
+
@staticmethod
|
119 |
+
def check_num_inference_steps(num_steps: int) -> None:
|
120 |
+
if not 1 <= num_steps <= MAX_NUM_STEPS:
|
121 |
+
raise ValueError
|
122 |
+
|
123 |
+
@staticmethod
|
124 |
+
def get_custom_timesteps(name: str) -> list[int] | None:
|
125 |
+
if name == 'none':
|
126 |
+
timesteps = None
|
127 |
+
elif name == 'fast27':
|
128 |
+
timesteps = fast27_timesteps
|
129 |
+
elif name == 'smart27':
|
130 |
+
timesteps = smart27_timesteps
|
131 |
+
elif name == 'smart50':
|
132 |
+
timesteps = smart50_timesteps
|
133 |
+
elif name == 'smart100':
|
134 |
+
timesteps = smart100_timesteps
|
135 |
+
elif name == 'smart185':
|
136 |
+
timesteps = smart185_timesteps
|
137 |
+
else:
|
138 |
+
raise ValueError
|
139 |
+
return timesteps
|
140 |
+
|
141 |
+
@staticmethod
|
142 |
+
def run_garbage_collection():
|
143 |
+
gc.collect()
|
144 |
+
torch.cuda.empty_cache()
|
145 |
+
|
146 |
+
def run_stage1(
|
147 |
+
self,
|
148 |
+
prompt: str,
|
149 |
+
negative_prompt: str = '',
|
150 |
+
seed: int = 0,
|
151 |
+
num_images: int = 1,
|
152 |
+
guidance_scale_1: float = 7.0,
|
153 |
+
custom_timesteps_1: str = 'smart100',
|
154 |
+
num_inference_steps_1: int = 100,
|
155 |
+
) -> tuple[list[PIL.Image.Image], str, str]:
|
156 |
+
self.check_seed(seed)
|
157 |
+
self.check_num_images(num_images)
|
158 |
+
self.check_num_inference_steps(num_inference_steps_1)
|
159 |
+
|
160 |
+
if RUN_GARBAGE_COLLECTION:
|
161 |
+
self.run_garbage_collection()
|
162 |
+
|
163 |
+
generator = torch.Generator(device=self.device).manual_seed(seed)
|
164 |
+
|
165 |
+
prompt_embeds, negative_embeds = self.pipe.encode_prompt(
|
166 |
+
prompt=prompt, negative_prompt=negative_prompt)
|
167 |
+
|
168 |
+
timesteps = self.get_custom_timesteps(custom_timesteps_1)
|
169 |
+
|
170 |
+
images = self.pipe(prompt_embeds=prompt_embeds,
|
171 |
+
negative_prompt_embeds=negative_embeds,
|
172 |
+
num_images_per_prompt=num_images,
|
173 |
+
guidance_scale=guidance_scale_1,
|
174 |
+
timesteps=timesteps,
|
175 |
+
num_inference_steps=num_inference_steps_1,
|
176 |
+
generator=generator,
|
177 |
+
output_type='pt').images
|
178 |
+
pil_images = self.to_pil_images(images)
|
179 |
+
self.pipe.watermarker.apply_watermark(
|
180 |
+
pil_images, self.pipe.unet.config.sample_size)
|
181 |
+
|
182 |
+
stage1_params = {
|
183 |
+
'prompt': prompt,
|
184 |
+
'negative_prompt': negative_prompt,
|
185 |
+
'seed': seed,
|
186 |
+
'num_images': num_images,
|
187 |
+
'guidance_scale_1': guidance_scale_1,
|
188 |
+
'custom_timesteps_1': custom_timesteps_1,
|
189 |
+
'num_inference_steps_1': num_inference_steps_1,
|
190 |
+
}
|
191 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as param_file:
|
192 |
+
param_file.write(json.dumps(stage1_params))
|
193 |
+
stage1_result = {
|
194 |
+
'prompt_embeds': prompt_embeds,
|
195 |
+
'negative_embeds': negative_embeds,
|
196 |
+
'images': images,
|
197 |
+
'pil_images': pil_images,
|
198 |
+
}
|
199 |
+
with tempfile.NamedTemporaryFile(delete=False) as result_file:
|
200 |
+
torch.save(stage1_result, result_file.name)
|
201 |
+
return pil_images, param_file.name, result_file.name
|
202 |
+
|
203 |
+
def run_stage2(
|
204 |
+
self,
|
205 |
+
stage1_result_path: str,
|
206 |
+
stage2_index: int,
|
207 |
+
seed_2: int = 0,
|
208 |
+
guidance_scale_2: float = 4.0,
|
209 |
+
custom_timesteps_2: str = 'smart50',
|
210 |
+
num_inference_steps_2: int = 50,
|
211 |
+
disable_watermark: bool = False,
|
212 |
+
) -> PIL.Image.Image:
|
213 |
+
self.check_seed(seed_2)
|
214 |
+
self.check_num_inference_steps(num_inference_steps_2)
|
215 |
+
|
216 |
+
if RUN_GARBAGE_COLLECTION:
|
217 |
+
self.run_garbage_collection()
|
218 |
+
|
219 |
+
generator = torch.Generator(device=self.device).manual_seed(seed_2)
|
220 |
+
|
221 |
+
stage1_result = torch.load(stage1_result_path)
|
222 |
+
prompt_embeds = stage1_result['prompt_embeds']
|
223 |
+
negative_embeds = stage1_result['negative_embeds']
|
224 |
+
images = stage1_result['images']
|
225 |
+
images = images[[stage2_index]]
|
226 |
+
|
227 |
+
timesteps = self.get_custom_timesteps(custom_timesteps_2)
|
228 |
+
|
229 |
+
out = self.super_res_1_pipe(image=images,
|
230 |
+
prompt_embeds=prompt_embeds,
|
231 |
+
negative_prompt_embeds=negative_embeds,
|
232 |
+
num_images_per_prompt=1,
|
233 |
+
guidance_scale=guidance_scale_2,
|
234 |
+
timesteps=timesteps,
|
235 |
+
num_inference_steps=num_inference_steps_2,
|
236 |
+
generator=generator,
|
237 |
+
output_type='pt',
|
238 |
+
noise_level=250).images
|
239 |
+
pil_images = self.to_pil_images(out)
|
240 |
+
|
241 |
+
if disable_watermark:
|
242 |
+
return pil_images[0]
|
243 |
+
|
244 |
+
self.super_res_1_pipe.watermarker.apply_watermark(
|
245 |
+
pil_images, self.super_res_1_pipe.unet.config.sample_size)
|
246 |
+
return pil_images[0]
|
247 |
+
|
248 |
+
def run_stage3(
|
249 |
+
self,
|
250 |
+
image: PIL.Image.Image,
|
251 |
+
prompt: str = '',
|
252 |
+
negative_prompt: str = '',
|
253 |
+
seed_3: int = 0,
|
254 |
+
guidance_scale_3: float = 9.0,
|
255 |
+
num_inference_steps_3: int = 75,
|
256 |
+
) -> PIL.Image.Image:
|
257 |
+
self.check_seed(seed_3)
|
258 |
+
self.check_num_inference_steps(num_inference_steps_3)
|
259 |
+
|
260 |
+
if RUN_GARBAGE_COLLECTION:
|
261 |
+
self.run_garbage_collection()
|
262 |
+
|
263 |
+
generator = torch.Generator(device=self.device).manual_seed(seed_3)
|
264 |
+
out = self.super_res_2_pipe(image=image,
|
265 |
+
prompt=prompt,
|
266 |
+
negative_prompt=negative_prompt,
|
267 |
+
num_images_per_prompt=1,
|
268 |
+
guidance_scale=guidance_scale_3,
|
269 |
+
num_inference_steps=num_inference_steps_3,
|
270 |
+
generator=generator,
|
271 |
+
noise_level=100).images
|
272 |
+
self.apply_watermark_to_sd_x4_upscaler_results(out)
|
273 |
+
return out[0]
|
274 |
+
|
275 |
+
def run_stage2_3(
|
276 |
+
self,
|
277 |
+
stage1_result_path: str,
|
278 |
+
stage2_index: int,
|
279 |
+
seed_2: int = 0,
|
280 |
+
guidance_scale_2: float = 4.0,
|
281 |
+
custom_timesteps_2: str = 'smart50',
|
282 |
+
num_inference_steps_2: int = 50,
|
283 |
+
prompt: str = '',
|
284 |
+
negative_prompt: str = '',
|
285 |
+
seed_3: int = 0,
|
286 |
+
guidance_scale_3: float = 9.0,
|
287 |
+
num_inference_steps_3: int = 75,
|
288 |
+
) -> Generator[PIL.Image.Image]:
|
289 |
+
self.check_seed(seed_3)
|
290 |
+
self.check_num_inference_steps(num_inference_steps_3)
|
291 |
+
|
292 |
+
out_image = self.run_stage2(
|
293 |
+
stage1_result_path=stage1_result_path,
|
294 |
+
stage2_index=stage2_index,
|
295 |
+
seed_2=seed_2,
|
296 |
+
guidance_scale_2=guidance_scale_2,
|
297 |
+
custom_timesteps_2=custom_timesteps_2,
|
298 |
+
num_inference_steps_2=num_inference_steps_2,
|
299 |
+
disable_watermark=True)
|
300 |
+
temp_image = out_image.copy()
|
301 |
+
self.super_res_1_pipe.watermarker.apply_watermark(
|
302 |
+
[temp_image], self.super_res_1_pipe.unet.config.sample_size)
|
303 |
+
yield temp_image
|
304 |
+
yield self.run_stage3(image=out_image,
|
305 |
+
prompt=prompt,
|
306 |
+
negative_prompt=negative_prompt,
|
307 |
+
seed_3=seed_3,
|
308 |
+
guidance_scale_3=guidance_scale_3,
|
309 |
+
num_inference_steps_3=num_inference_steps_3)
|
requirements.txt
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate==0.18.0
|
2 |
+
beautifulsoup4==4.12.2
|
3 |
+
bitsandbytes==0.38.1
|
4 |
+
diffusers==0.16.0
|
5 |
+
ftfy==6.1.1
|
6 |
+
gradio==3.27.0
|
7 |
+
huggingface_hub==0.14.1
|
8 |
+
numpy==1.24.3
|
9 |
+
Pillow==9.5.0
|
10 |
+
safetensors==0.3.0
|
11 |
+
sentencepiece==0.1.98
|
12 |
+
tokenizers==0.13.3
|
13 |
+
torch==2.0.0
|
14 |
+
torchvision==0.15.1
|
15 |
+
tqdm==4.65.0
|
16 |
+
transformers==4.28.1
|
settings.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
6 |
+
UPLOAD_REPO_ID = os.getenv('UPLOAD_REPO_ID')
|
7 |
+
UPLOAD_RESULT_IMAGE = os.getenv('UPLOAD_RESULT_IMAGE') == '1'
|
8 |
+
|
9 |
+
# UI options
|
10 |
+
SHOW_DUPLICATE_BUTTON = os.getenv('SHOW_DUPLICATE_BUTTON', '0') == '1'
|
11 |
+
SHOW_DEVICE_WARNING = os.getenv('SHOW_DEVICE_WARNING', '1') == '1'
|
12 |
+
SHOW_ADVANCED_OPTIONS = os.getenv('SHOW_ADVANCED_OPTIONS', '1') == '1'
|
13 |
+
SHOW_UPSCALE_TO_256_BUTTON = os.getenv('SHOW_UPSCALE_TO_256_BUTTON',
|
14 |
+
'0') == '1'
|
15 |
+
SHOW_NUM_IMAGES = os.getenv('SHOW_NUM_IMAGES_OPTION', '1') == '1'
|
16 |
+
SHOW_CUSTOM_TIMESTEPS_1 = os.getenv('SHOW_CUSTOM_TIMESTEPS_1', '1') == '1'
|
17 |
+
SHOW_CUSTOM_TIMESTEPS_2 = os.getenv('SHOW_CUSTOM_TIMESTEPS_2', '1') == '1'
|
18 |
+
SHOW_NUM_STEPS_1 = os.getenv('SHOW_NUM_STEPS_1', '0') == '1'
|
19 |
+
SHOW_NUM_STEPS_2 = os.getenv('SHOW_NUM_STEPS_2', '0') == '1'
|
20 |
+
SHOW_NUM_STEPS_3 = os.getenv('SHOW_NUM_STEPS_3', '1') == '1'
|
21 |
+
GALLERY_COLUMN_NUM = int(os.getenv('GALLERY_COLUMN_NUM', '4'))
|
22 |
+
|
23 |
+
# Parameters
|
24 |
+
MAX_QUEUE_SIZE = int(os.getenv('MAX_QUEUE_SIZE', '10'))
|
25 |
+
MAX_SEED = np.iinfo(np.int32).max
|
26 |
+
MAX_NUM_IMAGES = int(os.getenv('MAX_NUM_IMAGES', '4'))
|
27 |
+
DEFAULT_NUM_IMAGES = min(MAX_NUM_IMAGES,
|
28 |
+
int(os.getenv('DEFAULT_NUM_IMAGES', '4')))
|
29 |
+
MAX_NUM_STEPS = int(os.getenv('MAX_NUM_STEPS', '200'))
|
30 |
+
DEFAULT_CUSTOM_TIMESTEPS_1 = os.getenv('DEFAULT_CUSTOM_TIMESTEPS_1',
|
31 |
+
'smart100')
|
32 |
+
DEFAULT_CUSTOM_TIMESTEPS_2 = os.getenv('DEFAULT_CUSTOM_TIMESTEPS_2', 'smart50')
|
33 |
+
DEFAULT_NUM_STEPS_3 = int(os.getenv('DEFAULT_NUM_STEPS_3', '40'))
|
34 |
+
|
35 |
+
# Model options
|
36 |
+
DISABLE_AUTOMATIC_CPU_OFFLOAD = os.getenv(
|
37 |
+
'DISABLE_AUTOMATIC_CPU_OFFLOAD') == '1'
|
38 |
+
DISABLE_SD_X4_UPSCALER = os.getenv('DISABLE_SD_X4_UPSCALER') == '1'
|
39 |
+
|
40 |
+
# Other options
|
41 |
+
RUN_GARBAGE_COLLECTION = os.getenv('RUN_GARBAGE_COLLECTION', '1') == '1'
|
42 |
+
DEBUG = os.getenv('DEBUG') == '1'
|
43 |
+
|
44 |
+
# Default options for the public demo
|
45 |
+
if os.getenv('IS_PUBLIC_DEMO') == '1':
|
46 |
+
# UI
|
47 |
+
SHOW_DUPLICATE_BUTTON = True
|
48 |
+
SHOW_NUM_STEPS_3 = False
|
49 |
+
SHOW_CUSTOM_TIMESTEPS_1 = False
|
50 |
+
SHOW_CUSTOM_TIMESTEPS_2 = False
|
51 |
+
SHOW_NUM_IMAGES = False
|
52 |
+
# parameters
|
53 |
+
DEFAULT_CUSTOM_TIMESTEPS_1 = 'smart50'
|
54 |
+
UPLOAD_RESULT_IMAGE = True
|
55 |
+
# model
|
56 |
+
DISABLE_AUTOMATIC_CPU_OFFLOAD = True
|
57 |
+
RUN_GARBAGE_COLLECTION = False
|
share_btn.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
|
2 |
+
<path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
|
3 |
+
<path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
|
4 |
+
</svg>"""
|
5 |
+
|
6 |
+
loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin" style="color: #ffffff;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
|
7 |
+
|
8 |
+
share_js = """async () => {
|
9 |
+
async function uploadFile(file){
|
10 |
+
const UPLOAD_URL = 'https://huggingface.co/uploads';
|
11 |
+
const response = await fetch(UPLOAD_URL, {
|
12 |
+
method: 'POST',
|
13 |
+
headers: {
|
14 |
+
'Content-Type': file.type,
|
15 |
+
'X-Requested-With': 'XMLHttpRequest',
|
16 |
+
},
|
17 |
+
body: file, /// <- File inherits from Blob
|
18 |
+
});
|
19 |
+
const url = await response.text();
|
20 |
+
return url;
|
21 |
+
}
|
22 |
+
async function getInputImageFile(imageEl){
|
23 |
+
const res = await fetch(imageEl.src);
|
24 |
+
const blob = await res.blob();
|
25 |
+
const imageId = Date.now();
|
26 |
+
const fileName = `rich-text-image-${{imageId}}.png`;
|
27 |
+
return new File([blob], fileName, { type: 'image/png'});
|
28 |
+
}
|
29 |
+
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
|
30 |
+
const negative_prompt = gradioEl.querySelector('#negative-prompt-text-input input').value;
|
31 |
+
const prompt = gradioEl.querySelector('#prompt-text-input input').value;
|
32 |
+
const upscaledImage = gradioEl.querySelector('#upscaled-image img');
|
33 |
+
|
34 |
+
const titleTxt = `DeepFloyd IF: ${prompt.slice(0, 50)}...`;
|
35 |
+
|
36 |
+
const shareBtnEl = gradioEl.querySelector('#share-btn');
|
37 |
+
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
|
38 |
+
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
|
39 |
+
if(!upscaledImage){
|
40 |
+
return;
|
41 |
+
};
|
42 |
+
shareBtnEl.style.pointerEvents = 'none';
|
43 |
+
shareIconEl.style.display = 'none';
|
44 |
+
loadingIconEl.style.removeProperty('display');
|
45 |
+
|
46 |
+
const upscaledImageFile = await getInputImageFile(upscaledImage);
|
47 |
+
const upscaledImageURL = await uploadFile(upscaledImageFile);
|
48 |
+
|
49 |
+
const descriptionMd = `
|
50 |
+
### Prompt
|
51 |
+
${prompt}
|
52 |
+
|
53 |
+
### Negative Prompt
|
54 |
+
${negative_prompt}
|
55 |
+
|
56 |
+
### Upscaled Image
|
57 |
+
<img src="${upscaledImageURL}" alt="Upscaled Image" width="500"/>
|
58 |
+
|
59 |
+
`;
|
60 |
+
const params = new URLSearchParams({
|
61 |
+
title: titleTxt,
|
62 |
+
description: descriptionMd,
|
63 |
+
});
|
64 |
+
const paramsStr = params.toString();
|
65 |
+
window.open(`https://huggingface.co/spaces/DeepFloyd/IF/discussions/new?${paramsStr}`, '_blank');
|
66 |
+
shareBtnEl.style.removeProperty('pointer-events');
|
67 |
+
shareIconEl.style.removeProperty('display');
|
68 |
+
loadingIconEl.style.display = 'none';
|
69 |
+
}"""
|
style.css
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
This CSS file is modified from:
|
3 |
+
https://huggingface.co/spaces/stabilityai/stable-diffusion/blob/2794a3c3ba66115c307075098e713f572b08bf80/app.py
|
4 |
+
*/
|
5 |
+
|
6 |
+
h1 {
|
7 |
+
text-align: center;
|
8 |
+
}
|
9 |
+
|
10 |
+
.gradio-container {
|
11 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
12 |
+
}
|
13 |
+
|
14 |
+
.gr-button {
|
15 |
+
color: white;
|
16 |
+
border-color: black;
|
17 |
+
background: black;
|
18 |
+
}
|
19 |
+
|
20 |
+
input[type='range'] {
|
21 |
+
accent-color: black;
|
22 |
+
}
|
23 |
+
|
24 |
+
.dark input[type='range'] {
|
25 |
+
accent-color: #dfdfdf;
|
26 |
+
}
|
27 |
+
|
28 |
+
.container {
|
29 |
+
max-width: 730px;
|
30 |
+
margin: auto;
|
31 |
+
padding-top: 1.5rem;
|
32 |
+
}
|
33 |
+
|
34 |
+
#gallery {
|
35 |
+
min-height: auto;
|
36 |
+
height: 185px;
|
37 |
+
margin-top: 15px;
|
38 |
+
margin-left: auto;
|
39 |
+
margin-right: auto;
|
40 |
+
border-bottom-right-radius: .5rem !important;
|
41 |
+
border-bottom-left-radius: .5rem !important;
|
42 |
+
}
|
43 |
+
#gallery .grid-wrap, #gallery .empty{
|
44 |
+
height: 185px;
|
45 |
+
min-height: 185px;
|
46 |
+
}
|
47 |
+
#gallery .preview{
|
48 |
+
height: 185px;
|
49 |
+
min-height: 185px!important;
|
50 |
+
}
|
51 |
+
#gallery>div>.h-full {
|
52 |
+
min-height: 20rem;
|
53 |
+
}
|
54 |
+
|
55 |
+
.details:hover {
|
56 |
+
text-decoration: underline;
|
57 |
+
}
|
58 |
+
|
59 |
+
.gr-button {
|
60 |
+
white-space: nowrap;
|
61 |
+
}
|
62 |
+
|
63 |
+
.gr-button:focus {
|
64 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
65 |
+
outline: none;
|
66 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
67 |
+
--tw-border-opacity: 1;
|
68 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
69 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
70 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
71 |
+
--tw-ring-opacity: .5;
|
72 |
+
}
|
73 |
+
|
74 |
+
#advanced-btn {
|
75 |
+
font-size: .7rem !important;
|
76 |
+
line-height: 19px;
|
77 |
+
margin-top: 12px;
|
78 |
+
margin-bottom: 12px;
|
79 |
+
padding: 2px 8px;
|
80 |
+
border-radius: 14px !important;
|
81 |
+
}
|
82 |
+
|
83 |
+
#advanced-options {
|
84 |
+
display: none;
|
85 |
+
margin-bottom: 20px;
|
86 |
+
}
|
87 |
+
|
88 |
+
.footer {
|
89 |
+
margin-bottom: 45px;
|
90 |
+
margin-top: 35px;
|
91 |
+
text-align: center;
|
92 |
+
border-bottom: 1px solid #e5e5e5;
|
93 |
+
}
|
94 |
+
|
95 |
+
.footer>p {
|
96 |
+
font-size: .8rem;
|
97 |
+
display: inline-block;
|
98 |
+
padding: 0 10px;
|
99 |
+
transform: translateY(10px);
|
100 |
+
background: white;
|
101 |
+
}
|
102 |
+
|
103 |
+
.dark .footer {
|
104 |
+
border-color: #303030;
|
105 |
+
}
|
106 |
+
|
107 |
+
.dark .footer>p {
|
108 |
+
background: #0b0f19;
|
109 |
+
}
|
110 |
+
|
111 |
+
.acknowledgments h4 {
|
112 |
+
margin: 1.25em 0 .25em 0;
|
113 |
+
font-weight: bold;
|
114 |
+
font-size: 115%;
|
115 |
+
}
|
116 |
+
|
117 |
+
.animate-spin {
|
118 |
+
animation: spin 1s linear infinite;
|
119 |
+
}
|
120 |
+
|
121 |
+
@keyframes spin {
|
122 |
+
from {
|
123 |
+
transform: rotate(0deg);
|
124 |
+
}
|
125 |
+
|
126 |
+
to {
|
127 |
+
transform: rotate(360deg);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
#share-btn-container {
|
132 |
+
display: flex;
|
133 |
+
padding-left: 0.5rem !important;
|
134 |
+
padding-right: 0.5rem !important;
|
135 |
+
background-color: #000000;
|
136 |
+
justify-content: center;
|
137 |
+
align-items: center;
|
138 |
+
border-radius: 9999px !important;
|
139 |
+
width: 13rem;
|
140 |
+
margin-top: 10px;
|
141 |
+
margin-left: auto;
|
142 |
+
}
|
143 |
+
|
144 |
+
#share-btn {
|
145 |
+
all: initial;
|
146 |
+
color: #ffffff;
|
147 |
+
font-weight: 600;
|
148 |
+
cursor: pointer;
|
149 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
150 |
+
margin-left: 0.5rem !important;
|
151 |
+
padding-top: 0.25rem !important;
|
152 |
+
padding-bottom: 0.25rem !important;
|
153 |
+
right: 0;
|
154 |
+
}
|
155 |
+
|
156 |
+
#share-btn * {
|
157 |
+
all: unset;
|
158 |
+
}
|
159 |
+
|
160 |
+
#share-btn-container div:nth-child(-n+2) {
|
161 |
+
width: auto !important;
|
162 |
+
min-height: 0px !important;
|
163 |
+
}
|
164 |
+
|
165 |
+
#share-btn-container .wrap {
|
166 |
+
display: none !important;
|
167 |
+
}
|
168 |
+
|
169 |
+
.gr-form {
|
170 |
+
flex: 1 1 50%;
|
171 |
+
border-top-right-radius: 0;
|
172 |
+
border-bottom-right-radius: 0;
|
173 |
+
}
|
174 |
+
|
175 |
+
#prompt-container {
|
176 |
+
gap: 0;
|
177 |
+
}
|
178 |
+
|
179 |
+
#prompt-text-input,
|
180 |
+
#negative-prompt-text-input {
|
181 |
+
padding: .45rem 0.625rem
|
182 |
+
}
|
183 |
+
|
184 |
+
#component-16 {
|
185 |
+
border-top-width: 1px !important;
|
186 |
+
margin-top: 1em
|
187 |
+
}
|
188 |
+
|
189 |
+
.image_duplication {
|
190 |
+
position: absolute;
|
191 |
+
width: 100px;
|
192 |
+
left: 50px
|
193 |
+
}
|
194 |
+
|
195 |
+
#component-0 {
|
196 |
+
max-width: 730px;
|
197 |
+
margin: auto;
|
198 |
+
padding-top: 1.5rem;
|
199 |
+
}
|
200 |
+
|
201 |
+
#upscaled-image img {
|
202 |
+
object-fit: scale-down;
|
203 |
+
}
|
204 |
+
/* share button */
|
205 |
+
#share-btn-container {
|
206 |
+
display: flex;
|
207 |
+
padding-left: 0.5rem !important;
|
208 |
+
padding-right: 0.5rem !important;
|
209 |
+
background-color: #000000;
|
210 |
+
justify-content: center;
|
211 |
+
align-items: center;
|
212 |
+
border-radius: 9999px !important;
|
213 |
+
width: 13rem;
|
214 |
+
margin-top: 10px;
|
215 |
+
margin-left: auto;
|
216 |
+
flex: unset !important;
|
217 |
+
}
|
218 |
+
#share-btn {
|
219 |
+
all: initial;
|
220 |
+
color: #ffffff;
|
221 |
+
font-weight: 600;
|
222 |
+
cursor: pointer;
|
223 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
224 |
+
margin-left: 0.5rem !important;
|
225 |
+
padding-top: 0.25rem !important;
|
226 |
+
padding-bottom: 0.25rem !important;
|
227 |
+
right:0;
|
228 |
+
}
|
229 |
+
#share-btn * {
|
230 |
+
all: unset !important;
|
231 |
+
}
|
232 |
+
#share-btn-container div:nth-child(-n+2){
|
233 |
+
width: auto !important;
|
234 |
+
min-height: 0px !important;
|
235 |
+
}
|
236 |
+
#share-btn-container .wrap {
|
237 |
+
display: none !important;
|
238 |
+
}
|