Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
21df05c
1
Parent(s):
d6bdfdf
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import torch
|
|
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
from safetensors.torch import load_file
|
6 |
-
import spaces
|
7 |
|
8 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
9 |
|
10 |
### SDXL Turbo ####
|
11 |
-
pipe_turbo = StableDiffusionXLPipeline.from_pretrained(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
### SDXL Lightning ###
|
19 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
@@ -22,16 +22,17 @@ ckpt = "sdxl_lightning_1step_unet_x0.safetensors"
|
|
22 |
|
23 |
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
24 |
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt)))
|
25 |
-
pipe_lightning = StableDiffusionXLPipeline.from_pretrained(
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
del unet
|
36 |
pipe_lightning.scheduler = EulerDiscreteScheduler.from_config(pipe_lightning.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
|
37 |
pipe_lightning.to("cuda")
|
@@ -42,16 +43,17 @@ ckpt_name = "Hyper-SDXL-1step-Unet.safetensors"
|
|
42 |
|
43 |
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
44 |
unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name)))
|
45 |
-
pipe_hyper = StableDiffusionXLPipeline.from_pretrained(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
55 |
pipe_hyper.scheduler = LCMScheduler.from_config(pipe_hyper.scheduler.config)
|
56 |
pipe_hyper.to("cuda")
|
57 |
del unet
|
@@ -65,13 +67,14 @@ def run_comparison(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
65 |
image_hyper=pipe_hyper(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[800]).images[0]
|
66 |
yield image_turbo, image_lightning, image_hyper
|
67 |
|
68 |
-
examples = [
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"a
|
73 |
-
"a
|
74 |
-
"
|
|
|
75 |
]
|
76 |
|
77 |
with gr.Blocks() as demo:
|
@@ -104,4 +107,5 @@ with gr.Blocks() as demo:
|
|
104 |
cache_examples=False,
|
105 |
run_on_click=True
|
106 |
)
|
|
|
107 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
import torch
|
4 |
+
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler, LCMScheduler, AutoencoderKL
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
from safetensors.torch import load_file
|
|
|
7 |
|
8 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
9 |
|
10 |
### SDXL Turbo ####
|
11 |
+
pipe_turbo = StableDiffusionXLPipeline.from_pretrained(
|
12 |
+
"stabilityai/sdxl-turbo",
|
13 |
+
vae=vae,
|
14 |
+
torch_dtype=torch.float16,
|
15 |
+
variant="fp16"
|
16 |
+
).to("cuda")
|
17 |
|
18 |
### SDXL Lightning ###
|
19 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
|
|
22 |
|
23 |
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
24 |
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt)))
|
25 |
+
pipe_lightning = StableDiffusionXLPipeline.from_pretrained(
|
26 |
+
base,
|
27 |
+
unet=unet,
|
28 |
+
vae=vae,
|
29 |
+
text_encoder=pipe_turbo.text_encoder,
|
30 |
+
text_encoder_2=pipe_turbo.text_encoder_2,
|
31 |
+
tokenizer=pipe_turbo.tokenizer,
|
32 |
+
tokenizer_2=pipe_turbo.tokenizer_2,
|
33 |
+
torch_dtype=torch.float16,
|
34 |
+
variant="fp16"
|
35 |
+
)#.to("cuda")
|
36 |
del unet
|
37 |
pipe_lightning.scheduler = EulerDiscreteScheduler.from_config(pipe_lightning.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
|
38 |
pipe_lightning.to("cuda")
|
|
|
43 |
|
44 |
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
45 |
unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name)))
|
46 |
+
pipe_hyper = StableDiffusionXLPipeline.from_pretrained(
|
47 |
+
base,
|
48 |
+
unet=unet,
|
49 |
+
vae=vae,
|
50 |
+
text_encoder=pipe_turbo.text_encoder,
|
51 |
+
text_encoder_2=pipe_turbo.text_encoder_2,
|
52 |
+
tokenizer=pipe_turbo.tokenizer,
|
53 |
+
tokenizer_2=pipe_turbo.tokenizer_2,
|
54 |
+
torch_dtype=torch.float16,
|
55 |
+
variant="fp16"
|
56 |
+
)#.to("cuda")
|
57 |
pipe_hyper.scheduler = LCMScheduler.from_config(pipe_hyper.scheduler.config)
|
58 |
pipe_hyper.to("cuda")
|
59 |
del unet
|
|
|
67 |
image_hyper=pipe_hyper(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[800]).images[0]
|
68 |
yield image_turbo, image_lightning, image_hyper
|
69 |
|
70 |
+
examples = [
|
71 |
+
"A dignified beaver wearing glasses, a vest, and colorful neck tie.",
|
72 |
+
"The spirit of a tamagotchi wandering in the city of Barcelona",
|
73 |
+
"an ornate, high-backed mahogany chair with a red cushion",
|
74 |
+
"a sketch of a camel next to a stream",
|
75 |
+
"a delicate porcelain teacup sits on a saucer, its surface adorned with intricate blue patterns",
|
76 |
+
"a baby swan grafitti",
|
77 |
+
"A bald eagle made of chocolate powder, mango, and whipped cream"
|
78 |
]
|
79 |
|
80 |
with gr.Blocks() as demo:
|
|
|
107 |
cache_examples=False,
|
108 |
run_on_click=True
|
109 |
)
|
110 |
+
|
111 |
demo.launch()
|