import{s as Ae,n as Ke,o as Oe}from"../chunks/scheduler.6e0d5ff7.js";import{S as et,i as tt,g as p,s as i,r as m,E as lt,h as a,f as l,c as n,j as De,u as f,x as o,k as qe,y as st,a as s,v as r,d as u,t as c,w as b}from"../chunks/index.d7c1b260.js";import{C as S}from"../chunks/CodeBlock.09a08494.js";import{D as it}from"../chunks/DocNotebookDropdown.b1b23d60.js";import{H as Qe,E as nt}from"../chunks/EditOnGithub.733546da.js";function pt(ke){let d,q,F,Q,h,A,g,K,w,Ue=`텍스트 가이드 기반의 diffusion 모델은 주어진 텍스트 프롬프트를 기반으로 이미지를 생성합니다.
텍스트 프롬프트에는 모델이 생성해야 하는 여러 개념이 포함될 수 있으며 프롬프트의 특정 부분에 가중치를 부여하는 것이 바람직한 경우가 많습니다.`,O,M,Ge=`Diffusion 모델은 문맥화된 텍스트 임베딩으로 diffusion 모델의 cross attention 레이어를 조절함으로써 작동합니다.
(<a href="https://huggingface.co/docs/optimum-neuron/main/en/package_reference/modeling#stable-diffusion" rel="nofollow">더 많은 정보를 위한 Stable Diffusion Guide</a>를 참고하세요).
따라서 프롬프트의 특정 부분을 강조하는(또는 강조하지 않는) 간단한 방법은 프롬프트의 관련 부분에 해당하는 텍스트 임베딩 벡터의 크기를 늘리거나 줄이는 것입니다.
이것은 “프롬프트 가중치 부여” 라고 하며, 커뮤니티에서 가장 요구하는 기능입니다.(<a href="https://github.com/huggingface/diffusers/issues/2431" rel="nofollow">이곳</a>의 issue를 보세요 ).`,ee,T,te,y,Ve=`우리는 <code>diffusers</code>의 역할이 다른 프로젝트를 가능하게 하는 필수적인 기능을 제공하는 toolbex라고 생각합니다.
<a href="https://github.com/invoke-ai/InvokeAI" rel="nofollow">InvokeAI</a> 나 <a href="https://github.com/abhishekkrthakur/diffuzers" rel="nofollow">diffuzers</a> 같은 강력한 UI를 구축할 수 있습니다.
프롬프트를 조작하는 방법을 지원하기 위해, <code>diffusers</code> 는
<a href="https://huggingface.co/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline" rel="nofollow">StableDiffusionPipeline</a>와 같은
많은 파이프라인에 <a href="https://huggingface.co/docs/diffusers/v0.14.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline.__call__.prompt_embeds" rel="nofollow">prompt_embeds</a>
인수를 노출시켜, “prompt-weighted”/축척된 텍스트 임베딩을 파이프라인에 바로 전달할 수 있게 합니다.`,le,$,He=`<a href="https://github.com/damian0815/compel" rel="nofollow">Compel 라이브러리</a>는 프롬프트의 일부를 강조하거나 강조하지 않을 수 있는 쉬운 방법을 제공합니다.
임베딩을 직접 준비하는 것 대신 이 방법을 사용하는 것을 강력히 추천합니다.`,se,v,xe=`간단한 예제를 살펴보겠습니다.
다음과 같이 <code>&quot;공을 갖고 노는 붉은색 고양이&quot;</code> 이미지를 생성하고 싶습니다:`,ie,_,ne,J,Ie="생성된 이미지:",pe,C,je='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_0.png" alt="img"/>',ae,Z,Be="사진에서 알 수 있듯이, “공”은 이미지에 없습니다. 이 부분을 강조해 볼까요!",oe,k,Xe="먼저 <code>compel</code> 라이브러리를 설치해야합니다:",me,U,fe,G,We="그런 다음에는 <code>Compel</code> 오브젝트를 생성합니다:",re,V,ue,H,Ne="이제 <code>&quot;++&quot;</code> 를 사용해서 “공” 을 강조해 봅시다:",ce,x,be,I,Ee="그리고 이 프롬프트를 파이프라인에 바로 전달하지 않고, <code>compel_proc</code> 를 사용하여 처리해야합니다:",de,j,he,B,Le="파이프라인에 <code>prompt_embeds</code> 를 바로 전달할 수 있습니다:",ge,X,we,W,Pe="이제 “공”이 있는 그림을 출력할 수 있습니다!",Me,N,ze='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_1.png" alt="img"/>',Te,E,Re="마찬가지로 <code>--</code> 접미사를 단어에 사용하여 문장의 일부를 강조하지 않을 수 있습니다. 한번 시도해 보세요!",ye,L,Ye=`즐겨찾는 파이프라인에 <code>prompt_embeds</code> 입력이 없는 경우 issue를 새로 만들어주세요.
Diffusers 팀은 최대한 대응하려고 노력합니다.`,$e,P,Se=`Compel 1.1.6 는 textual inversions을 사용하여 단순화하는 유티릴티 클래스를 추가합니다.
<code>DiffusersTextualInversionManager</code>를 인스턴스화 한 후 이를 Compel init에 전달합니다:`,ve,z,_e,R,Fe='더 많은 정보를 얻고 싶다면 <a href="https://github.com/damian0815/compel" rel="nofollow">compel</a> 라이브러리 문서를 참고하세요.',Je,Y,Ce,D,Ze;return h=new Qe({props:{title:"프롬프트에 가중치 부여하기",local:"프롬프트에-가중치-부여하기",headingTag:"h1"}}),g=new it({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/weighted_prompts.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/weighted_prompts.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/weighted_prompts.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/weighted_prompts.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/weighted_prompts.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/weighted_prompts.ipynb"}]}}),T=new Qe({props:{title:"Diffusers에서 프롬프트 가중치 부여하는 방법",local:"diffusers에서-프롬프트-가중치-부여하는-방법",headingTag:"h2"}}),_=new S({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTJDJTIwVW5pUENNdWx0aXN0ZXBTY2hlZHVsZXIlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIpJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBVbmlQQ011bHRpc3RlcFNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWcpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyYSUyMHJlZCUyMGNhdCUyMHBsYXlpbmclMjB3aXRoJTIwYSUyMGJhbGwlMjIlMEElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5HZW5lcmF0b3IoZGV2aWNlJTNEJTIyY3B1JTIyKS5tYW51YWxfc2VlZCgzMyklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2U=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline, UniPCMultistepScheduler

pipe = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

prompt = <span class="hljs-string">&quot;a red cat playing with a ball&quot;</span>

generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">33</span>)

image = pipe(prompt, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
image`,wrap:!1}}),U=new S({props:{code:"cGlwJTIwaW5zdGFsbCUyMGNvbXBlbA==",highlighted:"pip install compel",wrap:!1}}),V=new S({props:{code:"ZnJvbSUyMGNvbXBlbCUyMGltcG9ydCUyMENvbXBlbCUwQSUwQWNvbXBlbF9wcm9jJTIwJTNEJTIwQ29tcGVsKHRva2VuaXplciUzRHBpcGUudG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyJTNEcGlwZS50ZXh0X2VuY29kZXIp",highlighted:`<span class="hljs-keyword">from</span> compel <span class="hljs-keyword">import</span> Compel

compel_proc = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)`,wrap:!1}}),x=new S({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyYSUyMHJlZCUyMGNhdCUyMHBsYXlpbmclMjB3aXRoJTIwYSUyMGJhbGwlMkIlMkIlMjI=",highlighted:'prompt = <span class="hljs-string">&quot;a red cat playing with a ball++&quot;</span>',wrap:!1}}),j=new S({props:{code:"cHJvbXB0X2VtYmVkcyUyMCUzRCUyMGNvbXBlbF9wcm9jKHByb21wdCk=",highlighted:"prompt_embeds = compel_proc(prompt)",wrap:!1}}),X=new S({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmNwdSUyMikubWFudWFsX3NlZWQoMzMpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZShwcm9tcHRfZW1iZWRzJTNEcHJvbXB0X2VtYmVkcyUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCkuaW1hZ2VzJTVCMCU1RCUwQWltYWdl",highlighted:`generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">33</span>)

images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
image`,wrap:!1}}),z=new S({props:{code:"dGV4dHVhbF9pbnZlcnNpb25fbWFuYWdlciUyMCUzRCUyMERpZmZ1c2Vyc1RleHR1YWxJbnZlcnNpb25NYW5hZ2VyKHBpcGUpJTBBY29tcGVsJTIwJTNEJTIwQ29tcGVsKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHBpcGUudG9rZW5pemVyJTJDJTBBJTIwJTIwJTIwJTIwdGV4dF9lbmNvZGVyJTNEcGlwZS50ZXh0X2VuY29kZXIlMkMlMEElMjAlMjAlMjAlMjB0ZXh0dWFsX2ludmVyc2lvbl9tYW5hZ2VyJTNEdGV4dHVhbF9pbnZlcnNpb25fbWFuYWdlcik=",highlighted:`<span class="hljs-attr">textual_inversion_manager</span> = DiffusersTextualInversionManager(pipe)
<span class="hljs-attr">compel</span> = Compel(
    <span class="hljs-attr">tokenizer</span>=pipe.tokenizer,
    <span class="hljs-attr">text_encoder</span>=pipe.text_encoder,
    <span class="hljs-attr">textual_inversion_manager</span>=textual_inversion_manager)`,wrap:!1}}),Y=new nt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/using-diffusers/weighted_prompts.md"}}),{c(){d=p("meta"),q=i(),F=p("p"),Q=i(),m(h.$$.fragment),A=i(),m(g.$$.fragment),K=i(),w=p("p"),w.textContent=Ue,O=i(),M=p("p"),M.innerHTML=Ge,ee=i(),m(T.$$.fragment),te=i(),y=p("p"),y.innerHTML=Ve,le=i(),$=p("p"),$.innerHTML=He,se=i(),v=p("p"),v.innerHTML=xe,ie=i(),m(_.$$.fragment),ne=i(),J=p("p"),J.textContent=Ie,pe=i(),C=p("p"),C.innerHTML=je,ae=i(),Z=p("p"),Z.textContent=Be,oe=i(),k=p("p"),k.innerHTML=Xe,me=i(),m(U.$$.fragment),fe=i(),G=p("p"),G.innerHTML=We,re=i(),m(V.$$.fragment),ue=i(),H=p("p"),H.innerHTML=Ne,ce=i(),m(x.$$.fragment),be=i(),I=p("p"),I.innerHTML=Ee,de=i(),m(j.$$.fragment),he=i(),B=p("p"),B.innerHTML=Le,ge=i(),m(X.$$.fragment),we=i(),W=p("p"),W.textContent=Pe,Me=i(),N=p("p"),N.innerHTML=ze,Te=i(),E=p("p"),E.innerHTML=Re,ye=i(),L=p("p"),L.innerHTML=Ye,$e=i(),P=p("p"),P.innerHTML=Se,ve=i(),m(z.$$.fragment),_e=i(),R=p("p"),R.innerHTML=Fe,Je=i(),m(Y.$$.fragment),Ce=i(),D=p("p"),this.h()},l(e){const t=lt("svelte-u9bgzb",document.head);d=a(t,"META",{name:!0,content:!0}),t.forEach(l),q=n(e),F=a(e,"P",{}),De(F).forEach(l),Q=n(e),f(h.$$.fragment,e),A=n(e),f(g.$$.fragment,e),K=n(e),w=a(e,"P",{"data-svelte-h":!0}),o(w)!=="svelte-6zgx2k"&&(w.textContent=Ue),O=n(e),M=a(e,"P",{"data-svelte-h":!0}),o(M)!=="svelte-jymdy2"&&(M.innerHTML=Ge),ee=n(e),f(T.$$.fragment,e),te=n(e),y=a(e,"P",{"data-svelte-h":!0}),o(y)!=="svelte-1tfiuem"&&(y.innerHTML=Ve),le=n(e),$=a(e,"P",{"data-svelte-h":!0}),o($)!=="svelte-3a9pj9"&&($.innerHTML=He),se=n(e),v=a(e,"P",{"data-svelte-h":!0}),o(v)!=="svelte-sndxnq"&&(v.innerHTML=xe),ie=n(e),f(_.$$.fragment,e),ne=n(e),J=a(e,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1kk09o0"&&(J.textContent=Ie),pe=n(e),C=a(e,"P",{"data-svelte-h":!0}),o(C)!=="svelte-lhtk1n"&&(C.innerHTML=je),ae=n(e),Z=a(e,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-1j2une0"&&(Z.textContent=Be),oe=n(e),k=a(e,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1uy3q6o"&&(k.innerHTML=Xe),me=n(e),f(U.$$.fragment,e),fe=n(e),G=a(e,"P",{"data-svelte-h":!0}),o(G)!=="svelte-1181b2z"&&(G.innerHTML=We),re=n(e),f(V.$$.fragment,e),ue=n(e),H=a(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-1ilrue"&&(H.innerHTML=Ne),ce=n(e),f(x.$$.fragment,e),be=n(e),I=a(e,"P",{"data-svelte-h":!0}),o(I)!=="svelte-1fd9ba2"&&(I.innerHTML=Ee),de=n(e),f(j.$$.fragment,e),he=n(e),B=a(e,"P",{"data-svelte-h":!0}),o(B)!=="svelte-s5my9t"&&(B.innerHTML=Le),ge=n(e),f(X.$$.fragment,e),we=n(e),W=a(e,"P",{"data-svelte-h":!0}),o(W)!=="svelte-1szos4z"&&(W.textContent=Pe),Me=n(e),N=a(e,"P",{"data-svelte-h":!0}),o(N)!=="svelte-rm5ydw"&&(N.innerHTML=ze),Te=n(e),E=a(e,"P",{"data-svelte-h":!0}),o(E)!=="svelte-1cz1utb"&&(E.innerHTML=Re),ye=n(e),L=a(e,"P",{"data-svelte-h":!0}),o(L)!=="svelte-1837j6q"&&(L.innerHTML=Ye),$e=n(e),P=a(e,"P",{"data-svelte-h":!0}),o(P)!=="svelte-1te8sqt"&&(P.innerHTML=Se),ve=n(e),f(z.$$.fragment,e),_e=n(e),R=a(e,"P",{"data-svelte-h":!0}),o(R)!=="svelte-1n4pw6m"&&(R.innerHTML=Fe),Je=n(e),f(Y.$$.fragment,e),Ce=n(e),D=a(e,"P",{}),De(D).forEach(l),this.h()},h(){qe(d,"name","hf:doc:metadata"),qe(d,"content",at)},m(e,t){st(document.head,d),s(e,q,t),s(e,F,t),s(e,Q,t),r(h,e,t),s(e,A,t),r(g,e,t),s(e,K,t),s(e,w,t),s(e,O,t),s(e,M,t),s(e,ee,t),r(T,e,t),s(e,te,t),s(e,y,t),s(e,le,t),s(e,$,t),s(e,se,t),s(e,v,t),s(e,ie,t),r(_,e,t),s(e,ne,t),s(e,J,t),s(e,pe,t),s(e,C,t),s(e,ae,t),s(e,Z,t),s(e,oe,t),s(e,k,t),s(e,me,t),r(U,e,t),s(e,fe,t),s(e,G,t),s(e,re,t),r(V,e,t),s(e,ue,t),s(e,H,t),s(e,ce,t),r(x,e,t),s(e,be,t),s(e,I,t),s(e,de,t),r(j,e,t),s(e,he,t),s(e,B,t),s(e,ge,t),r(X,e,t),s(e,we,t),s(e,W,t),s(e,Me,t),s(e,N,t),s(e,Te,t),s(e,E,t),s(e,ye,t),s(e,L,t),s(e,$e,t),s(e,P,t),s(e,ve,t),r(z,e,t),s(e,_e,t),s(e,R,t),s(e,Je,t),r(Y,e,t),s(e,Ce,t),s(e,D,t),Ze=!0},p:Ke,i(e){Ze||(u(h.$$.fragment,e),u(g.$$.fragment,e),u(T.$$.fragment,e),u(_.$$.fragment,e),u(U.$$.fragment,e),u(V.$$.fragment,e),u(x.$$.fragment,e),u(j.$$.fragment,e),u(X.$$.fragment,e),u(z.$$.fragment,e),u(Y.$$.fragment,e),Ze=!0)},o(e){c(h.$$.fragment,e),c(g.$$.fragment,e),c(T.$$.fragment,e),c(_.$$.fragment,e),c(U.$$.fragment,e),c(V.$$.fragment,e),c(x.$$.fragment,e),c(j.$$.fragment,e),c(X.$$.fragment,e),c(z.$$.fragment,e),c(Y.$$.fragment,e),Ze=!1},d(e){e&&(l(q),l(F),l(Q),l(A),l(K),l(w),l(O),l(M),l(ee),l(te),l(y),l(le),l($),l(se),l(v),l(ie),l(ne),l(J),l(pe),l(C),l(ae),l(Z),l(oe),l(k),l(me),l(fe),l(G),l(re),l(ue),l(H),l(ce),l(be),l(I),l(de),l(he),l(B),l(ge),l(we),l(W),l(Me),l(N),l(Te),l(E),l(ye),l(L),l($e),l(P),l(ve),l(_e),l(R),l(Je),l(Ce),l(D)),l(d),b(h,e),b(g,e),b(T,e),b(_,e),b(U,e),b(V,e),b(x,e),b(j,e),b(X,e),b(z,e),b(Y,e)}}}const at='{"title":"프롬프트에 가중치 부여하기","local":"프롬프트에-가중치-부여하기","sections":[{"title":"Diffusers에서 프롬프트 가중치 부여하는 방법","local":"diffusers에서-프롬프트-가중치-부여하는-방법","sections":[],"depth":2}],"depth":1}';function ot(ke){return Oe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class bt extends et{constructor(d){super(),tt(this,d,ot,pt,Ae,{})}}export{bt as component};
