Spaces:
Running
on
Zero
Running
on
Zero
adamelliotfields
commited on
Commit
•
23f4f95
1
Parent(s):
d618523
Embeddings multiselect
Browse files- app.css +1 -1
- app.py +61 -57
- cli.py +15 -14
- config.py +0 -57
- lib/__init__.py +3 -0
- lib/config.py +51 -0
- lib/inference.py +19 -0
- lib/loader.py +0 -12
- usage.md +16 -20
app.css
CHANGED
@@ -105,7 +105,7 @@
|
|
105 |
border-width: 0px;
|
106 |
}
|
107 |
.tabitem {
|
108 |
-
max-height:
|
109 |
overflow-x: hidden;
|
110 |
overflow-y: auto;
|
111 |
padding: 0 0 8px;
|
|
|
105 |
border-width: 0px;
|
106 |
}
|
107 |
.tabitem {
|
108 |
+
max-height: 698px;
|
109 |
overflow-x: hidden;
|
110 |
overflow-y: auto;
|
111 |
padding: 0 0 8px;
|
app.py
CHANGED
@@ -4,8 +4,7 @@ import random
|
|
4 |
|
5 |
import gradio as gr
|
6 |
|
7 |
-
import
|
8 |
-
from lib import generate
|
9 |
|
10 |
# the CSS `content` attribute expects a string so we need to wrap the number in quotes
|
11 |
refresh_seed_js = """
|
@@ -73,8 +72,8 @@ with gr.Blocks(
|
|
73 |
radius_size=gr.themes.sizes.radius_sm,
|
74 |
spacing_size=gr.themes.sizes.spacing_md,
|
75 |
# fonts
|
76 |
-
font=[gr.themes.GoogleFont("Inter"), *
|
77 |
-
font_mono=[gr.themes.GoogleFont("Ubuntu Mono"), *
|
78 |
).set(
|
79 |
layout_gap="8px",
|
80 |
block_shadow="0 0 #0000",
|
@@ -95,51 +94,59 @@ with gr.Blocks(
|
|
95 |
with gr.TabItem("⚙️ Settings"):
|
96 |
with gr.Group():
|
97 |
negative_prompt = gr.Textbox(
|
98 |
-
value=
|
99 |
label="Negative Prompt",
|
100 |
placeholder="ugly, bad",
|
101 |
lines=2,
|
102 |
)
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
with gr.Row():
|
111 |
styles = json.loads(read_file("data/styles.json"))
|
112 |
style = gr.Dropdown(
|
113 |
-
value=
|
114 |
label="Style",
|
115 |
min_width=200,
|
116 |
choices=[("None", None)] + [(s["name"], s["id"]) for s in styles],
|
117 |
)
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
filterable=False,
|
124 |
)
|
125 |
|
126 |
with gr.Row():
|
127 |
guidance_scale = gr.Slider(
|
128 |
-
value=
|
129 |
label="Guidance Scale",
|
130 |
minimum=1.0,
|
131 |
maximum=15.0,
|
132 |
step=0.1,
|
133 |
)
|
134 |
inference_steps = gr.Slider(
|
135 |
-
value=
|
136 |
label="Inference Steps",
|
137 |
minimum=1,
|
138 |
maximum=50,
|
139 |
step=1,
|
140 |
)
|
141 |
seed = gr.Number(
|
142 |
-
value=
|
143 |
label="Seed",
|
144 |
minimum=-1,
|
145 |
maximum=(2**64) - 1,
|
@@ -147,14 +154,14 @@ with gr.Blocks(
|
|
147 |
|
148 |
with gr.Row():
|
149 |
width = gr.Slider(
|
150 |
-
value=
|
151 |
label="Width",
|
152 |
minimum=320,
|
153 |
maximum=768,
|
154 |
step=16,
|
155 |
)
|
156 |
height = gr.Slider(
|
157 |
-
value=
|
158 |
label="Height",
|
159 |
minimum=320,
|
160 |
maximum=768,
|
@@ -175,45 +182,19 @@ with gr.Blocks(
|
|
175 |
min_width=180,
|
176 |
)
|
177 |
scale = gr.Dropdown(
|
178 |
-
choices=[(f"{s}x", s) for s in
|
179 |
filterable=False,
|
180 |
-
value=
|
181 |
label="Scale",
|
182 |
-
min_width=100,
|
183 |
)
|
|
|
|
|
184 |
num_images = gr.Dropdown(
|
185 |
choices=list(range(1, 5)),
|
186 |
-
value=
|
187 |
filterable=False,
|
188 |
label="Images",
|
189 |
-
min_width=60,
|
190 |
)
|
191 |
-
|
192 |
-
with gr.Row():
|
193 |
-
use_karras = gr.Checkbox(
|
194 |
-
elem_classes=["checkbox"],
|
195 |
-
label="Karras σ",
|
196 |
-
value=True,
|
197 |
-
)
|
198 |
-
use_freeu = gr.Checkbox(
|
199 |
-
elem_classes=["checkbox"],
|
200 |
-
label="FreeU",
|
201 |
-
value=False,
|
202 |
-
)
|
203 |
-
use_clip_skip = gr.Checkbox(
|
204 |
-
elem_classes=["checkbox"],
|
205 |
-
label="Clip skip",
|
206 |
-
value=False,
|
207 |
-
)
|
208 |
-
increment_seed = gr.Checkbox(
|
209 |
-
elem_classes=["checkbox"],
|
210 |
-
label="Autoincrement",
|
211 |
-
value=True,
|
212 |
-
)
|
213 |
-
|
214 |
-
with gr.TabItem("🛠️ Advanced"):
|
215 |
-
with gr.Group():
|
216 |
-
with gr.Row():
|
217 |
file_format = gr.Dropdown(
|
218 |
choices=["png", "jpeg", "webp"],
|
219 |
label="File Format",
|
@@ -221,14 +202,14 @@ with gr.Blocks(
|
|
221 |
value="png",
|
222 |
)
|
223 |
deepcache_interval = gr.Slider(
|
224 |
-
value=
|
225 |
-
label="DeepCache
|
226 |
minimum=1,
|
227 |
maximum=4,
|
228 |
step=1,
|
229 |
)
|
230 |
tome_ratio = gr.Slider(
|
231 |
-
value=
|
232 |
label="ToMe Ratio",
|
233 |
minimum=0.0,
|
234 |
maximum=0.5,
|
@@ -236,6 +217,28 @@ with gr.Blocks(
|
|
236 |
)
|
237 |
|
238 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
use_taesd = gr.Checkbox(
|
240 |
elem_classes=["checkbox"],
|
241 |
label="Tiny VAE",
|
@@ -333,6 +336,7 @@ with gr.Blocks(
|
|
333 |
inputs=[
|
334 |
prompt,
|
335 |
negative_prompt,
|
|
|
336 |
style,
|
337 |
seed,
|
338 |
model,
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
|
7 |
+
from lib import Config, generate
|
|
|
8 |
|
9 |
# the CSS `content` attribute expects a string so we need to wrap the number in quotes
|
10 |
refresh_seed_js = """
|
|
|
72 |
radius_size=gr.themes.sizes.radius_sm,
|
73 |
spacing_size=gr.themes.sizes.spacing_md,
|
74 |
# fonts
|
75 |
+
font=[gr.themes.GoogleFont("Inter"), *Config.SANS_FONTS],
|
76 |
+
font_mono=[gr.themes.GoogleFont("Ubuntu Mono"), *Config.MONO_FONTS],
|
77 |
).set(
|
78 |
layout_gap="8px",
|
79 |
block_shadow="0 0 #0000",
|
|
|
94 |
with gr.TabItem("⚙️ Settings"):
|
95 |
with gr.Group():
|
96 |
negative_prompt = gr.Textbox(
|
97 |
+
value=None,
|
98 |
label="Negative Prompt",
|
99 |
placeholder="ugly, bad",
|
100 |
lines=2,
|
101 |
)
|
102 |
+
|
103 |
+
with gr.Row():
|
104 |
+
model = gr.Dropdown(
|
105 |
+
choices=Config.MODELS,
|
106 |
+
filterable=False,
|
107 |
+
value=Config.MODEL,
|
108 |
+
label="Model",
|
109 |
+
)
|
110 |
+
scheduler = gr.Dropdown(
|
111 |
+
choices=Config.SCHEDULERS,
|
112 |
+
value=Config.SCHEDULER,
|
113 |
+
elem_id="scheduler",
|
114 |
+
label="Scheduler",
|
115 |
+
filterable=False,
|
116 |
+
)
|
117 |
|
118 |
with gr.Row():
|
119 |
styles = json.loads(read_file("data/styles.json"))
|
120 |
style = gr.Dropdown(
|
121 |
+
value=Config.STYLE,
|
122 |
label="Style",
|
123 |
min_width=200,
|
124 |
choices=[("None", None)] + [(s["name"], s["id"]) for s in styles],
|
125 |
)
|
126 |
+
embeddings = gr.Dropdown(
|
127 |
+
label="Embeddings",
|
128 |
+
choices=[(f"<{e}>", e) for e in Config.EMBEDDINGS],
|
129 |
+
multiselect=True,
|
130 |
+
value=[Config.EMBEDDING],
|
|
|
131 |
)
|
132 |
|
133 |
with gr.Row():
|
134 |
guidance_scale = gr.Slider(
|
135 |
+
value=Config.GUIDANCE_SCALE,
|
136 |
label="Guidance Scale",
|
137 |
minimum=1.0,
|
138 |
maximum=15.0,
|
139 |
step=0.1,
|
140 |
)
|
141 |
inference_steps = gr.Slider(
|
142 |
+
value=Config.INFERENCE_STEPS,
|
143 |
label="Inference Steps",
|
144 |
minimum=1,
|
145 |
maximum=50,
|
146 |
step=1,
|
147 |
)
|
148 |
seed = gr.Number(
|
149 |
+
value=Config.SEED,
|
150 |
label="Seed",
|
151 |
minimum=-1,
|
152 |
maximum=(2**64) - 1,
|
|
|
154 |
|
155 |
with gr.Row():
|
156 |
width = gr.Slider(
|
157 |
+
value=Config.WIDTH,
|
158 |
label="Width",
|
159 |
minimum=320,
|
160 |
maximum=768,
|
161 |
step=16,
|
162 |
)
|
163 |
height = gr.Slider(
|
164 |
+
value=Config.HEIGHT,
|
165 |
label="Height",
|
166 |
minimum=320,
|
167 |
maximum=768,
|
|
|
182 |
min_width=180,
|
183 |
)
|
184 |
scale = gr.Dropdown(
|
185 |
+
choices=[(f"{s}x", s) for s in Config.SCALES],
|
186 |
filterable=False,
|
187 |
+
value=Config.SCALE,
|
188 |
label="Scale",
|
|
|
189 |
)
|
190 |
+
|
191 |
+
with gr.Row():
|
192 |
num_images = gr.Dropdown(
|
193 |
choices=list(range(1, 5)),
|
194 |
+
value=Config.NUM_IMAGES,
|
195 |
filterable=False,
|
196 |
label="Images",
|
|
|
197 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
file_format = gr.Dropdown(
|
199 |
choices=["png", "jpeg", "webp"],
|
200 |
label="File Format",
|
|
|
202 |
value="png",
|
203 |
)
|
204 |
deepcache_interval = gr.Slider(
|
205 |
+
value=Config.DEEPCACHE_INTERVAL,
|
206 |
+
label="DeepCache",
|
207 |
minimum=1,
|
208 |
maximum=4,
|
209 |
step=1,
|
210 |
)
|
211 |
tome_ratio = gr.Slider(
|
212 |
+
value=Config.TOME_RATIO,
|
213 |
label="ToMe Ratio",
|
214 |
minimum=0.0,
|
215 |
maximum=0.5,
|
|
|
217 |
)
|
218 |
|
219 |
with gr.Row():
|
220 |
+
increment_seed = gr.Checkbox(
|
221 |
+
elem_classes=["checkbox"],
|
222 |
+
label="Autoincrement",
|
223 |
+
value=True,
|
224 |
+
)
|
225 |
+
use_freeu = gr.Checkbox(
|
226 |
+
elem_classes=["checkbox"],
|
227 |
+
label="FreeU",
|
228 |
+
value=False,
|
229 |
+
)
|
230 |
+
use_clip_skip = gr.Checkbox(
|
231 |
+
elem_classes=["checkbox"],
|
232 |
+
label="Clip skip",
|
233 |
+
value=False,
|
234 |
+
)
|
235 |
+
|
236 |
+
with gr.Row():
|
237 |
+
use_karras = gr.Checkbox(
|
238 |
+
elem_classes=["checkbox"],
|
239 |
+
label="Karras σ",
|
240 |
+
value=True,
|
241 |
+
)
|
242 |
use_taesd = gr.Checkbox(
|
243 |
elem_classes=["checkbox"],
|
244 |
label="Tiny VAE",
|
|
|
336 |
inputs=[
|
337 |
prompt,
|
338 |
negative_prompt,
|
339 |
+
embeddings,
|
340 |
style,
|
341 |
seed,
|
342 |
model,
|
cli.py
CHANGED
@@ -2,8 +2,7 @@
|
|
2 |
# usage: python cli.py 'colorful calico cat artstation'
|
3 |
import argparse
|
4 |
|
5 |
-
import
|
6 |
-
from lib import generate
|
7 |
|
8 |
|
9 |
def save_images(images, filename="image.png"):
|
@@ -16,20 +15,21 @@ def main():
|
|
16 |
# fmt: off
|
17 |
parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
|
18 |
parser.add_argument("prompt", type=str, metavar="PROMPT")
|
19 |
-
parser.add_argument("-n", "--negative", type=str, metavar="STR", default=
|
20 |
-
parser.add_argument("-
|
|
|
21 |
parser.add_argument("-i", "--images", type=int, metavar="INT", default=1)
|
22 |
parser.add_argument("-f", "--filename", type=str, metavar="STR", default="image.png")
|
23 |
-
parser.add_argument("-w", "--width", type=int, metavar="INT", default=
|
24 |
-
parser.add_argument("-h", "--height", type=int, metavar="INT", default=
|
25 |
-
parser.add_argument("-m", "--model", type=str, metavar="STR", default=
|
26 |
-
parser.add_argument("-d", "--deepcache", type=int, metavar="INT", default=
|
27 |
-
parser.add_argument("--scale", type=int, metavar="INT", choices=
|
28 |
-
parser.add_argument("--style", type=str, metavar="STR", default=
|
29 |
-
parser.add_argument("--scheduler", type=str, metavar="STR", default=
|
30 |
-
parser.add_argument("--guidance", type=float, metavar="FLOAT", default=
|
31 |
-
parser.add_argument("--steps", type=int, metavar="INT", default=
|
32 |
-
parser.add_argument("--tome", type=float, metavar="FLOAT", default=
|
33 |
parser.add_argument("--taesd", action="store_true")
|
34 |
parser.add_argument("--clip-skip", action="store_true")
|
35 |
parser.add_argument("--truncate", action="store_true")
|
@@ -42,6 +42,7 @@ def main():
|
|
42 |
images = generate(
|
43 |
args.prompt,
|
44 |
args.negative,
|
|
|
45 |
args.style,
|
46 |
args.seed,
|
47 |
args.model,
|
|
|
2 |
# usage: python cli.py 'colorful calico cat artstation'
|
3 |
import argparse
|
4 |
|
5 |
+
from lib import Config, generate
|
|
|
6 |
|
7 |
|
8 |
def save_images(images, filename="image.png"):
|
|
|
15 |
# fmt: off
|
16 |
parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
|
17 |
parser.add_argument("prompt", type=str, metavar="PROMPT")
|
18 |
+
parser.add_argument("-n", "--negative", type=str, metavar="STR", default="")
|
19 |
+
parser.add_argument("-e", "--embedding", type=str, metavar="STR", default=[], action="append")
|
20 |
+
parser.add_argument("-s", "--seed", type=int, metavar="INT", default=Config.SEED)
|
21 |
parser.add_argument("-i", "--images", type=int, metavar="INT", default=1)
|
22 |
parser.add_argument("-f", "--filename", type=str, metavar="STR", default="image.png")
|
23 |
+
parser.add_argument("-w", "--width", type=int, metavar="INT", default=Config.WIDTH)
|
24 |
+
parser.add_argument("-h", "--height", type=int, metavar="INT", default=Config.HEIGHT)
|
25 |
+
parser.add_argument("-m", "--model", type=str, metavar="STR", default=Config.MODEL)
|
26 |
+
parser.add_argument("-d", "--deepcache", type=int, metavar="INT", default=Config.DEEPCACHE_INTERVAL)
|
27 |
+
parser.add_argument("--scale", type=int, metavar="INT", choices=Config.SCALES, default=Config.SCALE)
|
28 |
+
parser.add_argument("--style", type=str, metavar="STR", default=Config.STYLE)
|
29 |
+
parser.add_argument("--scheduler", type=str, metavar="STR", default=Config.SCHEDULER)
|
30 |
+
parser.add_argument("--guidance", type=float, metavar="FLOAT", default=Config.GUIDANCE_SCALE)
|
31 |
+
parser.add_argument("--steps", type=int, metavar="INT", default=Config.INFERENCE_STEPS)
|
32 |
+
parser.add_argument("--tome", type=float, metavar="FLOAT", default=Config.TOME_RATIO)
|
33 |
parser.add_argument("--taesd", action="store_true")
|
34 |
parser.add_argument("--clip-skip", action="store_true")
|
35 |
parser.add_argument("--truncate", action="store_true")
|
|
|
42 |
images = generate(
|
43 |
args.prompt,
|
44 |
args.negative,
|
45 |
+
args.embedding,
|
46 |
args.style,
|
47 |
args.seed,
|
48 |
args.model,
|
config.py
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
MONO_FONTS = ["monospace"]
|
2 |
-
|
3 |
-
SANS_FONTS = [
|
4 |
-
"sans-serif",
|
5 |
-
"Apple Color Emoji",
|
6 |
-
"Segoe UI Emoji",
|
7 |
-
"Segoe UI Symbol",
|
8 |
-
"Noto Color Emoji",
|
9 |
-
]
|
10 |
-
|
11 |
-
# embeddings loaded and renamed in generate.py
|
12 |
-
NEGATIVE_PROMPT = "<fast_negative>"
|
13 |
-
|
14 |
-
MODEL = "Lykon/dreamshaper-8"
|
15 |
-
|
16 |
-
MODELS = [
|
17 |
-
"fluently/Fluently-v4",
|
18 |
-
"Linaqruf/anything-v3-1",
|
19 |
-
"Lykon/dreamshaper-8",
|
20 |
-
"prompthero/openjourney-v4",
|
21 |
-
"runwayml/stable-diffusion-v1-5",
|
22 |
-
"SG161222/Realistic_Vision_V5.1_Novae",
|
23 |
-
]
|
24 |
-
|
25 |
-
SCHEDULER = "DEIS 2M"
|
26 |
-
|
27 |
-
SCHEDULERS = [
|
28 |
-
"DEIS 2M",
|
29 |
-
"DPM++ 2M",
|
30 |
-
"DPM2 a",
|
31 |
-
"Euler a",
|
32 |
-
"Heun",
|
33 |
-
"LMS",
|
34 |
-
"PNDM",
|
35 |
-
]
|
36 |
-
|
37 |
-
STYLE = "sai-enhance"
|
38 |
-
|
39 |
-
WIDTH = 448
|
40 |
-
|
41 |
-
HEIGHT = 576
|
42 |
-
|
43 |
-
NUM_IMAGES = 4
|
44 |
-
|
45 |
-
SEED = -1
|
46 |
-
|
47 |
-
GUIDANCE_SCALE = 7
|
48 |
-
|
49 |
-
INFERENCE_STEPS = 30
|
50 |
-
|
51 |
-
DEEPCACHE_INTERVAL = 2
|
52 |
-
|
53 |
-
TOME_RATIO = 0.0
|
54 |
-
|
55 |
-
SCALE = 2
|
56 |
-
|
57 |
-
SCALES = [1, 2, 4]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/__init__.py
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
1 |
from .inference import generate
|
2 |
from .loader import Loader
|
3 |
from .upscaler import RealESRGAN
|
|
|
|
|
|
1 |
+
from .config import Config
|
2 |
from .inference import generate
|
3 |
from .loader import Loader
|
4 |
from .upscaler import RealESRGAN
|
5 |
+
|
6 |
+
__all__ = ["Config", "Loader", "RealESRGAN", "generate"]
|
lib/config.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from types import SimpleNamespace
|
2 |
+
|
3 |
+
Config = SimpleNamespace(
|
4 |
+
MONO_FONTS=["monospace"],
|
5 |
+
SANS_FONTS=[
|
6 |
+
"sans-serif",
|
7 |
+
"Apple Color Emoji",
|
8 |
+
"Segoe UI Emoji",
|
9 |
+
"Segoe UI Symbol",
|
10 |
+
"Noto Color Emoji",
|
11 |
+
],
|
12 |
+
MODEL="Lykon/dreamshaper-8",
|
13 |
+
MODELS=[
|
14 |
+
"fluently/Fluently-v4",
|
15 |
+
"Linaqruf/anything-v3-1",
|
16 |
+
"Lykon/dreamshaper-8",
|
17 |
+
"prompthero/openjourney-v4",
|
18 |
+
"runwayml/stable-diffusion-v1-5",
|
19 |
+
"SG161222/Realistic_Vision_V5.1_Novae",
|
20 |
+
],
|
21 |
+
SCHEDULER="DEIS 2M",
|
22 |
+
SCHEDULERS=[
|
23 |
+
"DEIS 2M",
|
24 |
+
"DPM++ 2M",
|
25 |
+
"DPM2 a",
|
26 |
+
"Euler a",
|
27 |
+
"Heun",
|
28 |
+
"LMS",
|
29 |
+
"PNDM",
|
30 |
+
],
|
31 |
+
EMBEDDING="fast_negative",
|
32 |
+
EMBEDDINGS={
|
33 |
+
"async_negative",
|
34 |
+
"bad_dream",
|
35 |
+
"cyberrealistic_negative",
|
36 |
+
"deep_negative",
|
37 |
+
"fast_negative",
|
38 |
+
"unrealistic_dream",
|
39 |
+
},
|
40 |
+
STYLE="sai-enhance",
|
41 |
+
WIDTH=448,
|
42 |
+
HEIGHT=576,
|
43 |
+
NUM_IMAGES=1,
|
44 |
+
SEED=-1,
|
45 |
+
GUIDANCE_SCALE=7,
|
46 |
+
INFERENCE_STEPS=30,
|
47 |
+
DEEPCACHE_INTERVAL=2,
|
48 |
+
TOME_RATIO=0.0,
|
49 |
+
SCALE=1,
|
50 |
+
SCALES=[1, 2, 4],
|
51 |
+
)
|
lib/inference.py
CHANGED
@@ -12,6 +12,7 @@ import tomesd
|
|
12 |
import torch
|
13 |
from compel import Compel, DiffusersTextualInversionManager, ReturnedEmbeddingsType
|
14 |
from compel.prompt_parser import PromptParser
|
|
|
15 |
|
16 |
from .loader import Loader
|
17 |
|
@@ -75,6 +76,7 @@ def apply_style(prompt, style_id, negative=False):
|
|
75 |
def generate(
|
76 |
positive_prompt,
|
77 |
negative_prompt="",
|
|
|
78 |
style=None,
|
79 |
seed=None,
|
80 |
model="runwayml/stable-diffusion-v1-5",
|
@@ -132,6 +134,21 @@ def generate(
|
|
132 |
DEVICE,
|
133 |
)
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
# prompt embeds
|
136 |
compel = Compel(
|
137 |
textual_inversion_manager=DiffusersTextualInversionManager(pipe),
|
@@ -185,6 +202,7 @@ def generate(
|
|
185 |
images.append((image, str(current_seed)))
|
186 |
finally:
|
187 |
if not ZERO_GPU:
|
|
|
188 |
torch.cuda.empty_cache()
|
189 |
|
190 |
if increment_seed:
|
@@ -193,6 +211,7 @@ def generate(
|
|
193 |
if ZERO_GPU:
|
194 |
# spaces always start fresh
|
195 |
loader.pipe = None
|
|
|
196 |
|
197 |
diff = time.perf_counter() - start
|
198 |
if Info:
|
|
|
12 |
import torch
|
13 |
from compel import Compel, DiffusersTextualInversionManager, ReturnedEmbeddingsType
|
14 |
from compel.prompt_parser import PromptParser
|
15 |
+
from huggingface_hub.utils import HFValidationError, RepositoryNotFoundError
|
16 |
|
17 |
from .loader import Loader
|
18 |
|
|
|
76 |
def generate(
|
77 |
positive_prompt,
|
78 |
negative_prompt="",
|
79 |
+
embeddings=[],
|
80 |
style=None,
|
81 |
seed=None,
|
82 |
model="runwayml/stable-diffusion-v1-5",
|
|
|
134 |
DEVICE,
|
135 |
)
|
136 |
|
137 |
+
# load embeddings and append to negative prompt
|
138 |
+
embeddings_dir = os.path.join(os.path.dirname(__file__), "..", "embeddings")
|
139 |
+
embeddings_dir = os.path.abspath(embeddings_dir)
|
140 |
+
for embedding in embeddings:
|
141 |
+
try:
|
142 |
+
pipe.load_textual_inversion(
|
143 |
+
pretrained_model_name_or_path=f"{embeddings_dir}/{embedding}.pt",
|
144 |
+
token=f"<{embedding}>",
|
145 |
+
)
|
146 |
+
negative_prompt = (
|
147 |
+
f"{negative_prompt}, {embedding}" if negative_prompt else embedding
|
148 |
+
)
|
149 |
+
except (EnvironmentError, HFValidationError, RepositoryNotFoundError):
|
150 |
+
raise Error(f"Invalid embedding: {embedding}")
|
151 |
+
|
152 |
# prompt embeds
|
153 |
compel = Compel(
|
154 |
textual_inversion_manager=DiffusersTextualInversionManager(pipe),
|
|
|
202 |
images.append((image, str(current_seed)))
|
203 |
finally:
|
204 |
if not ZERO_GPU:
|
205 |
+
pipe.unload_textual_inversion()
|
206 |
torch.cuda.empty_cache()
|
207 |
|
208 |
if increment_seed:
|
|
|
211 |
if ZERO_GPU:
|
212 |
# spaces always start fresh
|
213 |
loader.pipe = None
|
214 |
+
loader.upscaler = None
|
215 |
|
216 |
diff = time.perf_counter() - start
|
217 |
if Info:
|
lib/loader.py
CHANGED
@@ -22,14 +22,6 @@ ZERO_GPU = (
|
|
22 |
or os.environ.get("SPACES_ZERO_GPU", "") == "1"
|
23 |
)
|
24 |
|
25 |
-
EMBEDDINGS = {
|
26 |
-
"./embeddings/bad_prompt_version2.pt": "<bad_prompt>",
|
27 |
-
"./embeddings/BadDream.pt": "<bad_dream>",
|
28 |
-
"./embeddings/FastNegativeV2.pt": "<fast_negative>",
|
29 |
-
"./embeddings/negative_hand.pt": "<negative_hand>",
|
30 |
-
"./embeddings/UnrealisticDream.pt": "<unrealistic_dream>",
|
31 |
-
}
|
32 |
-
|
33 |
|
34 |
# inspired by ComfyUI
|
35 |
# https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/model_management.py
|
@@ -191,10 +183,6 @@ class Loader:
|
|
191 |
device=device,
|
192 |
dtype=dtype,
|
193 |
)
|
194 |
-
self.pipe.load_textual_inversion(
|
195 |
-
pretrained_model_name_or_path=list(EMBEDDINGS.keys()),
|
196 |
-
tokens=list(EMBEDDINGS.values()),
|
197 |
-
)
|
198 |
self._load_vae(model_lower, taesd, variant)
|
199 |
self._load_freeu(freeu)
|
200 |
self._load_deepcache(deepcache_interval)
|
|
|
22 |
or os.environ.get("SPACES_ZERO_GPU", "") == "1"
|
23 |
)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# inspired by ComfyUI
|
27 |
# https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/model_management.py
|
|
|
183 |
device=device,
|
184 |
dtype=dtype,
|
185 |
)
|
|
|
|
|
|
|
|
|
186 |
self._load_vae(model_lower, taesd, variant)
|
187 |
self._load_freeu(freeu)
|
188 |
self._load_deepcache(deepcache_interval)
|
usage.md
CHANGED
@@ -12,33 +12,21 @@ Positive and negative prompts are embedded by [Compel](https://github.com/damian
|
|
12 |
|
13 |
Note that `++` is `1.1^2` (and so on). See [syntax features](https://github.com/damian0815/compel/blob/main/doc/syntax.md) to learn more and read [Civitai](https://civitai.com)'s guide on [prompting](https://education.civitai.com/civitais-prompt-crafting-guide-part-1-basics/) for best practices.
|
14 |
|
15 |
-
#### Negative Prompt
|
16 |
-
|
17 |
-
Start with a [textual inversion](https://huggingface.co/docs/diffusers/en/using-diffusers/textual_inversion_inference) embedding:
|
18 |
-
|
19 |
-
* [`<bad_prompt>`](https://civitai.com/models/55700/badprompt-negative-embedding)
|
20 |
-
* [`<negative_hand>`](https://civitai.com/models/56519/negativehand-negative-embedding)
|
21 |
-
* [`<fast_negative>`](https://civitai.com/models/71961/fast-negative-embedding-fastnegativev2)
|
22 |
-
* [`<bad_dream>`](https://civitai.com/models/72437?modelVersionId=77169)
|
23 |
-
* [`<unrealistic_dream>`](https://civitai.com/models/72437?modelVersionId=77173)
|
24 |
-
|
25 |
-
And add to it. You can use weighting in the negative prompt as well.
|
26 |
-
|
27 |
#### Arrays
|
28 |
|
29 |
Arrays allow you to generate different images from a single prompt. For example, `[[cat,corgi]]` will expand into 2 separate prompts. Make sure `Images` is set accordingly (e.g., 2). Only works for the positive prompt. Inspired by [Fooocus](https://github.com/lllyasviel/Fooocus/pull/1503).
|
30 |
|
31 |
-
###
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
[
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
### Scale
|
44 |
|
@@ -55,7 +43,7 @@ Each model checkpoint has a different aesthetic:
|
|
55 |
* [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5): base
|
56 |
* [sg161222/realistic_vision_v5.1](https://huggingface.co/SG161222/Realistic_Vision_V5.1_noVAE): photorealistic
|
57 |
|
58 |
-
|
59 |
|
60 |
Optionally, the [Karras](https://arxiv.org/abs/2206.00364) noise schedule can be used:
|
61 |
|
@@ -81,6 +69,14 @@ Optionally, the [Karras](https://arxiv.org/abs/2206.00364) noise schedule can be
|
|
81 |
|
82 |
[Token merging](https://github.com/dbolya/tomesd) (Bolya & Hoffman 2023) reduces the number of tokens processed by the model. Set `Ratio` to the desired reduction factor. ToMe's impact is more noticeable on larger images.
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
#### Tiny VAE
|
85 |
|
86 |
Enable [madebyollin/taesd](https://github.com/madebyollin/taesd) for almost instant latent decoding with a minor loss in detail. Useful for development.
|
|
|
12 |
|
13 |
Note that `++` is `1.1^2` (and so on). See [syntax features](https://github.com/damian0815/compel/blob/main/doc/syntax.md) to learn more and read [Civitai](https://civitai.com)'s guide on [prompting](https://education.civitai.com/civitais-prompt-crafting-guide-part-1-basics/) for best practices.
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
#### Arrays
|
16 |
|
17 |
Arrays allow you to generate different images from a single prompt. For example, `[[cat,corgi]]` will expand into 2 separate prompts. Make sure `Images` is set accordingly (e.g., 2). Only works for the positive prompt. Inspired by [Fooocus](https://github.com/lllyasviel/Fooocus/pull/1503).
|
18 |
|
19 |
+
### Embeddings
|
20 |
|
21 |
+
Select multiple negative [textual inversion](https://huggingface.co/docs/diffusers/en/using-diffusers/textual_inversion_inference) embeddings. Fast Negative and Bad Dream can be used standalone or together; Unrealistic Dream should be combined with one of the others:
|
22 |
|
23 |
+
* [`<fast_negative>`](https://civitai.com/models/71961/fast-negative-embedding-fastnegativev2): all-purpose (default)
|
24 |
+
* [`<bad_dream>`](https://civitai.com/models/72437?modelVersionId=77169): DreamShaper-style
|
25 |
+
* [`<unrealistic_dream>`](https://civitai.com/models/72437?modelVersionId=77173): realistic add-on
|
26 |
|
27 |
+
### Styles
|
28 |
|
29 |
+
Styles are prompt templates from twri's [sdxl_prompt_styler](https://github.com/twri/sdxl_prompt_styler) Comfy node. Start with a subject like "cat", pick a style, and iterate from there.
|
30 |
|
31 |
### Scale
|
32 |
|
|
|
43 |
* [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5): base
|
44 |
* [sg161222/realistic_vision_v5.1](https://huggingface.co/SG161222/Realistic_Vision_V5.1_noVAE): photorealistic
|
45 |
|
46 |
+
### Schedulers
|
47 |
|
48 |
Optionally, the [Karras](https://arxiv.org/abs/2206.00364) noise schedule can be used:
|
49 |
|
|
|
69 |
|
70 |
[Token merging](https://github.com/dbolya/tomesd) (Bolya & Hoffman 2023) reduces the number of tokens processed by the model. Set `Ratio` to the desired reduction factor. ToMe's impact is more noticeable on larger images.
|
71 |
|
72 |
+
#### FreeU
|
73 |
+
|
74 |
+
[FreeU](https://github.com/ChenyangSi/FreeU) (Si et al. 2023) re-weights the contributions sourced from the U-Net’s skip connections and backbone feature maps to potentially improve image quality.
|
75 |
+
|
76 |
+
#### Clip Skip
|
77 |
+
|
78 |
+
When enabled, the last CLIP layer is skipped. This _can_ improve image quality with anime models.
|
79 |
+
|
80 |
#### Tiny VAE
|
81 |
|
82 |
Enable [madebyollin/taesd](https://github.com/madebyollin/taesd) for almost instant latent decoding with a minor loss in detail. Useful for development.
|