Spaces:
Runtime error
Runtime error
initial commit
Browse files- .gitignore +162 -0
- .pre-commit-config.yaml +36 -0
- .style.yapf +5 -0
- .vscode/settings.json +18 -0
- LICENSE +21 -0
- README.md +9 -5
- app.py +328 -0
- requirements.txt +7 -0
- style.css +25 -0
.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
CHANGED
@@ -1,13 +1,17 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.39.0
|
8 |
app_file: app.py
|
9 |
-
pinned: false
|
10 |
license: mit
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
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: hysts/SD-XL
|
13 |
---
|
14 |
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
16 |
+
|
17 |
+
https://arxiv.org/abs/2307.01952
|
app.py
ADDED
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.models import AutoencoderKL
|
13 |
+
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
14 |
+
|
15 |
+
DESCRIPTION = '# Animagine XL'
|
16 |
+
if not torch.cuda.is_available():
|
17 |
+
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'
|
18 |
+
|
19 |
+
MAX_SEED = np.iinfo(np.int32).max
|
20 |
+
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv(
|
21 |
+
'CACHE_EXAMPLES') == '1'
|
22 |
+
USE_TORCH_COMPILE = os.getenv('USE_TORCH_COMPILE') == '1'
|
23 |
+
ENABLE_CPU_OFFLOAD = os.getenv('ENABLE_CPU_OFFLOAD') == '1'
|
24 |
+
|
25 |
+
MODEL = "Linaqruf/animagine-xl"
|
26 |
+
|
27 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
28 |
+
if torch.cuda.is_available():
|
29 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
30 |
+
MODEL,
|
31 |
+
torch_dtype=torch.float16,
|
32 |
+
use_safetensors=True,
|
33 |
+
variant='fp16')
|
34 |
+
|
35 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
36 |
+
|
37 |
+
if ENABLE_CPU_OFFLOAD:
|
38 |
+
pipe.enable_model_cpu_offload()
|
39 |
+
else:
|
40 |
+
pipe.to(device)
|
41 |
+
|
42 |
+
if USE_TORCH_COMPILE:
|
43 |
+
pipe.unet = torch.compile(pipe.unet,
|
44 |
+
mode='reduce-overhead',
|
45 |
+
fullgraph=True)
|
46 |
+
else:
|
47 |
+
pipe = None
|
48 |
+
|
49 |
+
|
50 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
51 |
+
if randomize_seed:
|
52 |
+
seed = random.randint(0, MAX_SEED)
|
53 |
+
return seed
|
54 |
+
|
55 |
+
|
56 |
+
def generate(prompt: str,
|
57 |
+
negative_prompt: str = '',
|
58 |
+
prompt_2: str = '',
|
59 |
+
negative_prompt_2: str = '',
|
60 |
+
use_prompt_2: bool = False,
|
61 |
+
seed: int = 0,
|
62 |
+
width: int = 1024,
|
63 |
+
height: int = 1024,
|
64 |
+
target_width: int = 1024,
|
65 |
+
target_height: int = 1024,
|
66 |
+
original_width: int = 4096,
|
67 |
+
original_height: int = 4096,
|
68 |
+
guidance_scale_base: float = 12.0,
|
69 |
+
num_inference_steps_base: int = 50) -> PIL.Image.Image:
|
70 |
+
|
71 |
+
generator = torch.Generator().manual_seed(seed)
|
72 |
+
|
73 |
+
if negative_prompt == '':
|
74 |
+
negative_prompt = None # type: ignore
|
75 |
+
if not use_prompt_2:
|
76 |
+
prompt_2 = None # type: ignore
|
77 |
+
negative_prompt_2 = None # type: ignore
|
78 |
+
if negative_prompt_2 == '':
|
79 |
+
negative_prompt_2 = None
|
80 |
+
|
81 |
+
return pipe(prompt=prompt,
|
82 |
+
negative_prompt=negative_prompt,
|
83 |
+
prompt_2=prompt_2,
|
84 |
+
negative_prompt_2=negative_prompt_2,
|
85 |
+
width=width,
|
86 |
+
height=height,
|
87 |
+
target_size=(target_width, target_height),
|
88 |
+
original_size=(original_width, original_height),
|
89 |
+
guidance_scale=guidance_scale_base,
|
90 |
+
num_inference_steps=num_inference_steps_base,
|
91 |
+
generator=generator,
|
92 |
+
output_type='pil').images[0]
|
93 |
+
|
94 |
+
|
95 |
+
examples = [
|
96 |
+
'face focus, cute, masterpiece, best quality, 1girl, green hair, sweater, looking at viewer, upper body, beanie, outdoors, night, turtleneck',
|
97 |
+
'face focus, bishounen, masterpiece, best quality, 1boy, green hair, sweater, looking at viewer, upper body, beanie, outdoors, night, turtleneck',
|
98 |
+
]
|
99 |
+
|
100 |
+
# choices = [
|
101 |
+
# "Vertical (9:16)",
|
102 |
+
# "Portrait (4:5)",
|
103 |
+
# "Square (1:1)",
|
104 |
+
# "Photo (4:3)",
|
105 |
+
# "Landscape (3:2)",
|
106 |
+
# "Widescreen (16:9)",
|
107 |
+
# "Cinematic (21:9)",
|
108 |
+
# ]
|
109 |
+
|
110 |
+
# choice_to_size = {
|
111 |
+
# "Vertical (9:16)": (768, 1344),
|
112 |
+
# "Portrait (4:5)": (912, 1144),
|
113 |
+
# "Square (1:1)": (1024, 1024),
|
114 |
+
# "Photo (4:3)": (1184, 888),
|
115 |
+
# "Landscape (3:2)": (1256, 832),
|
116 |
+
# "Widescreen (16:9)": (1368, 768),
|
117 |
+
# "Cinematic (21:9)": (1568, 672),
|
118 |
+
# }
|
119 |
+
|
120 |
+
with gr.Blocks(css='style.css') as demo:
|
121 |
+
gr.Markdown(DESCRIPTION)
|
122 |
+
gr.DuplicateButton(value='Duplicate Space for private use',
|
123 |
+
elem_id='duplicate-button',
|
124 |
+
visible=os.getenv('SHOW_DUPLICATE_BUTTON') == '1')
|
125 |
+
with gr.Row():
|
126 |
+
with gr.Column(scale=1):
|
127 |
+
prompt = gr.Text(
|
128 |
+
label='Prompt',
|
129 |
+
max_lines=1,
|
130 |
+
placeholder='Enter your prompt',
|
131 |
+
)
|
132 |
+
negative_prompt = gr.Text(
|
133 |
+
label='Negative Prompt',
|
134 |
+
max_lines=1,
|
135 |
+
placeholder='Enter a negative prompt',
|
136 |
+
value='lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry',
|
137 |
+
)
|
138 |
+
use_prompt_2 = gr.Checkbox(
|
139 |
+
label='Use prompt 2',
|
140 |
+
value=False
|
141 |
+
)
|
142 |
+
prompt_2 = gr.Text(
|
143 |
+
label='Prompt 2',
|
144 |
+
max_lines=1,
|
145 |
+
placeholder='Enter your prompt',
|
146 |
+
visible=False,
|
147 |
+
)
|
148 |
+
negative_prompt_2 = gr.Text(
|
149 |
+
label='Negative prompt 2',
|
150 |
+
max_lines=1,
|
151 |
+
placeholder='Enter a negative prompt',
|
152 |
+
visible=False,
|
153 |
+
)
|
154 |
+
|
155 |
+
# with gr.Row():
|
156 |
+
# aspect_ratio = gr.Dropdown(choices=choices, label="Aspect Ratio Preset", value=choices[2])
|
157 |
+
with gr.Row():
|
158 |
+
width = gr.Slider(
|
159 |
+
label='Width',
|
160 |
+
minimum=256,
|
161 |
+
maximum=4096,
|
162 |
+
step=32,
|
163 |
+
value=1024,
|
164 |
+
)
|
165 |
+
height = gr.Slider(
|
166 |
+
label='Height',
|
167 |
+
minimum=256,
|
168 |
+
maximum=4096,
|
169 |
+
step=32,
|
170 |
+
value=1024,
|
171 |
+
)
|
172 |
+
with gr.Accordion(label='Advanced Config', open=False):
|
173 |
+
with gr.Accordion(label='Conditioning Resolution', open=False):
|
174 |
+
with gr.Row():
|
175 |
+
original_width = gr.Slider(
|
176 |
+
label='Original Width',
|
177 |
+
minimum=1024,
|
178 |
+
maximum=4096,
|
179 |
+
step=32,
|
180 |
+
value=4096,
|
181 |
+
)
|
182 |
+
original_height = gr.Slider(
|
183 |
+
label='Original Height',
|
184 |
+
minimum=1024,
|
185 |
+
maximum=4096,
|
186 |
+
step=32,
|
187 |
+
value=4096,
|
188 |
+
)
|
189 |
+
with gr.Row():
|
190 |
+
target_width = gr.Slider(
|
191 |
+
label='Target Width',
|
192 |
+
minimum=1024,
|
193 |
+
maximum=4096,
|
194 |
+
step=32,
|
195 |
+
value=1024,
|
196 |
+
)
|
197 |
+
target_height = gr.Slider(
|
198 |
+
label='Target Height',
|
199 |
+
minimum=1024,
|
200 |
+
maximum=4096,
|
201 |
+
step=32,
|
202 |
+
value=1024,
|
203 |
+
)
|
204 |
+
seed = gr.Slider(label='Seed',
|
205 |
+
minimum=0,
|
206 |
+
maximum=MAX_SEED,
|
207 |
+
step=1,
|
208 |
+
value=0)
|
209 |
+
|
210 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=True)
|
211 |
+
with gr.Row():
|
212 |
+
guidance_scale_base = gr.Slider(
|
213 |
+
label='Guidance scale',
|
214 |
+
minimum=1,
|
215 |
+
maximum=20,
|
216 |
+
step=0.1,
|
217 |
+
value=12.0)
|
218 |
+
num_inference_steps_base = gr.Slider(
|
219 |
+
label='Number of inference steps',
|
220 |
+
minimum=10,
|
221 |
+
maximum=100,
|
222 |
+
step=1,
|
223 |
+
value=50)
|
224 |
+
|
225 |
+
with gr.Column(scale=2):
|
226 |
+
with gr.Blocks():
|
227 |
+
run_button = gr.Button('Generate')
|
228 |
+
result = gr.Image(label='Result', show_label=False)
|
229 |
+
|
230 |
+
gr.Examples(examples=examples,
|
231 |
+
inputs=prompt,
|
232 |
+
outputs=result,
|
233 |
+
fn=generate,
|
234 |
+
cache_examples=CACHE_EXAMPLES)
|
235 |
+
|
236 |
+
use_prompt_2.change(
|
237 |
+
fn=lambda x: gr.update(visible=x),
|
238 |
+
inputs=use_prompt_2,
|
239 |
+
outputs=prompt_2,
|
240 |
+
queue=False,
|
241 |
+
api_name=False,
|
242 |
+
)
|
243 |
+
use_prompt_2.change(
|
244 |
+
fn=lambda x: gr.update(visible=x),
|
245 |
+
inputs=use_prompt_2,
|
246 |
+
outputs=negative_prompt_2,
|
247 |
+
queue=False,
|
248 |
+
api_name=False,
|
249 |
+
)
|
250 |
+
|
251 |
+
inputs = [
|
252 |
+
prompt,
|
253 |
+
negative_prompt,
|
254 |
+
prompt_2,
|
255 |
+
negative_prompt_2,
|
256 |
+
use_prompt_2,
|
257 |
+
seed,
|
258 |
+
width,
|
259 |
+
height,
|
260 |
+
target_width,
|
261 |
+
target_height,
|
262 |
+
original_width,
|
263 |
+
original_height,
|
264 |
+
guidance_scale_base,
|
265 |
+
num_inference_steps_base,
|
266 |
+
]
|
267 |
+
prompt.submit(
|
268 |
+
fn=randomize_seed_fn,
|
269 |
+
inputs=[seed, randomize_seed],
|
270 |
+
outputs=seed,
|
271 |
+
queue=False,
|
272 |
+
api_name=False,
|
273 |
+
).then(
|
274 |
+
fn=generate,
|
275 |
+
inputs=inputs,
|
276 |
+
outputs=result,
|
277 |
+
api_name='run',
|
278 |
+
)
|
279 |
+
negative_prompt.submit(
|
280 |
+
fn=randomize_seed_fn,
|
281 |
+
inputs=[seed, randomize_seed],
|
282 |
+
outputs=seed,
|
283 |
+
queue=False,
|
284 |
+
api_name=False,
|
285 |
+
).then(
|
286 |
+
fn=generate,
|
287 |
+
inputs=inputs,
|
288 |
+
outputs=result,
|
289 |
+
api_name=False,
|
290 |
+
)
|
291 |
+
prompt_2.submit(
|
292 |
+
fn=randomize_seed_fn,
|
293 |
+
inputs=[seed, randomize_seed],
|
294 |
+
outputs=seed,
|
295 |
+
queue=False,
|
296 |
+
api_name=False,
|
297 |
+
).then(
|
298 |
+
fn=generate,
|
299 |
+
inputs=inputs,
|
300 |
+
outputs=result,
|
301 |
+
api_name=False,
|
302 |
+
)
|
303 |
+
negative_prompt_2.submit(
|
304 |
+
fn=randomize_seed_fn,
|
305 |
+
inputs=[seed, randomize_seed],
|
306 |
+
outputs=seed,
|
307 |
+
queue=False,
|
308 |
+
api_name=False,
|
309 |
+
).then(
|
310 |
+
fn=generate,
|
311 |
+
inputs=inputs,
|
312 |
+
outputs=result,
|
313 |
+
api_name=False,
|
314 |
+
)
|
315 |
+
run_button.click(
|
316 |
+
fn=randomize_seed_fn,
|
317 |
+
inputs=[seed, randomize_seed],
|
318 |
+
outputs=seed,
|
319 |
+
queue=False,
|
320 |
+
api_name=False,
|
321 |
+
).then(
|
322 |
+
fn=generate,
|
323 |
+
inputs=inputs,
|
324 |
+
outputs=result,
|
325 |
+
api_name=False,
|
326 |
+
)
|
327 |
+
|
328 |
+
demo.queue(max_size=20).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate==0.21.0
|
2 |
+
diffusers==0.19.0
|
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,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
h1 {
|
2 |
+
text-align: center;
|
3 |
+
font-size: 10vw; /* relative to the viewport width */
|
4 |
+
}
|
5 |
+
|
6 |
+
#duplicate-button {
|
7 |
+
margin: auto;
|
8 |
+
color: #fff;
|
9 |
+
background: #1565c0;
|
10 |
+
border-radius: 100vh;
|
11 |
+
}
|
12 |
+
|
13 |
+
#component-0 {
|
14 |
+
max-width: 80%; /* relative to the parent element's width */
|
15 |
+
margin: auto;
|
16 |
+
padding-top: 1.5rem;
|
17 |
+
}
|
18 |
+
|
19 |
+
/* You can also use media queries to adjust your style for different screen sizes */
|
20 |
+
@media (max-width: 600px) {
|
21 |
+
#component-0 {
|
22 |
+
max-width: 90%;
|
23 |
+
padding-top: 1rem;
|
24 |
+
}
|
25 |
+
}
|