Spaces:
Runtime error
Runtime error
Commit
·
01e731e
1
Parent(s):
2644577
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,11 @@ model_id = "stabilityai/stable-diffusion-2-1"
|
|
| 38 |
pip_2_1 = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 39 |
pip_2_1 = pip_2_1.to("cuda")
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def infer(prompt, sd_options, seed, b1, b2, s1, s2):
|
| 42 |
|
| 43 |
if sd_options == 'SD1.5':
|
|
@@ -46,14 +51,26 @@ def infer(prompt, sd_options, seed, b1, b2, s1, s2):
|
|
| 46 |
pip = pip_2_1
|
| 47 |
else:
|
| 48 |
pip = pip_1_4
|
| 49 |
-
|
| 50 |
-
register_free_upblock2d(pip, b1=1.0, b2=1.0, s1=1.0, s2=1.0)
|
| 51 |
-
register_free_crossattn_upblock2d(pip, b1=1.0, b2=1.0, s1=1.0, s2=1.0)
|
| 52 |
-
|
| 53 |
-
torch.manual_seed(seed)
|
| 54 |
-
print("Generating SD:")
|
| 55 |
-
sd_image = pip(prompt, num_inference_steps=25).images[0]
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
register_free_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
|
| 58 |
register_free_crossattn_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
|
| 59 |
|
|
@@ -168,12 +185,12 @@ with block:
|
|
| 168 |
b1 = gr.Slider(label='b1: backbone factor of the first stage block of decoder',
|
| 169 |
minimum=1,
|
| 170 |
maximum=1.6,
|
| 171 |
-
step=0.
|
| 172 |
value=1)
|
| 173 |
b2 = gr.Slider(label='b2: backbone factor of the second stage block of decoder',
|
| 174 |
minimum=1,
|
| 175 |
maximum=1.6,
|
| 176 |
-
step=0.
|
| 177 |
value=1)
|
| 178 |
with gr.Accordion('FreeU Parameters: s', open=True):
|
| 179 |
s1 = gr.Slider(label='s1: skip factor of the first stage block of decoder',
|
|
|
|
| 38 |
pip_2_1 = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 39 |
pip_2_1 = pip_2_1.to("cuda")
|
| 40 |
|
| 41 |
+
prompt_prev = None
|
| 42 |
+
sd_options_prev = None
|
| 43 |
+
seed_prev = None
|
| 44 |
+
sd_image_prev = None
|
| 45 |
+
|
| 46 |
def infer(prompt, sd_options, seed, b1, b2, s1, s2):
|
| 47 |
|
| 48 |
if sd_options == 'SD1.5':
|
|
|
|
| 51 |
pip = pip_2_1
|
| 52 |
else:
|
| 53 |
pip = pip_1_4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
run_baseline = False
|
| 56 |
+
if prompt != prompt_prev or sd_options != sd_options_prev or seed != seed_prev:
|
| 57 |
+
run_baseline = True
|
| 58 |
+
prompt_prev = prompt
|
| 59 |
+
sd_options_prev = sd_options
|
| 60 |
+
seed_prev = seed_prev
|
| 61 |
+
|
| 62 |
+
if run_baseline:
|
| 63 |
+
register_free_upblock2d(pip, b1=1.0, b2=1.0, s1=1.0, s2=1.0)
|
| 64 |
+
register_free_crossattn_upblock2d(pip, b1=1.0, b2=1.0, s1=1.0, s2=1.0)
|
| 65 |
+
|
| 66 |
+
torch.manual_seed(seed)
|
| 67 |
+
print("Generating SD:")
|
| 68 |
+
sd_image = pip(prompt, num_inference_steps=25).images[0]
|
| 69 |
+
sd_image_prev = sd_image
|
| 70 |
+
else:
|
| 71 |
+
sd_image = sd_image_prev
|
| 72 |
+
|
| 73 |
+
|
| 74 |
register_free_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
|
| 75 |
register_free_crossattn_upblock2d(pip, b1=b1, b2=b2, s1=s1, s2=s1)
|
| 76 |
|
|
|
|
| 185 |
b1 = gr.Slider(label='b1: backbone factor of the first stage block of decoder',
|
| 186 |
minimum=1,
|
| 187 |
maximum=1.6,
|
| 188 |
+
step=0.01,
|
| 189 |
value=1)
|
| 190 |
b2 = gr.Slider(label='b2: backbone factor of the second stage block of decoder',
|
| 191 |
minimum=1,
|
| 192 |
maximum=1.6,
|
| 193 |
+
step=0.01,
|
| 194 |
value=1)
|
| 195 |
with gr.Accordion('FreeU Parameters: s', open=True):
|
| 196 |
s1 = gr.Slider(label='s1: skip factor of the first stage block of decoder',
|