@@ -368,7 +368,7 @@ def load_textual_inversion(
368
368
):
369
369
r"""
370
370
Load textual inversion embeddings into the text encoder of stable diffusion pipelines. Both `diffusers` and
371
- `Automatic1111` formats are supported.
371
+ `Automatic1111` formats are supported (see example below) .
372
372
373
373
<Tip warning={true}>
374
374
@@ -427,6 +427,42 @@ def load_textual_inversion(
427
427
models](https://huggingface.co/docs/hub/models-gated#gated-models).
428
428
429
429
</Tip>
430
+
431
+ Example:
432
+
433
+ To load a textual inversion embedding vector in `diffusers` format:
434
+ ```py
435
+ from diffusers import StableDiffusionPipeline
436
+ import torch
437
+
438
+ model_id = "runwayml/stable-diffusion-v1-5"
439
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
440
+
441
+ pipe.load_textual_inversion("sd-concepts-library/cat-toy")
442
+
443
+ prompt = "A <cat-toy> backpack"
444
+
445
+ image = pipe(prompt, num_inference_steps=50).images[0]
446
+ image.save("cat-backpack.png")
447
+ ```
448
+
449
+ To load a textual inversion embedding vector in Automatic1111 format, make sure to first download the vector,
450
+ e.g. from [civitAI](https://civitai.com/models/3036?modelVersionId=9857) and then load the vector locally:
451
+
452
+ ```py
453
+ from diffusers import StableDiffusionPipeline
454
+ import torch
455
+
456
+ model_id = "runwayml/stable-diffusion-v1-5"
457
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
458
+
459
+ pipe.load_textual_inversion("./charturnerv2.pt")
460
+
461
+ prompt = "charturnerv2, multiple views of the same character in the same outfit, a character turnaround of a woman wearing a black jacket and red shirt, best quality, intricate details."
462
+
463
+ image = pipe(prompt, num_inference_steps=50).images[0]
464
+ image.save("character.png")
465
+ ```
430
466
"""
431
467
if not hasattr (self , "tokenizer" ) or not isinstance (self .tokenizer , PreTrainedTokenizer ):
432
468
raise ValueError (
0 commit comments