import{s as _e,o as ye,n as le}from"../chunks/scheduler.182ea377.js";import{S as be,i as Te,g as u,s as i,r as y,A as Me,h as f,f as r,c as l,j as q,u as b,x as k,k as E,y as p,a as d,v as T,d as M,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 ge}from"../chunks/ExampleCodeBlock.658f5cd6.js";import{H as xe}from"../chunks/Heading.16916d63.js";function $e(I){let o,x='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=u("p"),o.innerHTML=x},l(s){o=f(s,"P",{"data-svelte-h":!0}),k(o)!=="svelte-1n8qarv"&&(o.innerHTML=x)},m(s,a){d(s,o,a)},p:le,d(s){s&&r(o)}}}function ke(I){let o,x="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=u("p"),o.textContent=x,s=i(),y(a.$$.fragment)},l(t){o=f(t,"P",{"data-svelte-h":!0}),k(o)!=="svelte-1gc783q"&&(o.textContent=x),s=l(t),b(a.$$.fragment,t)},m(t,h){d(t,o,h),d(t,s,h),T(a,t,h),c=!0},p:le,i(t){c||(M(a.$$.fragment,t),c=!0)},o(t){w(a.$$.fragment,t),c=!1},d(t){t&&(r(o),r(s)),$(a,t)}}}function Ie(I){let o,x="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=u("p"),o.textContent=x,s=i(),y(a.$$.fragment)},l(t){o=f(t,"P",{"data-svelte-h":!0}),k(o)!=="svelte-4c75kq"&&(o.textContent=x),s=l(t),b(a.$$.fragment,t)},m(t,h){d(t,o,h),d(t,s,h),T(a,t,h),c=!0},p:le,i(t){c||(M(a.$$.fragment,t),c=!0)},o(t){w(a.$$.fragment,t),c=!1},d(t){t&&(r(o),r(s)),$(a,t)}}}function Ue(I){let o,x,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,D,j,V,v,N,K,B,pe="Load Textual Inversion tokens and embeddings to the tokenizer and text encoder.",O,m,W,ee,G,me=`Load Textual Inversion embeddings into the text encoder of <a href="/docs/diffusers/v0.24.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> (both 🤗 Diffusers and
Automatic1111 formats are supported).`,te,H,ue="Example:",oe,J,ne,P,fe=`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,z,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 xe({props:{title:"Textual Inversion",local:"textual-inversion",headingTag:"h1"}}),U=new we({props:{$$slots:{default:[$e]},$$scope:{ctx:I}}}),j=new xe({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/v0.24.0/src/diffusers/loaders/textual_inversion.py#L117"}}),W=new ie({props:{name:"load_textual_inversion",anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion",parameters:[{name:"pretrained_model_name_or_path",val:": typing.Union[str, typing.List[str], typing.Dict[str, torch.Tensor], typing.List[typing.Dict[str, torch.Tensor]]]"},{name:"token",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"tokenizer",val:": typing.Optional[ForwardRef('PreTrainedTokenizer')] = None"},{name:"text_encoder",val:": typing.Optional[ForwardRef('PreTrainedModel')] = 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/v4.35.2/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/v4.35.2/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.use_auth_token",description:`<strong>use_auth_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:"use_auth_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/v0.24.0/src/diffusers/loaders/textual_inversion.py#L270"}}),J=new ge({props:{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example",$$slots:{default:[ke]},$$scope:{ctx:I}}}),C=new ge({props:{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example-2",$$slots:{default:[Ie]},$$scope:{ctx:I}}}),Y=new ie({props:{name:"maybe_convert_prompt",anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{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/v0.24.0/src/diffusers/loaders/textual_inversion.py#L122",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=u("meta"),x=i(),s=u("p"),a=i(),y(c.$$.fragment),t=i(),h=u("p"),h.textContent=de,S=i(),Z=u("p"),Z.innerHTML=ce,X=i(),y(U.$$.fragment),D=i(),y(j.$$.fragment),V=i(),v=u("div"),y(N.$$.fragment),K=i(),B=u("p"),B.textContent=pe,O=i(),m=u("div"),y(W.$$.fragment),ee=i(),G=u("p"),G.innerHTML=me,te=i(),H=u("p"),H.textContent=ue,oe=i(),y(J.$$.fragment),ne=i(),P=u("p"),P.innerHTML=fe,re=i(),y(C.$$.fragment),ae=i(),L=u("div"),y(Y.$$.fragment),se=i(),z=u("p"),z.textContent=he,Q=i(),F=u("p"),this.h()},l(e){const n=Me("svelte-u9bgzb",document.head);o=f(n,"META",{name:!0,content:!0}),n.forEach(r),x=l(e),s=f(e,"P",{}),q(s).forEach(r),a=l(e),b(c.$$.fragment,e),t=l(e),h=f(e,"P",{"data-svelte-h":!0}),k(h)!=="svelte-17iorh0"&&(h.textContent=de),S=l(e),Z=f(e,"P",{"data-svelte-h":!0}),k(Z)!=="svelte-16c4ckr"&&(Z.innerHTML=ce),X=l(e),b(U.$$.fragment,e),D=l(e),b(j.$$.fragment,e),V=l(e),v=f(e,"DIV",{class:!0});var _=q(v);b(N.$$.fragment,_),K=l(_),B=f(_,"P",{"data-svelte-h":!0}),k(B)!=="svelte-7bntze"&&(B.textContent=pe),O=l(_),m=f(_,"DIV",{class:!0});var g=q(m);b(W.$$.fragment,g),ee=l(g),G=f(g,"P",{"data-svelte-h":!0}),k(G)!=="svelte-db5xiv"&&(G.innerHTML=me),te=l(g),H=f(g,"P",{"data-svelte-h":!0}),k(H)!=="svelte-11lpom8"&&(H.textContent=ue),oe=l(g),b(J.$$.fragment,g),ne=l(g),P=f(g,"P",{"data-svelte-h":!0}),k(P)!=="svelte-15d7mv5"&&(P.innerHTML=fe),re=l(g),b(C.$$.fragment,g),g.forEach(r),ae=l(_),L=f(_,"DIV",{class:!0});var R=q(L);b(Y.$$.fragment,R),se=l(R),z=f(R,"P",{"data-svelte-h":!0}),k(z)!=="svelte-gjjmbb"&&(z.textContent=he),R.forEach(r),_.forEach(r),Q=l(e),F=f(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,x,n),d(e,s,n),d(e,a,n),T(c,e,n),d(e,t,n),d(e,h,n),d(e,S,n),d(e,Z,n),d(e,X,n),T(U,e,n),d(e,D,n),T(j,e,n),d(e,V,n),d(e,v,n),T(N,v,null),p(v,K),p(v,B),p(v,O),p(v,m),T(W,m,null),p(m,ee),p(m,G),p(m,te),p(m,H),p(m,oe),T(J,m,null),p(m,ne),p(m,P),p(m,re),T(C,m,null),p(v,ae),p(v,L),T(Y,L,null),p(L,se),p(L,z),d(e,Q,n),d(e,F,n),A=!0},p(e,[n]){const _={};n&2&&(_.$$scope={dirty:n,ctx:e}),U.$set(_);const g={};n&2&&(g.$$scope={dirty:n,ctx:e}),J.$set(g);const R={};n&2&&(R.$$scope={dirty:n,ctx:e}),C.$set(R)},i(e){A||(M(c.$$.fragment,e),M(U.$$.fragment,e),M(j.$$.fragment,e),M(N.$$.fragment,e),M(W.$$.fragment,e),M(J.$$.fragment,e),M(C.$$.fragment,e),M(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(x),r(s),r(a),r(t),r(h),r(S),r(Z),r(X),r(D),r(V),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(I){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Be extends be{constructor(o){super(),Te(this,o,Ce,Ue,_e,{})}}export{Be as component};
