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/style-enhancer-xl-lora"
10lora_filename = "style-enhancer-xl.safetensors"
11
12# Load VAE component
13vae = AutoencoderKL.from_pretrained(
14 "madebyollin/sdxl-vae-fp16-fix",
15 torch_dtype=torch.float16
16)
17
18# Configure the pipeline
19pipe = StableDiffusionXLPipeline.from_pretrained(
20 "Linaqruf/animagine-xl-2.0",
21 vae=vae,
22 torch_dtype=torch.float16,
23 use_safetensors=True,
24 variant="fp16"
25)
26pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
27pipe.to('cuda')
28
29# Load and fuse LoRA weights
30pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
31pipe.fuse_lora(lora_scale=0.6)
32
33# Define prompts and generate image
34prompt = "face focus, cute, masterpiece, best quality, 1girl, green hair, sweater, looking at viewer, upper body, beanie, outdoors, night, turtleneck"
35negative_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"
36
37image = pipe(
38 prompt,
39 negative_prompt=negative_prompt,
40 width=1024,
41 height=1024,
42 guidance_scale=12,
43 num_inference_steps=50
44).images[0]
45
46# Unfuse LoRA before saving the image
47pipe.unfuse_lora()
48image.save("anime_girl.png")
49