Views
No views yet
1import torch
2from diffusers import AutoencoderKL, DiffusionPipeline
3from safetensors.torch import load_file
4
5# Load pipeline
6vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
7pipe = DiffusionPipeline.from_pretrained(
8 "stabilityai/stable-diffusion-xl-base-1.0",
9 vae=vae,
10 torch_dtype=torch.float16,
11 variant="fp16",
12).to("cuda")
13
14# Load LoRA weights
15pipe.load_lora_weights("aaronw122/prtkl-sdxl-lora", weight_name="pytorch_lora_weights.safetensors")
16
17# Load textual inversion embeddings
18from huggingface_hub import hf_hub_download
19ti_path = hf_hub_download("aaronw122/prtkl-sdxl-lora", "results_emb.safetensors")
20state_dict = load_file(ti_path)
21pipe.load_textual_inversion(state_dict["clip_l"], token=["<s0>", "<s1>"], text_encoder=pipe.text_encoder, tokenizer=pipe.tokenizer)
22pipe.load_textual_inversion(state_dict["clip_g"], token=["<s0>", "<s1>"], text_encoder=pipe.text_encoder_2, tokenizer=pipe.tokenizer_2)
23
24# Generate
25image = pipe(
26 "<s0><s1>, a figure dancing with arms raised, white background",
27 negative_prompt="photorealistic, detailed, shading, gradient, gray, color, dense",
28 num_inference_steps=30,
29 guidance_scale=5.0,
30).images[0]
31image.save("particle_art.png")<s0><s1> (mapped from prtkl)<s0><s1>,"photorealistic, detailed, shading, gradient, gray, color, dense, beige, tan, sepia"