import{s as _e,o as be,n as le}from"../chunks/scheduler.182ea377.js";import{S as ye,i as Me,g as f,s as i,r as b,A as Te,h as u,f as r,c as l,j as q,u as y,x as I,k as E,y as p,a as d,v as M,d as T,t as w,w as $}from"../chunks/index.abf12888.js";import{T as we}from"../chunks/Tip.230e2334.js";import{D as ie}from"../chunks/Docstring.93f6f462.js";import{C as ve}from"../chunks/CodeBlock.57fe6e13.js";import{E as xe}from"../chunks/ExampleCodeBlock.658f5cd6.js";import{H as ge}from"../chunks/Heading.16916d63.js";function $e(k){let o,g='To learn more about how to load Textual Inversion embeddings, see the <a href="../../using-diffusers/loading_adapters#textual-inversion">Textual Inversion</a> loading guide.';return{c(){o=f("p"),o.innerHTML=g},l(s){o=u(s,"P",{"data-svelte-h":!0}),I(o)!=="svelte-1n8qarv"&&(o.innerHTML=g)},m(s,a){d(s,o,a)},p:le,d(s){s&&r(o)}}}function Ie(k){let o,g="To load a Textual Inversion embedding vector in 🤗 Diffusers format:",s,a,c;return a=new ve({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBcGlwZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNikudG8oJTIyY3VkYSUyMiklMEElMEFwaXBlLmxvYWRfdGV4dHVhbF9pbnZlcnNpb24oJTIyc2QtY29uY2VwdHMtbGlicmFyeSUyRmNhdC10b3klMjIpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQSUyMCUzQ2NhdC10b3klM0UlMjBiYWNrcGFjayUyMiUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTApLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMmNhdC1iYWNrcGFjay5wbmclMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch

model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)

pipe.load_textual_inversion(<span class="hljs-string">&quot;sd-concepts-library/cat-toy&quot;</span>)

prompt = <span class="hljs-string">&quot;A &lt;cat-toy&gt; backpack&quot;</span>

image = pipe(prompt, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;cat-backpack.png&quot;</span>)`,wrap:!1}}),{c(){o=f("p"),o.textContent=g,s=i(),b(a.$$.fragment)},l(t){o=u(t,"P",{"data-svelte-h":!0}),I(o)!=="svelte-1gc783q"&&(o.textContent=g),s=l(t),y(a.$$.fragment,t)},m(t,h){d(t,o,h),d(t,s,h),M(a,t,h),c=!0},p:le,i(t){c||(T(a.$$.fragment,t),c=!0)},o(t){w(a.$$.fragment,t),c=!1},d(t){t&&(r(o),r(s)),$(a,t)}}}function ke(k){let o,g="locally:",s,a,c;return a=new ve({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBcGlwZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNikudG8oJTIyY3VkYSUyMiklMEElMEFwaXBlLmxvYWRfdGV4dHVhbF9pbnZlcnNpb24oJTIyLiUyRmNoYXJ0dXJuZXJ2Mi5wdCUyMiUyQyUyMHRva2VuJTNEJTIyY2hhcnR1cm5lcnYyJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMmNoYXJ0dXJuZXJ2MiUyQyUyMG11bHRpcGxlJTIwdmlld3MlMjBvZiUyMHRoZSUyMHNhbWUlMjBjaGFyYWN0ZXIlMjBpbiUyMHRoZSUyMHNhbWUlMjBvdXRmaXQlMkMlMjBhJTIwY2hhcmFjdGVyJTIwdHVybmFyb3VuZCUyMG9mJTIwYSUyMHdvbWFuJTIwd2VhcmluZyUyMGElMjBibGFjayUyMGphY2tldCUyMGFuZCUyMHJlZCUyMHNoaXJ0JTJDJTIwYmVzdCUyMHF1YWxpdHklMkMlMjBpbnRyaWNhdGUlMjBkZXRhaWxzLiUyMiUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTApLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMmNoYXJhY3Rlci5wbmclMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch

model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)

pipe.load_textual_inversion(<span class="hljs-string">&quot;./charturnerv2.pt&quot;</span>, token=<span class="hljs-string">&quot;charturnerv2&quot;</span>)

prompt = <span class="hljs-string">&quot;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.&quot;</span>

image = pipe(prompt, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;character.png&quot;</span>)`,wrap:!1}}),{c(){o=f("p"),o.textContent=g,s=i(),b(a.$$.fragment)},l(t){o=u(t,"P",{"data-svelte-h":!0}),I(o)!=="svelte-4c75kq"&&(o.textContent=g),s=l(t),y(a.$$.fragment,t)},m(t,h){d(t,o,h),d(t,s,h),M(a,t,h),c=!0},p:le,i(t){c||(T(a.$$.fragment,t),c=!0)},o(t){w(a.$$.fragment,t),c=!1},d(t){t&&(r(o),r(s)),$(a,t)}}}function Ue(k){let o,g,s,a,c,t,h,de="Textual Inversion is a training method for personalizing models by learning new text embeddings from a few example images. The file produced from training is extremely small (a few KBs) and the new embeddings can be loaded into the text encoder.",S,Z,ce="<code>TextualInversionLoaderMixin</code> provides a function for loading Textual Inversion embeddings from Diffusers and Automatic1111 into the text encoder and loading a special token to activate the embeddings.",X,U,V,j,D,v,N,K,G,pe="Load Textual Inversion tokens and embeddings to the tokenizer and text encoder.",O,m,W,ee,H,me=`Load Textual Inversion embeddings into the text encoder of <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> (both 🤗 Diffusers and
Automatic1111 formats are supported).`,te,R,fe="Example:",oe,J,ne,z,ue=`To load a Textual Inversion embedding vector in Automatic1111 format, make sure to download the vector first
(for example from <a href="https://civitai.com/models/3036?modelVersionId=9857" rel="nofollow">civitAI</a>) and then load the vector`,re,C,ae,L,Y,se,P,he=`Processes prompts that include a special token corresponding to a multi-vector textual inversion embedding to
be replaced with multiple special tokens each corresponding to one of the vectors. If the prompt has no textual
inversion token or if the textual inversion token is a single vector, the input prompt is returned.`,Q,F,A;return c=new ge({props:{title:"Textual Inversion",local:"textual-inversion",headingTag:"h1"}}),U=new we({props:{$$slots:{default:[$e]},$$scope:{ctx:k}}}),j=new ge({props:{title:"TextualInversionLoaderMixin",local:"diffusers.loaders.TextualInversionLoaderMixin",headingTag:"h2"}}),N=new ie({props:{name:"class diffusers.loaders.TextualInversionLoaderMixin",anchor:"diffusers.loaders.TextualInversionLoaderMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L112"}}),W=new ie({props:{name:"load_textual_inversion",anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion",parameters:[{name:"pretrained_model_name_or_path",val:": Union"},{name:"token",val:": Union = None"},{name:"tokenizer",val:": Optional = None"},{name:"text_encoder",val:": Optional = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code> or <code>List[str or os.PathLike]</code> or <code>Dict</code> or <code>List[Dict]</code>) &#x2014;
Can be either one of the following or a list of them:</p>
<ul>
<li>A string, the <em>model id</em> (for example <code>sd-concepts-library/low-poly-hd-logos-icons</code>) of a
pretrained model hosted on the Hub.</li>
<li>A path to a <em>directory</em> (for example <code>./my_text_inversion_directory/</code>) containing the textual
inversion weights.</li>
<li>A path to a <em>file</em> (for example <code>./my_text_inversions.pt</code>) containing textual inversion weights.</li>
<li>A <a href="https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict" rel="nofollow">torch state
dict</a>.</li>
</ul>`,name:"pretrained_model_name_or_path"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.token",description:`<strong>token</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
Override the token to use for the textual inversion weights. If <code>pretrained_model_name_or_path</code> is a
list, then <code>token</code> must also be a list of equal length.`,name:"token"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>, <em>optional</em>) &#x2014;
Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a>).
If not specified, function will take self.tokenizer.`,name:"text_encoder"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>, <em>optional</em>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text. If not specified, function will take self.tokenizer.`,name:"tokenizer"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.weight_name",description:`<strong>weight_name</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Name of a custom weight file. This should be used when:</p>
<ul>
<li>The saved textual inversion file is in &#x1F917; Diffusers format, but was saved under a specific weight
name such as <code>text_inv.bin</code>.</li>
<li>The saved textual inversion file is in the Automatic1111 format.</li>
</ul>`,name:"weight_name"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.cache_dir",description:`<strong>cache_dir</strong> (<code>Union[str, os.PathLike]</code>, <em>optional</em>) &#x2014;
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
is not used.`,name:"cache_dir"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.force_download",description:`<strong>force_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
cached versions if they exist.`,name:"force_download"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.resume_download",description:`<strong>resume_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to resume downloading the model weights and configuration files. If set to <code>False</code>, any
incompletely downloaded files are deleted.`,name:"resume_download"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.proxies",description:`<strong>proxies</strong> (<code>Dict[str, str]</code>, <em>optional</em>) &#x2014;
A dictionary of proxy servers to use by protocol or endpoint, for example, <code>{&apos;http&apos;: &apos;foo.bar:3128&apos;, &apos;http://hostname&apos;: &apos;foo.bar:4012&apos;}</code>. The proxies are used on each request.`,name:"proxies"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.local_files_only",description:`<strong>local_files_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to only load local model weights and configuration files or not. If set to <code>True</code>, the model
won&#x2019;t be downloaded from the Hub.`,name:"local_files_only"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.token",description:`<strong>token</strong> (<code>str</code> or <em>bool</em>, <em>optional</em>) &#x2014;
The token to use as HTTP bearer authorization for remote files. If <code>True</code>, the token generated from
<code>diffusers-cli login</code> (stored in <code>~/.huggingface</code>) is used.`,name:"token"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;main&quot;</code>) &#x2014;
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
allowed by Git.`,name:"revision"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.subfolder",description:`<strong>subfolder</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&quot;</code>) &#x2014;
The subfolder location of a model file within a larger model repository on the Hub or locally.`,name:"subfolder"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.mirror",description:`<strong>mirror</strong> (<code>str</code>, <em>optional</em>) &#x2014;
Mirror source to resolve accessibility issues if you&#x2019;re downloading a model in China. We do not
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
information.`,name:"mirror"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L265"}}),J=new xe({props:{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example",$$slots:{default:[Ie]},$$scope:{ctx:k}}}),C=new xe({props:{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example-2",$$slots:{default:[ke]},$$scope:{ctx:k}}}),Y=new ie({props:{name:"maybe_convert_prompt",anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt",parameters:[{name:"prompt",val:": Union"},{name:"tokenizer",val:": PreTrainedTokenizer"}],parametersDescription:[{anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or list of <code>str</code>) &#x2014;
The prompt or prompts to guide the image generation.`,name:"prompt"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt.tokenizer",description:`<strong>tokenizer</strong> (<code>PreTrainedTokenizer</code>) &#x2014;
The tokenizer responsible for encoding the prompt into input tokens.`,name:"tokenizer"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/loaders/textual_inversion.py#L117",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The converted prompt</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>str</code> or list of <code>str</code></p>
`}}),{c(){o=f("meta"),g=i(),s=f("p"),a=i(),b(c.$$.fragment),t=i(),h=f("p"),h.textContent=de,S=i(),Z=f("p"),Z.innerHTML=ce,X=i(),b(U.$$.fragment),V=i(),b(j.$$.fragment),D=i(),v=f("div"),b(N.$$.fragment),K=i(),G=f("p"),G.textContent=pe,O=i(),m=f("div"),b(W.$$.fragment),ee=i(),H=f("p"),H.innerHTML=me,te=i(),R=f("p"),R.textContent=fe,oe=i(),b(J.$$.fragment),ne=i(),z=f("p"),z.innerHTML=ue,re=i(),b(C.$$.fragment),ae=i(),L=f("div"),b(Y.$$.fragment),se=i(),P=f("p"),P.textContent=he,Q=i(),F=f("p"),this.h()},l(e){const n=Te("svelte-u9bgzb",document.head);o=u(n,"META",{name:!0,content:!0}),n.forEach(r),g=l(e),s=u(e,"P",{}),q(s).forEach(r),a=l(e),y(c.$$.fragment,e),t=l(e),h=u(e,"P",{"data-svelte-h":!0}),I(h)!=="svelte-17iorh0"&&(h.textContent=de),S=l(e),Z=u(e,"P",{"data-svelte-h":!0}),I(Z)!=="svelte-16c4ckr"&&(Z.innerHTML=ce),X=l(e),y(U.$$.fragment,e),V=l(e),y(j.$$.fragment,e),D=l(e),v=u(e,"DIV",{class:!0});var _=q(v);y(N.$$.fragment,_),K=l(_),G=u(_,"P",{"data-svelte-h":!0}),I(G)!=="svelte-7bntze"&&(G.textContent=pe),O=l(_),m=u(_,"DIV",{class:!0});var x=q(m);y(W.$$.fragment,x),ee=l(x),H=u(x,"P",{"data-svelte-h":!0}),I(H)!=="svelte-1lv88wo"&&(H.innerHTML=me),te=l(x),R=u(x,"P",{"data-svelte-h":!0}),I(R)!=="svelte-11lpom8"&&(R.textContent=fe),oe=l(x),y(J.$$.fragment,x),ne=l(x),z=u(x,"P",{"data-svelte-h":!0}),I(z)!=="svelte-15d7mv5"&&(z.innerHTML=ue),re=l(x),y(C.$$.fragment,x),x.forEach(r),ae=l(_),L=u(_,"DIV",{class:!0});var B=q(L);y(Y.$$.fragment,B),se=l(B),P=u(B,"P",{"data-svelte-h":!0}),I(P)!=="svelte-gjjmbb"&&(P.textContent=he),B.forEach(r),_.forEach(r),Q=l(e),F=u(e,"P",{}),q(F).forEach(r),this.h()},h(){E(o,"name","hf:doc:metadata"),E(o,"content",Je),E(m,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),E(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,n){p(document.head,o),d(e,g,n),d(e,s,n),d(e,a,n),M(c,e,n),d(e,t,n),d(e,h,n),d(e,S,n),d(e,Z,n),d(e,X,n),M(U,e,n),d(e,V,n),M(j,e,n),d(e,D,n),d(e,v,n),M(N,v,null),p(v,K),p(v,G),p(v,O),p(v,m),M(W,m,null),p(m,ee),p(m,H),p(m,te),p(m,R),p(m,oe),M(J,m,null),p(m,ne),p(m,z),p(m,re),M(C,m,null),p(v,ae),p(v,L),M(Y,L,null),p(L,se),p(L,P),d(e,Q,n),d(e,F,n),A=!0},p(e,[n]){const _={};n&2&&(_.$$scope={dirty:n,ctx:e}),U.$set(_);const x={};n&2&&(x.$$scope={dirty:n,ctx:e}),J.$set(x);const B={};n&2&&(B.$$scope={dirty:n,ctx:e}),C.$set(B)},i(e){A||(T(c.$$.fragment,e),T(U.$$.fragment,e),T(j.$$.fragment,e),T(N.$$.fragment,e),T(W.$$.fragment,e),T(J.$$.fragment,e),T(C.$$.fragment,e),T(Y.$$.fragment,e),A=!0)},o(e){w(c.$$.fragment,e),w(U.$$.fragment,e),w(j.$$.fragment,e),w(N.$$.fragment,e),w(W.$$.fragment,e),w(J.$$.fragment,e),w(C.$$.fragment,e),w(Y.$$.fragment,e),A=!1},d(e){e&&(r(g),r(s),r(a),r(t),r(h),r(S),r(Z),r(X),r(V),r(D),r(v),r(Q),r(F)),r(o),$(c,e),$(U,e),$(j,e),$(N),$(W),$(J),$(C),$(Y)}}}const Je='{"title":"Textual Inversion","local":"textual-inversion","sections":[{"title":"TextualInversionLoaderMixin","local":"diffusers.loaders.TextualInversionLoaderMixin","sections":[],"depth":2}],"depth":1}';function Ce(k){return be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ge extends ye{constructor(o){super(),Me(this,o,Ce,Ue,_e,{})}}export{Ge as component};
