Spaces:
Build error
Build error
Commit
•
e8f4668
0
Parent(s):
Duplicate from jbilcke-hf/360-server-1
Browse filesCo-authored-by: Julian Bilcke <[email protected]>
- .gitattributes +35 -0
- .gitignore +162 -0
- .pre-commit-config.yaml +36 -0
- .style.yapf +5 -0
- .vscode/settings.json +18 -0
- LICENSE +21 -0
- README.md +15 -0
- app.py +305 -0
- requirements.txt +7 -0
- style.css +16 -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 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.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,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
repos:
|
2 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
3 |
+
rev: v4.2.0
|
4 |
+
hooks:
|
5 |
+
- id: check-executables-have-shebangs
|
6 |
+
- id: check-json
|
7 |
+
- id: check-merge-conflict
|
8 |
+
- id: check-shebang-scripts-are-executable
|
9 |
+
- id: check-toml
|
10 |
+
- id: check-yaml
|
11 |
+
- id: double-quote-string-fixer
|
12 |
+
- id: end-of-file-fixer
|
13 |
+
- id: mixed-line-ending
|
14 |
+
args: ['--fix=lf']
|
15 |
+
- id: requirements-txt-fixer
|
16 |
+
- id: trailing-whitespace
|
17 |
+
- repo: https://github.com/myint/docformatter
|
18 |
+
rev: v1.4
|
19 |
+
hooks:
|
20 |
+
- id: docformatter
|
21 |
+
args: ['--in-place']
|
22 |
+
- repo: https://github.com/pycqa/isort
|
23 |
+
rev: 5.12.0
|
24 |
+
hooks:
|
25 |
+
- id: isort
|
26 |
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
27 |
+
rev: v0.991
|
28 |
+
hooks:
|
29 |
+
- id: mypy
|
30 |
+
args: ['--ignore-missing-imports']
|
31 |
+
additional_dependencies: ['types-python-slugify']
|
32 |
+
- repo: https://github.com/google/yapf
|
33 |
+
rev: v0.32.0
|
34 |
+
hooks:
|
35 |
+
- id: yapf
|
36 |
+
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
|
.vscode/settings.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"python.linting.enabled": true,
|
3 |
+
"python.linting.flake8Enabled": true,
|
4 |
+
"python.linting.pylintEnabled": false,
|
5 |
+
"python.linting.lintOnSave": true,
|
6 |
+
"python.formatting.provider": "yapf",
|
7 |
+
"python.formatting.yapfArgs": [
|
8 |
+
"--style={based_on_style: pep8, indent_width: 4, blank_line_before_nested_class_or_def: false, spaces_before_comment: 2, split_before_logical_operator: true}"
|
9 |
+
],
|
10 |
+
"[python]": {
|
11 |
+
"editor.formatOnType": true,
|
12 |
+
"editor.codeActionsOnSave": {
|
13 |
+
"source.organizeImports": true
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"editor.formatOnSave": true,
|
17 |
+
"files.insertFinalNewline": true
|
18 |
+
}
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2023 hysts
|
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.
|
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: SD-XL
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.39.0
|
8 |
+
app_file: app.py
|
9 |
+
license: mit
|
10 |
+
pinned: false
|
11 |
+
suggested_hardware: a10g-small
|
12 |
+
duplicated_from: jbilcke-hf/360-server-1
|
13 |
+
---
|
14 |
+
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
import os
|
6 |
+
import random
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import numpy as np
|
10 |
+
import PIL.Image
|
11 |
+
import torch
|
12 |
+
from diffusers import DiffusionPipeline
|
13 |
+
|
14 |
+
DESCRIPTION = '# SD-XL'
|
15 |
+
if not torch.cuda.is_available():
|
16 |
+
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
|
17 |
+
|
18 |
+
MAX_SEED = np.iinfo(np.int32).max
|
19 |
+
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv(
|
20 |
+
'CACHE_EXAMPLES') == '1'
|
21 |
+
MAX_IMAGE_SIZE = int(os.getenv('MAX_IMAGE_SIZE', '1024'))
|
22 |
+
USE_TORCH_COMPILE = os.getenv('USE_TORCH_COMPILE') == '1'
|
23 |
+
ENABLE_CPU_OFFLOAD = os.getenv('ENABLE_CPU_OFFLOAD') == '1'
|
24 |
+
|
25 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
26 |
+
if torch.cuda.is_available():
|
27 |
+
pipe = DiffusionPipeline.from_pretrained(
|
28 |
+
'stabilityai/stable-diffusion-xl-base-1.0',
|
29 |
+
torch_dtype=torch.float16,
|
30 |
+
use_safetensors=True,
|
31 |
+
variant='fp16')
|
32 |
+
refiner = DiffusionPipeline.from_pretrained(
|
33 |
+
'stabilityai/stable-diffusion-xl-refiner-1.0',
|
34 |
+
torch_dtype=torch.float16,
|
35 |
+
use_safetensors=True,
|
36 |
+
variant='fp16')
|
37 |
+
|
38 |
+
# LoRA for 360° images
|
39 |
+
pipe.load_lora_weights('artificialguybr/360Redmond', weight_name='View360.safetensors')
|
40 |
+
|
41 |
+
if ENABLE_CPU_OFFLOAD:
|
42 |
+
pipe.enable_model_cpu_offload()
|
43 |
+
refiner.enable_model_cpu_offload()
|
44 |
+
else:
|
45 |
+
pipe.to(device)
|
46 |
+
refiner.to(device)
|
47 |
+
|
48 |
+
if USE_TORCH_COMPILE:
|
49 |
+
pipe.unet = torch.compile(pipe.unet,
|
50 |
+
mode='reduce-overhead',
|
51 |
+
fullgraph=True)
|
52 |
+
|
53 |
+
else:
|
54 |
+
pipe = None
|
55 |
+
refiner = None
|
56 |
+
|
57 |
+
|
58 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
59 |
+
if randomize_seed:
|
60 |
+
seed = random.randint(0, MAX_SEED)
|
61 |
+
return seed
|
62 |
+
|
63 |
+
|
64 |
+
def generate(prompt: str,
|
65 |
+
negative_prompt: str = '',
|
66 |
+
prompt_2: str = '',
|
67 |
+
negative_prompt_2: str = '',
|
68 |
+
use_negative_prompt: bool = False,
|
69 |
+
use_prompt_2: bool = False,
|
70 |
+
use_negative_prompt_2: bool = False,
|
71 |
+
seed: int = 0,
|
72 |
+
width: int = 1024,
|
73 |
+
height: int = 1024,
|
74 |
+
guidance_scale_base: float = 5.0,
|
75 |
+
guidance_scale_refiner: float = 5.0,
|
76 |
+
num_inference_steps_base: int = 50,
|
77 |
+
num_inference_steps_refiner: int = 50,
|
78 |
+
apply_refiner: bool = False) -> PIL.Image.Image:
|
79 |
+
generator = torch.Generator().manual_seed(seed)
|
80 |
+
|
81 |
+
if not use_negative_prompt:
|
82 |
+
negative_prompt = None # type: ignore
|
83 |
+
if not use_prompt_2:
|
84 |
+
prompt_2 = None # type: ignore
|
85 |
+
if not use_negative_prompt_2:
|
86 |
+
negative_prompt_2 = None # type: ignore
|
87 |
+
|
88 |
+
if not apply_refiner:
|
89 |
+
return pipe(prompt=prompt,
|
90 |
+
negative_prompt=negative_prompt,
|
91 |
+
prompt_2=prompt_2,
|
92 |
+
negative_prompt_2=negative_prompt_2,
|
93 |
+
width=width,
|
94 |
+
height=height,
|
95 |
+
guidance_scale=guidance_scale_base,
|
96 |
+
num_inference_steps=num_inference_steps_base,
|
97 |
+
generator=generator,
|
98 |
+
output_type='pil').images[0]
|
99 |
+
else:
|
100 |
+
latents = pipe(prompt=prompt,
|
101 |
+
negative_prompt=negative_prompt,
|
102 |
+
prompt_2=prompt_2,
|
103 |
+
negative_prompt_2=negative_prompt_2,
|
104 |
+
width=width,
|
105 |
+
height=height,
|
106 |
+
guidance_scale=guidance_scale_base,
|
107 |
+
num_inference_steps=num_inference_steps_base,
|
108 |
+
generator=generator,
|
109 |
+
output_type='latent').images
|
110 |
+
image = refiner(prompt=prompt,
|
111 |
+
negative_prompt=negative_prompt,
|
112 |
+
prompt_2=prompt_2,
|
113 |
+
negative_prompt_2=negative_prompt_2,
|
114 |
+
guidance_scale=guidance_scale_refiner,
|
115 |
+
num_inference_steps=num_inference_steps_refiner,
|
116 |
+
image=latents,
|
117 |
+
generator=generator).images[0]
|
118 |
+
return image
|
119 |
+
|
120 |
+
|
121 |
+
examples = [
|
122 |
+
'Astronaut in a jungle, cold color palette, muted colors, detailed, 8k',
|
123 |
+
'An astronaut riding a green horse',
|
124 |
+
]
|
125 |
+
|
126 |
+
with gr.Blocks(css='style.css') as demo:
|
127 |
+
gr.Markdown(DESCRIPTION)
|
128 |
+
gr.DuplicateButton(value='Duplicate Space for private use',
|
129 |
+
elem_id='duplicate-button',
|
130 |
+
visible=os.getenv('SHOW_DUPLICATE_BUTTON') == '1')
|
131 |
+
with gr.Box():
|
132 |
+
with gr.Row():
|
133 |
+
prompt = gr.Text(
|
134 |
+
label='Prompt',
|
135 |
+
show_label=False,
|
136 |
+
max_lines=1,
|
137 |
+
placeholder='Enter your prompt',
|
138 |
+
container=False,
|
139 |
+
)
|
140 |
+
run_button = gr.Button('Run', scale=0)
|
141 |
+
result = gr.Image(label='Result', show_label=False)
|
142 |
+
with gr.Accordion('Advanced options', open=False):
|
143 |
+
with gr.Row():
|
144 |
+
use_negative_prompt = gr.Checkbox(label='Use negative prompt',
|
145 |
+
value=False)
|
146 |
+
use_prompt_2 = gr.Checkbox(label='Use prompt 2', value=False)
|
147 |
+
use_negative_prompt_2 = gr.Checkbox(
|
148 |
+
label='Use negative prompt 2', value=False)
|
149 |
+
negative_prompt = gr.Text(
|
150 |
+
label='Negative prompt',
|
151 |
+
max_lines=1,
|
152 |
+
placeholder='Enter a negative prompt',
|
153 |
+
visible=False,
|
154 |
+
)
|
155 |
+
prompt_2 = gr.Text(
|
156 |
+
label='Prompt 2',
|
157 |
+
max_lines=1,
|
158 |
+
placeholder='Enter your prompt',
|
159 |
+
visible=False,
|
160 |
+
)
|
161 |
+
negative_prompt_2 = gr.Text(
|
162 |
+
label='Negative prompt 2',
|
163 |
+
max_lines=1,
|
164 |
+
placeholder='Enter a negative prompt',
|
165 |
+
visible=False,
|
166 |
+
)
|
167 |
+
|
168 |
+
seed = gr.Slider(label='Seed',
|
169 |
+
minimum=0,
|
170 |
+
maximum=MAX_SEED,
|
171 |
+
step=1,
|
172 |
+
value=0)
|
173 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=True)
|
174 |
+
with gr.Row():
|
175 |
+
width = gr.Slider(
|
176 |
+
label='Width',
|
177 |
+
minimum=256,
|
178 |
+
maximum=MAX_IMAGE_SIZE,
|
179 |
+
step=32,
|
180 |
+
value=1024,
|
181 |
+
)
|
182 |
+
height = gr.Slider(
|
183 |
+
label='Height',
|
184 |
+
minimum=256,
|
185 |
+
maximum=MAX_IMAGE_SIZE,
|
186 |
+
step=32,
|
187 |
+
value=1024,
|
188 |
+
)
|
189 |
+
apply_refiner = gr.Checkbox(label='Apply refiner', value=False)
|
190 |
+
with gr.Row():
|
191 |
+
guidance_scale_base = gr.Slider(
|
192 |
+
label='Guidance scale for base',
|
193 |
+
minimum=1,
|
194 |
+
maximum=20,
|
195 |
+
step=0.1,
|
196 |
+
value=5.0)
|
197 |
+
num_inference_steps_base = gr.Slider(
|
198 |
+
label='Number of inference steps for base',
|
199 |
+
minimum=10,
|
200 |
+
maximum=100,
|
201 |
+
step=1,
|
202 |
+
value=50)
|
203 |
+
with gr.Row(visible=False) as refiner_params:
|
204 |
+
guidance_scale_refiner = gr.Slider(
|
205 |
+
label='Guidance scale for refiner',
|
206 |
+
minimum=1,
|
207 |
+
maximum=20,
|
208 |
+
step=0.1,
|
209 |
+
value=5.0)
|
210 |
+
num_inference_steps_refiner = gr.Slider(
|
211 |
+
label='Number of inference steps for refiner',
|
212 |
+
minimum=10,
|
213 |
+
maximum=100,
|
214 |
+
step=1,
|
215 |
+
value=50)
|
216 |
+
|
217 |
+
gr.Examples(examples=examples,
|
218 |
+
inputs=prompt,
|
219 |
+
outputs=result,
|
220 |
+
fn=generate,
|
221 |
+
cache_examples=CACHE_EXAMPLES)
|
222 |
+
|
223 |
+
use_negative_prompt.change(
|
224 |
+
fn=lambda x: gr.update(visible=x),
|
225 |
+
inputs=use_negative_prompt,
|
226 |
+
outputs=negative_prompt,
|
227 |
+
queue=False,
|
228 |
+
api_name=False,
|
229 |
+
)
|
230 |
+
use_prompt_2.change(
|
231 |
+
fn=lambda x: gr.update(visible=x),
|
232 |
+
inputs=use_prompt_2,
|
233 |
+
outputs=prompt_2,
|
234 |
+
queue=False,
|
235 |
+
api_name=False,
|
236 |
+
)
|
237 |
+
use_negative_prompt_2.change(
|
238 |
+
fn=lambda x: gr.update(visible=x),
|
239 |
+
inputs=use_negative_prompt_2,
|
240 |
+
outputs=negative_prompt_2,
|
241 |
+
queue=False,
|
242 |
+
api_name=False,
|
243 |
+
)
|
244 |
+
apply_refiner.change(
|
245 |
+
fn=lambda x: gr.update(visible=x),
|
246 |
+
inputs=apply_refiner,
|
247 |
+
outputs=refiner_params,
|
248 |
+
queue=False,
|
249 |
+
api_name=False,
|
250 |
+
)
|
251 |
+
|
252 |
+
inputs = [
|
253 |
+
prompt,
|
254 |
+
negative_prompt,
|
255 |
+
prompt_2,
|
256 |
+
negative_prompt_2,
|
257 |
+
use_negative_prompt,
|
258 |
+
use_prompt_2,
|
259 |
+
use_negative_prompt_2,
|
260 |
+
seed,
|
261 |
+
width,
|
262 |
+
height,
|
263 |
+
guidance_scale_base,
|
264 |
+
guidance_scale_refiner,
|
265 |
+
num_inference_steps_base,
|
266 |
+
num_inference_steps_refiner,
|
267 |
+
apply_refiner,
|
268 |
+
]
|
269 |
+
prompt.submit(
|
270 |
+
fn=randomize_seed_fn,
|
271 |
+
inputs=[seed, randomize_seed],
|
272 |
+
outputs=seed,
|
273 |
+
queue=False,
|
274 |
+
api_name=False,
|
275 |
+
).then(
|
276 |
+
fn=generate,
|
277 |
+
inputs=inputs,
|
278 |
+
outputs=result,
|
279 |
+
api_name='run',
|
280 |
+
)
|
281 |
+
negative_prompt.submit(
|
282 |
+
fn=randomize_seed_fn,
|
283 |
+
inputs=[seed, randomize_seed],
|
284 |
+
outputs=seed,
|
285 |
+
queue=False,
|
286 |
+
api_name=False,
|
287 |
+
).then(
|
288 |
+
fn=generate,
|
289 |
+
inputs=inputs,
|
290 |
+
outputs=result,
|
291 |
+
api_name=False,
|
292 |
+
)
|
293 |
+
run_button.click(
|
294 |
+
fn=randomize_seed_fn,
|
295 |
+
inputs=[seed, randomize_seed],
|
296 |
+
outputs=seed,
|
297 |
+
queue=False,
|
298 |
+
api_name=False,
|
299 |
+
).then(
|
300 |
+
fn=generate,
|
301 |
+
inputs=inputs,
|
302 |
+
outputs=result,
|
303 |
+
api_name=False,
|
304 |
+
)
|
305 |
+
demo.queue(max_size=20).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate==0.21.0
|
2 |
+
diffusers @ git+https://github.com/huggingface/diffusers@fix/text-encoder-sdxl-lora
|
3 |
+
gradio==3.39.0
|
4 |
+
invisible-watermark==0.2.0
|
5 |
+
Pillow==10.0.0
|
6 |
+
torch==2.0.1
|
7 |
+
transformers==4.31.0
|
style.css
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
}
|
4 |
+
|
5 |
+
#duplicate-button {
|
6 |
+
margin: auto;
|
7 |
+
color: #fff;
|
8 |
+
background: #1565c0;
|
9 |
+
border-radius: 100vh;
|
10 |
+
}
|
11 |
+
|
12 |
+
#component-0 {
|
13 |
+
max-width: 730px;
|
14 |
+
margin: auto;
|
15 |
+
padding-top: 1.5rem;
|
16 |
+
}
|