Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines3456789101112131415161718192021222324252627282 unmodified linesfrom huggingface_hub import hf_hub_downloadfrom safetensors.torch import load_fileimport gradio as grbase = "stabilityai/stable-diffusion-xl-base-1.0"repo = "ByteDance/SDXL-Lightning"ckpt = "sdxl_lightning_1step_unet_x0.safetensors" # Use the correct ckpt for your step setting!# Load model.def generate():unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")# Ensure sampler uses "trailing" timesteps and "sample" prediction type.pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample")# Ensure using the same inference steps as the loaded model and CFG set to 0.def greet(prompt):image = pipe(prompt, num_inference_steps=1, guidance_scale=0).images[0].save("output.png")return imagedemo = gr.Interface(fn=greet, inputs="text", outputs="image")demo.launch()2 unmodified lines3456789101112131415161718192021222324252627282930312 unmodified linesfrom huggingface_hub import hf_hub_downloadfrom safetensors.torch import load_fileimport gradio as grimport spacesbase = "stabilityai/stable-diffusion-xl-base-1.0"repo = "ByteDance/SDXL-Lightning"ckpt = "sdxl_lightning_1step_unet_x0.safetensors" # Use the correct ckpt for your step setting!# Load model.@spaces.GPUdef generate(prompt):unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")# Ensure sampler uses "trailing" timesteps and "sample" prediction type.pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample")image = pipe(prompt, num_inference_steps=1, guidance_scale=0).images[0].save("output.png")return image# Ensure using the same inference steps as the loaded model and CFG set to 0.# @spaces.GPU# def greet(prompt):# image = pipe(prompt, num_inference_steps=1, guidance_scale=0).images[0].save("output.png")# return imagedemo = gr.Interface(fn=generate, inputs="text", outputs="image")demo.launch()
app.py+11-8