Creation of Images from Text-Prompt (Customized Training)

The options you give when loading LoRA are a little special. You have to separate the file name from the directory name. Like this.

from diffusers import AutoPipelineForText2Image
import torch
import os
from pathlib import Path

# Load the base model
pipeline = AutoPipelineForText2Image.from_pretrained("sd-dreambooth-library/herge-style", torch_dtype=torch.float16).to("cuda")

# Specify the path to your LoRA weights file
lora_weights_path = "D:\\Ganu\\AIImage\\huggingface\\kohya_ss\\kohya_ss\\trained-model\\model\\last.safetensors"

# Verify the LoRA weights file
if not os.path.exists(lora_weights_path):
    raise FileNotFoundError(f"LoRA weights file not found at {lora_weights_path}")

# Load LoRA weights
try:
    pipeline.load_lora_weights(Path(lora_weights_path).parent, weight_name=Path(lora_weights_path).name)
    #pipeline.fuse_lora(lora_scale=1.0) # if LoRA isn't work
    #pipeline.save_pretrained("lora_applied_model") # if you want to save LoRA applied model
    #https://huggingface.co/docs/diffusers/v0.32.1/api/loaders/lora
except ValueError as e:
    raise ValueError("Invalid LoRA checkpoint. Please check the compatibility and format of the weights file.") from e

# Generate an image from a text prompt
prompt = "A cute herge_style brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration"
image = pipeline(prompt).images[0]

# Display the generated image
image.save("generated_image.jpg")
image.show()