You can load and use the LoRA weights directly with the Diffusers library for both text-to-image and image-to-image tasks:
1import torch
2from diffusers import StableDiffusionXLPipeline
3
4# Load base SDXL pipeline
5pipeline = StableDiffusionXLPipeline.from_pretrained(
6 "stabilityai/stable-diffusion-xl-base-1.0",
7 torch_dtype=torch.float16,
8 variant="fp16",
9 use_safetensors=True
10)
11pipeline.enable_model_cpu_offload()
12
13# Load KielForge-HD LoRA weights
14pipeline.load_lora_weights("kiel2/KielForge-HD", weight_name="pytorch_lora_weights.safetensors")
15
16# Text-to-Image Generation
17
18prompt = "A cinematic close-up portrait of the man, detailed skin texture, natural lighting, masterpiece"
19negative_prompt = "blurry, low quality, distorted, deformed face, plastic skin, waxy"
20
21image = pipeline(
22 prompt=prompt,
23 negative_prompt=negative_prompt,
24 num_inference_steps=35,
25 guidance_scale=7.5,
26 cross_attention_kwargs={"scale": 0.75}
27).images[0]
28
29image.save("output.png")
1import torch
2from diffusers import StableDiffusionXLImg2ImgPipeline
3from diffusers.utils import load_image
4
5# Load pipeline for Image-to-Image
6pipeline = StableDiffusionXLImg2ImgPipeline.from_pretrained(
7 "stabilityai/stable-diffusion-xl-base-1.0",
8 torch_dtype=torch.float16,
9 variant="fp16",
10 use_safetensors=True
11)
12pipeline.enable_model_cpu_offload()
13
14# Load LoRA weights
15pipeline.load_lora_weights("kiel2/KielForge-HD", weight_name="pytorch_lora_weights.safetensors")
16
17# Load input source image
18init_image = load_image("[https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_file_sd.png](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_file_sd.png)").resize((1024, 1024))
19
20prompt = "A cinematic portrait of the man in an outdoor canyon setting"
21image = pipeline(
22 prompt=prompt,
23 image=init_image,
24 strength=0.75,
25 guidance_scale=7.5,
26 cross_attention_kwargs={"scale": 0.75}
27).images[0]
28
29image.save("img2img_output.png")