Spaces:
Sleeping
Sleeping
Commit
·
ea0bceb
1
Parent(s):
cde0b82
update
Browse files
app.py
CHANGED
|
@@ -351,8 +351,11 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
| 351 |
noise_pred_cond = unet(sample=input, timestep=t, encoder_hidden_states=encoder_hidden_states_cond[:slider_batch]).sample # b, 4, 64, 64
|
| 352 |
noise_pred_uncond = unet(sample=input, timestep=t, encoder_hidden_states=encoder_hidden_states_nocond[:slider_batch]).sample # b, 4, 64, 64
|
| 353 |
noisy_residual = noise_pred_uncond + slider_guidance * (noise_pred_cond - noise_pred_uncond) # b, 4, 64, 64
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
# decode
|
| 358 |
input = 1 / vae.config.scaling_factor * input
|
|
@@ -372,6 +375,8 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
| 372 |
# results.insert(0, new_image)
|
| 373 |
# return new_image
|
| 374 |
os.system('nvidia-smi')
|
|
|
|
|
|
|
| 375 |
return tuple(results), composed_prompt
|
| 376 |
|
| 377 |
elif radio == 'TextDiffuser-2-LCM':
|
|
@@ -384,6 +389,9 @@ def text_to_image(prompt,keywords,radio,slider_step,slider_guidance,slider_batch
|
|
| 384 |
guidance_scale=1,
|
| 385 |
num_images_per_prompt=slider_batch,
|
| 386 |
).images
|
|
|
|
|
|
|
|
|
|
| 387 |
return tuple(image), composed_prompt
|
| 388 |
|
| 389 |
with gr.Blocks() as demo:
|
|
|
|
| 351 |
noise_pred_cond = unet(sample=input, timestep=t, encoder_hidden_states=encoder_hidden_states_cond[:slider_batch]).sample # b, 4, 64, 64
|
| 352 |
noise_pred_uncond = unet(sample=input, timestep=t, encoder_hidden_states=encoder_hidden_states_nocond[:slider_batch]).sample # b, 4, 64, 64
|
| 353 |
noisy_residual = noise_pred_uncond + slider_guidance * (noise_pred_cond - noise_pred_uncond) # b, 4, 64, 64
|
| 354 |
+
input = scheduler.step(noisy_residual, t, input).prev_sample
|
| 355 |
+
del noise_pred_cond
|
| 356 |
+
del noise_pred_uncond
|
| 357 |
+
|
| 358 |
+
torch.cuda.empty_cache()
|
| 359 |
|
| 360 |
# decode
|
| 361 |
input = 1 / vae.config.scaling_factor * input
|
|
|
|
| 375 |
# results.insert(0, new_image)
|
| 376 |
# return new_image
|
| 377 |
os.system('nvidia-smi')
|
| 378 |
+
torch.cuda.empty_cache()
|
| 379 |
+
os.system('nvidia-smi')
|
| 380 |
return tuple(results), composed_prompt
|
| 381 |
|
| 382 |
elif radio == 'TextDiffuser-2-LCM':
|
|
|
|
| 389 |
guidance_scale=1,
|
| 390 |
num_images_per_prompt=slider_batch,
|
| 391 |
).images
|
| 392 |
+
os.system('nvidia-smi')
|
| 393 |
+
torch.cuda.empty_cache()
|
| 394 |
+
os.system('nvidia-smi')
|
| 395 |
return tuple(image), composed_prompt
|
| 396 |
|
| 397 |
with gr.Blocks() as demo:
|