Views
No views yet
diffusers library, along with other essential packages:1pip install diffusers --upgrade
2pip install transformers accelerate safetensors1import torch
2from diffusers import (
3 StableDiffusionXLPipeline,
4 EulerAncestralDiscreteScheduler,
5 AutoencoderKL
6)
7
8# Initialize LoRA model and weights
9lora_model_id = "Linaqruf/anime-detailer-xl-lora"
10lora_filename = "anime-detailer-xl.safetensors"
11lora_scale_slider = 2 # -2 for less detailed result
12
13# Load VAE component
14vae = AutoencoderKL.from_pretrained(
15 "madebyollin/sdxl-vae-fp16-fix",
16 torch_dtype=torch.float16
17)
18
19# Configure the pipeline
20pipe = StableDiffusionXLPipeline.from_pretrained(
21 "Linaqruf/animagine-xl-2.0",
22 vae=vae,
23 torch_dtype=torch.float16,
24 use_safetensors=True,
25 variant="fp16"
26)
27pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
28pipe.to('cuda')
29
30# Load and fuse LoRA weights
31pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
32pipe.fuse_lora(lora_scale=lora_scale_slider)
33
34# Define prompts and generate image
35prompt = "face focus, cute, masterpiece, best quality, 1girl, green hair, sweater, looking at viewer, upper body, beanie, outdoors, night, turtleneck"
36negative_prompt = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"
37
38image = pipe(
39 prompt,
40 negative_prompt=negative_prompt,
41 width=1024,
42 height=1024,
43 guidance_scale=12,
44 num_inference_steps=50
45).images[0]
46
47# Unfuse LoRA before saving the image
48pipe.unfuse_lora()
49image.save("anime_girl.png")
50