Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,17 +11,19 @@ from safetensors.torch import load_file
|
|
11 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
12 |
repo = "ByteDance/SDXL-Lightning"
|
13 |
ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!
|
14 |
-
|
15 |
# Load model.
|
|
|
16 |
@spaces.GPU
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
def run():
|
|
|
25 |
# Ensure using the same inference steps as the loaded model and CFG set to 0.
|
26 |
return pipe("A cat", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")
|
27 |
|
|
|
11 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
12 |
repo = "ByteDance/SDXL-Lightning"
|
13 |
ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!
|
|
|
14 |
# Load model.
|
15 |
+
pipe_box=[]
|
16 |
@spaces.GPU
|
17 |
+
def inti():
|
18 |
+
device="cuda"
|
19 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
|
20 |
+
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
21 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
22 |
+
# Ensure sampler uses "trailing" timesteps.
|
23 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
24 |
+
pipe_box.append(pipe)
|
25 |
def run():
|
26 |
+
pipe=pipe_box[0]
|
27 |
# Ensure using the same inference steps as the loaded model and CFG set to 0.
|
28 |
return pipe("A cat", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")
|
29 |
|