Spaces:
Runtime error
Runtime error
Commit
·
7239d24
1
Parent(s):
7540b2d
Update app.py
Browse files
app.py
CHANGED
@@ -10,40 +10,48 @@ from diffusers import StableDiffusionSAGPipeline
|
|
10 |
|
11 |
|
12 |
help_text = """
|
13 |
-
Self-Attention Guidance (SAG) - Condition-Agnostic Diffusion Guidance Using the Internal Self-Attention
|
14 |
"""
|
15 |
|
16 |
|
|
|
17 |
examples = [
|
18 |
[
|
19 |
' ',
|
20 |
50,
|
21 |
"Fix Seed",
|
22 |
-
|
23 |
-
|
24 |
1.0,
|
25 |
],
|
26 |
[
|
27 |
'.',
|
28 |
50,
|
29 |
"Fix Seed",
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
1.0,
|
33 |
],
|
34 |
[
|
35 |
-
'A
|
36 |
50,
|
37 |
"Fix Seed",
|
38 |
-
|
39 |
5.0,
|
40 |
1.0,
|
41 |
],
|
42 |
[
|
43 |
-
'A
|
44 |
50,
|
45 |
"Fix Seed",
|
46 |
-
|
47 |
5.0,
|
48 |
1.0,
|
49 |
],
|
@@ -69,14 +77,18 @@ def main():
|
|
69 |
ori_image = pipe(prompt, generator=generator, guidance_scale=cfg_scale, sag_scale=0.0).images[0]
|
70 |
generator = torch.manual_seed(seed)
|
71 |
sag_image = pipe(prompt, generator=generator, guidance_scale=cfg_scale, sag_scale=sag_scale).images[0]
|
72 |
-
return [ori_image, sag_image]
|
73 |
|
74 |
def reset():
|
75 |
-
return [0, "Randomize Seed",
|
76 |
|
77 |
with gr.Blocks() as demo:
|
78 |
-
gr.HTML("""<h1 style="font-weight: 900; margin-bottom:
|
79 |
-
|
|
|
|
|
|
|
|
|
80 |
""")
|
81 |
with gr.Row():
|
82 |
with gr.Column(scale=5):
|
@@ -100,7 +112,7 @@ def main():
|
|
100 |
|
101 |
with gr.Row():
|
102 |
cfg_scale = gr.Slider(
|
103 |
-
label="Guidance Scale", minimum=0, maximum=10, value=5.0, step=0.1
|
104 |
)
|
105 |
sag_scale = gr.Slider(
|
106 |
label="Self-Attention Guidance Scale", minimum=0, maximum=1.0, value=0.75, step=0.05
|
@@ -124,7 +136,7 @@ def main():
|
|
124 |
cfg_scale,
|
125 |
sag_scale,
|
126 |
],
|
127 |
-
outputs=[ori_image, sag_image],
|
128 |
cache_examples=False,
|
129 |
)
|
130 |
|
@@ -140,7 +152,7 @@ def main():
|
|
140 |
cfg_scale,
|
141 |
sag_scale,
|
142 |
],
|
143 |
-
outputs=[ori_image, sag_image],
|
144 |
)
|
145 |
reset_button.click(
|
146 |
fn=reset,
|
|
|
10 |
|
11 |
|
12 |
help_text = """
|
|
|
13 |
"""
|
14 |
|
15 |
|
16 |
+
|
17 |
examples = [
|
18 |
[
|
19 |
' ',
|
20 |
50,
|
21 |
"Fix Seed",
|
22 |
+
35934,
|
23 |
+
5.0,
|
24 |
1.0,
|
25 |
],
|
26 |
[
|
27 |
'.',
|
28 |
50,
|
29 |
"Fix Seed",
|
30 |
+
24865,
|
31 |
+
5.0,
|
32 |
+
1.0,
|
33 |
+
],
|
34 |
+
[
|
35 |
+
'A poster',
|
36 |
+
50,
|
37 |
+
"Fix Seed",
|
38 |
+
37956,
|
39 |
+
5.0,
|
40 |
1.0,
|
41 |
],
|
42 |
[
|
43 |
+
'A high-quality living room',
|
44 |
50,
|
45 |
"Fix Seed",
|
46 |
+
78710,
|
47 |
5.0,
|
48 |
1.0,
|
49 |
],
|
50 |
[
|
51 |
+
'A Scottish Fold playing with a ball',
|
52 |
50,
|
53 |
"Fix Seed",
|
54 |
+
11511,
|
55 |
5.0,
|
56 |
1.0,
|
57 |
],
|
|
|
77 |
ori_image = pipe(prompt, generator=generator, guidance_scale=cfg_scale, sag_scale=0.0).images[0]
|
78 |
generator = torch.manual_seed(seed)
|
79 |
sag_image = pipe(prompt, generator=generator, guidance_scale=cfg_scale, sag_scale=sag_scale).images[0]
|
80 |
+
return [ori_image, sag_image, seed]
|
81 |
|
82 |
def reset():
|
83 |
+
return [0, "Randomize Seed", 42, 5.0, 0.75, None, None]
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
+
gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 10px;">
|
87 |
+
Self-Attention Guidance (SAG) Demo
|
88 |
+
</h1>
|
89 |
+
<h3 style="font-weight: 500; margin-bottom: 10px;">
|
90 |
+
Condition-Agnostic Diffusion Guidance Using the Internal Self-Attention
|
91 |
+
</h3>
|
92 |
""")
|
93 |
with gr.Row():
|
94 |
with gr.Column(scale=5):
|
|
|
112 |
|
113 |
with gr.Row():
|
114 |
cfg_scale = gr.Slider(
|
115 |
+
label="Text Guidance Scale", minimum=0, maximum=10, value=5.0, step=0.1
|
116 |
)
|
117 |
sag_scale = gr.Slider(
|
118 |
label="Self-Attention Guidance Scale", minimum=0, maximum=1.0, value=0.75, step=0.05
|
|
|
136 |
cfg_scale,
|
137 |
sag_scale,
|
138 |
],
|
139 |
+
outputs=[ori_image, sag_image, seed],
|
140 |
cache_examples=False,
|
141 |
)
|
142 |
|
|
|
152 |
cfg_scale,
|
153 |
sag_scale,
|
154 |
],
|
155 |
+
outputs=[ori_image, sag_image, seed],
|
156 |
)
|
157 |
reset_button.click(
|
158 |
fn=reset,
|