import{S as Fr,i as Hr,s as zr,e as s,k as h,w as E,t as n,N as Vr,c as a,d as r,m as c,a as l,x as j,h as i,b as o,G as t,g as f,y as _,L as Qr,q as $,o as x,B as M,v as Dr}from"../chunks/vendor-hf-doc-builder.js";import{I as Je}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as ft}from"../chunks/CodeBlock-hf-doc-builder.js";function Lr(fr){let d,Ie,y,T,ue,C,ht,Z,ct,me,ut,mt,Ae,U,dt,Y,yt,vt,Se,v,k,de,R,wt,F,gt,ye,bt,Et,Pe,u,jt,ve,_t,$t,H,xt,Mt,We,w,J,we,z,Tt,ge,Ut,Ne,I,kt,be,Jt,It,Be,A,V,Q,Ee,At,St,D,je,Pt,Wt,L,_e,O,Nt,$e,X,Ge,S,Bt,xe,Gt,Ct,Ce,q,Ze,P,Zt,K,Yt,Rt,Ye,g,W,Me,ee,Ft,Te,Ht,Re,N,zt,te,Vt,Qt,Fe,re,He,B,Dt,se,Lt,Ot,ze,b,G,Ue,ae,Xt,ke,qt,Ve,m,ie,Kt,le,er,tr,pe,rr,oe,sr,ar,fe,lr,ne,or,Qe;return C=new Je({}),R=new Je({}),z=new Je({}),O=new ft({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTIzJTIwQWxsb2NhdGUlMjBhJTIwcGlwZWxpbmUlMjBmb3IlMjBzZW50aW1lbnQtYW5hbHlzaXMlMEFwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJ3NlbnRpbWVudC1hbmFseXNpcycpJTBBJTBBb3V0JTIwJTNEJTIwcGlwZSgnSSUyMGxvdmUlMjB0cmFuc2Zvcm1lcnMhJyklMEElMjMlMjAlNUIlN0InbGFiZWwnJTNBJTIwJ1BPU0lUSVZFJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5OTgwNjk0MSU3RCU1RA==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-comment"># Allocate a pipeline for sentiment-analysis</span>
pipe = pipeline(<span class="hljs-string">&#x27;sentiment-analysis&#x27;</span>)

out = pipe(<span class="hljs-string">&#x27;I love transformers!&#x27;</span>)
<span class="hljs-comment"># [{&#x27;label&#x27;: &#x27;POSITIVE&#x27;, &#x27;score&#x27;: 0.999806941}]</span>`}}),X=new ft({props:{code:"aW1wb3J0JTIwJTdCJTIwcGlwZWxpbmUlMjAlN0QlMjBmcm9tJTIwJyU0MHhlbm92YSUyRnRyYW5zZm9ybWVycyclM0IlMEElMEElMkYlMkYlMjBBbGxvY2F0ZSUyMGElMjBwaXBlbGluZSUyMGZvciUyMHNlbnRpbWVudC1hbmFseXNpcyUwQWxldCUyMHBpcGUlMjAlM0QlMjBhd2FpdCUyMHBpcGVsaW5lKCdzZW50aW1lbnQtYW5hbHlzaXMnKSUzQiUwQSUwQWxldCUyMG91dCUyMCUzRCUyMGF3YWl0JTIwcGlwZSgnSSUyMGxvdmUlMjB0cmFuc2Zvcm1lcnMhJyklM0IlMEElMkYlMkYlMjAlNUIlN0InbGFiZWwnJTNBJTIwJ1BPU0lUSVZFJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5OTgxNzY4NiU3RCU1RA==",highlighted:`<span class="hljs-keyword">import</span> { pipeline } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@xenova/transformers&#x27;</span>;

<span class="hljs-comment">// Allocate a pipeline for sentiment-analysis</span>
<span class="hljs-keyword">let</span> pipe = <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipeline</span>(<span class="hljs-string">&#x27;sentiment-analysis&#x27;</span>);

<span class="hljs-keyword">let</span> out = <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipe</span>(<span class="hljs-string">&#x27;I love transformers!&#x27;</span>);
<span class="hljs-comment">// [{&#x27;label&#x27;: &#x27;POSITIVE&#x27;, &#x27;score&#x27;: 0.999817686}]</span>`}}),q=new ft({props:{code:"JTJGJTJGJTIwVXNlJTIwYSUyMGRpZmZlcmVudCUyMG1vZGVsJTIwZm9yJTIwc2VudGltZW50LWFuYWx5c2lzJTBBbGV0JTIwcGlwZSUyMCUzRCUyMGF3YWl0JTIwcGlwZWxpbmUoJ3NlbnRpbWVudC1hbmFseXNpcyclMkMlMjAnbmxwdG93biUyRmJlcnQtYmFzZS1tdWx0aWxpbmd1YWwtdW5jYXNlZC1zZW50aW1lbnQnKSUzQg==",highlighted:`<span class="hljs-comment">// Use a different model for sentiment-analysis</span>
<span class="hljs-keyword">let</span> pipe = <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipeline</span>(<span class="hljs-string">&#x27;sentiment-analysis&#x27;</span>, <span class="hljs-string">&#x27;nlptown/bert-base-multilingual-uncased-sentiment&#x27;</span>);`}}),ee=new Je({}),re=new ft({props:{code:"bnBtJTIwaSUyMCU0MHhlbm92YSUyRnRyYW5zZm9ybWVycw==",highlighted:"npm i @xenova/transformers"}}),ae=new Je({}),{c(){d=s("meta"),Ie=h(),y=s("h1"),T=s("a"),ue=s("span"),E(C.$$.fragment),ht=h(),Z=s("span"),ct=n("Using "),me=s("code"),ut=n("Transformers.js"),mt=n(" at Hugging Face"),Ae=h(),U=s("p"),dt=n("Transformers.js is a JavaScript library for running \u{1F917} Transformers directly in your browser, with no need for a server! It is designed to be functionally equivalent to the original "),Y=s("a"),yt=n("Python library"),vt=n(", meaning you can run the same pretrained models using a very similar API."),Se=h(),v=s("h2"),k=s("a"),de=s("span"),E(R.$$.fragment),wt=h(),F=s("span"),gt=n("Exploring "),ye=s("code"),bt=n("transformers.js"),Et=n(" in the Hub"),Pe=h(),u=s("p"),jt=n("You can find "),ve=s("code"),_t=n("transformers.js"),$t=n(" models by filtering by library in the "),H=s("a"),xt=n("models page"),Mt=n("."),We=h(),w=s("h2"),J=s("a"),we=s("span"),E(z.$$.fragment),Tt=h(),ge=s("span"),Ut=n("Quick tour"),Ne=h(),I=s("p"),kt=n("It\u2019s super simple to translate from existing code! Just like the Python library, we support the "),be=s("code"),Jt=n("pipeline"),It=n(" API. Pipelines group together a pretrained model with preprocessing of inputs and postprocessing of outputs, making it the easiest way to run models with the library."),Be=h(),A=s("table"),V=s("tr"),Q=s("th"),Ee=s("b"),At=n("Python (original)"),St=h(),D=s("th"),je=s("b"),Pt=n("Javascript (ours)"),Wt=h(),L=s("tr"),_e=s("td"),E(O.$$.fragment),Nt=h(),$e=s("td"),E(X.$$.fragment),Ge=h(),S=s("p"),Bt=n("You can also use a different model by specifying the model id or path as the second argument to the "),xe=s("code"),Gt=n("pipeline"),Ct=n(" function. For example:"),Ce=h(),E(q.$$.fragment),Ze=h(),P=s("p"),Zt=n("Refer to the "),K=s("a"),Yt=n("documentation"),Rt=n(" for the full list of supported tasks and models."),Ye=h(),g=s("h2"),W=s("a"),Me=s("span"),E(ee.$$.fragment),Ft=h(),Te=s("span"),Ht=n("Installation"),Re=h(),N=s("p"),zt=n("To install via "),te=s("a"),Vt=n("NPM"),Qt=n(", run:"),Fe=h(),E(re.$$.fragment),He=h(),B=s("p"),Dt=n("For more information, including how to use it in vanilla JS (without any bundler) via a CDN or static hosting, refer to the "),se=s("a"),Lt=n("README"),Ot=n("."),ze=h(),b=s("h2"),G=s("a"),Ue=s("span"),E(ae.$$.fragment),Xt=h(),ke=s("span"),qt=n("Additional resources"),Ve=h(),m=s("ul"),ie=s("li"),Kt=n("Transformers.js "),le=s("a"),er=n("repository"),tr=h(),pe=s("li"),rr=n("Transformers.js "),oe=s("a"),sr=n("docs"),ar=h(),fe=s("li"),lr=n("Transformers.js "),ne=s("a"),or=n("demo"),this.h()},l(e){const p=Vr('[data-svelte="svelte-1phssyn"]',document.head);d=a(p,"META",{name:!0,content:!0}),p.forEach(r),Ie=c(e),y=a(e,"H1",{class:!0});var De=l(y);T=a(De,"A",{id:!0,class:!0,href:!0});var hr=l(T);ue=a(hr,"SPAN",{});var cr=l(ue);j(C.$$.fragment,cr),cr.forEach(r),hr.forEach(r),ht=c(De),Z=a(De,"SPAN",{});var Le=l(Z);ct=i(Le,"Using "),me=a(Le,"CODE",{});var ur=l(me);ut=i(ur,"Transformers.js"),ur.forEach(r),mt=i(Le," at Hugging Face"),Le.forEach(r),De.forEach(r),Ae=c(e),U=a(e,"P",{});var Oe=l(U);dt=i(Oe,"Transformers.js is a JavaScript library for running \u{1F917} Transformers directly in your browser, with no need for a server! It is designed to be functionally equivalent to the original "),Y=a(Oe,"A",{href:!0,rel:!0});var mr=l(Y);yt=i(mr,"Python library"),mr.forEach(r),vt=i(Oe,", meaning you can run the same pretrained models using a very similar API."),Oe.forEach(r),Se=c(e),v=a(e,"H2",{class:!0});var Xe=l(v);k=a(Xe,"A",{id:!0,class:!0,href:!0});var dr=l(k);de=a(dr,"SPAN",{});var yr=l(de);j(R.$$.fragment,yr),yr.forEach(r),dr.forEach(r),wt=c(Xe),F=a(Xe,"SPAN",{});var qe=l(F);gt=i(qe,"Exploring "),ye=a(qe,"CODE",{});var vr=l(ye);bt=i(vr,"transformers.js"),vr.forEach(r),Et=i(qe," in the Hub"),qe.forEach(r),Xe.forEach(r),Pe=c(e),u=a(e,"P",{});var he=l(u);jt=i(he,"You can find "),ve=a(he,"CODE",{});var wr=l(ve);_t=i(wr,"transformers.js"),wr.forEach(r),$t=i(he," models by filtering by library in the "),H=a(he,"A",{href:!0,rel:!0});var gr=l(H);xt=i(gr,"models page"),gr.forEach(r),Mt=i(he,"."),he.forEach(r),We=c(e),w=a(e,"H2",{class:!0});var Ke=l(w);J=a(Ke,"A",{id:!0,class:!0,href:!0});var br=l(J);we=a(br,"SPAN",{});var Er=l(we);j(z.$$.fragment,Er),Er.forEach(r),br.forEach(r),Tt=c(Ke),ge=a(Ke,"SPAN",{});var jr=l(ge);Ut=i(jr,"Quick tour"),jr.forEach(r),Ke.forEach(r),Ne=c(e),I=a(e,"P",{});var et=l(I);kt=i(et,"It\u2019s super simple to translate from existing code! Just like the Python library, we support the "),be=a(et,"CODE",{});var _r=l(be);Jt=i(_r,"pipeline"),_r.forEach(r),It=i(et," API. Pipelines group together a pretrained model with preprocessing of inputs and postprocessing of outputs, making it the easiest way to run models with the library."),et.forEach(r),Be=c(e),A=a(e,"TABLE",{});var tt=l(A);V=a(tt,"TR",{});var rt=l(V);Q=a(rt,"TH",{width:!0,align:!0});var $r=l(Q);Ee=a($r,"B",{});var xr=l(Ee);At=i(xr,"Python (original)"),xr.forEach(r),$r.forEach(r),St=c(rt),D=a(rt,"TH",{width:!0,align:!0});var Mr=l(D);je=a(Mr,"B",{});var Tr=l(je);Pt=i(Tr,"Javascript (ours)"),Tr.forEach(r),Mr.forEach(r),rt.forEach(r),Wt=c(tt),L=a(tt,"TR",{});var st=l(L);_e=a(st,"TD",{});var Ur=l(_e);j(O.$$.fragment,Ur),Ur.forEach(r),Nt=c(st),$e=a(st,"TD",{});var kr=l($e);j(X.$$.fragment,kr),kr.forEach(r),st.forEach(r),tt.forEach(r),Ge=c(e),S=a(e,"P",{});var at=l(S);Bt=i(at,"You can also use a different model by specifying the model id or path as the second argument to the "),xe=a(at,"CODE",{});var Jr=l(xe);Gt=i(Jr,"pipeline"),Jr.forEach(r),Ct=i(at," function. For example:"),at.forEach(r),Ce=c(e),j(q.$$.fragment,e),Ze=c(e),P=a(e,"P",{});var lt=l(P);Zt=i(lt,"Refer to the "),K=a(lt,"A",{href:!0,rel:!0});var Ir=l(K);Yt=i(Ir,"documentation"),Ir.forEach(r),Rt=i(lt," for the full list of supported tasks and models."),lt.forEach(r),Ye=c(e),g=a(e,"H2",{class:!0});var ot=l(g);W=a(ot,"A",{id:!0,class:!0,href:!0});var Ar=l(W);Me=a(Ar,"SPAN",{});var Sr=l(Me);j(ee.$$.fragment,Sr),Sr.forEach(r),Ar.forEach(r),Ft=c(ot),Te=a(ot,"SPAN",{});var Pr=l(Te);Ht=i(Pr,"Installation"),Pr.forEach(r),ot.forEach(r),Re=c(e),N=a(e,"P",{});var nt=l(N);zt=i(nt,"To install via "),te=a(nt,"A",{href:!0,rel:!0});var Wr=l(te);Vt=i(Wr,"NPM"),Wr.forEach(r),Qt=i(nt,", run:"),nt.forEach(r),Fe=c(e),j(re.$$.fragment,e),He=c(e),B=a(e,"P",{});var it=l(B);Dt=i(it,"For more information, including how to use it in vanilla JS (without any bundler) via a CDN or static hosting, refer to the "),se=a(it,"A",{href:!0,rel:!0});var Nr=l(se);Lt=i(Nr,"README"),Nr.forEach(r),Ot=i(it,"."),it.forEach(r),ze=c(e),b=a(e,"H2",{class:!0});var pt=l(b);G=a(pt,"A",{id:!0,class:!0,href:!0});var Br=l(G);Ue=a(Br,"SPAN",{});var Gr=l(Ue);j(ae.$$.fragment,Gr),Gr.forEach(r),Br.forEach(r),Xt=c(pt),ke=a(pt,"SPAN",{});var Cr=l(ke);qt=i(Cr,"Additional resources"),Cr.forEach(r),pt.forEach(r),Ve=c(e),m=a(e,"UL",{});var ce=l(m);ie=a(ce,"LI",{});var nr=l(ie);Kt=i(nr,"Transformers.js "),le=a(nr,"A",{href:!0,rel:!0});var Zr=l(le);er=i(Zr,"repository"),Zr.forEach(r),nr.forEach(r),tr=c(ce),pe=a(ce,"LI",{});var ir=l(pe);rr=i(ir,"Transformers.js "),oe=a(ir,"A",{href:!0,rel:!0});var Yr=l(oe);sr=i(Yr,"docs"),Yr.forEach(r),ir.forEach(r),ar=c(ce),fe=a(ce,"LI",{});var pr=l(fe);lr=i(pr,"Transformers.js "),ne=a(pr,"A",{href:!0,rel:!0});var Rr=l(ne);or=i(Rr,"demo"),Rr.forEach(r),pr.forEach(r),ce.forEach(r),this.h()},h(){o(d,"name","hf:doc:metadata"),o(d,"content",JSON.stringify(Or)),o(T,"id","using-transformersjs-at-hugging-face"),o(T,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(T,"href","#using-transformersjs-at-hugging-face"),o(y,"class","relative group"),o(Y,"href","https://github.com/huggingface/transformers"),o(Y,"rel","nofollow"),o(k,"id","exploring-transformersjs-in-the-hub"),o(k,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(k,"href","#exploring-transformersjs-in-the-hub"),o(v,"class","relative group"),o(H,"href","https://huggingface.co/models?library=transformers.js"),o(H,"rel","nofollow"),o(J,"id","quick-tour"),o(J,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(J,"href","#quick-tour"),o(w,"class","relative group"),o(Q,"width","440px"),o(Q,"align","center"),o(D,"width","440px"),o(D,"align","center"),o(K,"href","https://huggingface.co/docs/transformers.js"),o(K,"rel","nofollow"),o(W,"id","installation"),o(W,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(W,"href","#installation"),o(g,"class","relative group"),o(te,"href","https://www.npmjs.com/package/@xenova/transformers"),o(te,"rel","nofollow"),o(se,"href","https://github.com/xenova/transformers.js/blob/main/README.md#installation"),o(se,"rel","nofollow"),o(G,"id","additional-resources"),o(G,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),o(G,"href","#additional-resources"),o(b,"class","relative group"),o(le,"href","https://github.com/xenova/transformers.js"),o(le,"rel","nofollow"),o(oe,"href","https://huggingface.co/docs/transformers.js"),o(oe,"rel","nofollow"),o(ne,"href","https://xenova.github.io/transformers.js/"),o(ne,"rel","nofollow")},m(e,p){t(document.head,d),f(e,Ie,p),f(e,y,p),t(y,T),t(T,ue),_(C,ue,null),t(y,ht),t(y,Z),t(Z,ct),t(Z,me),t(me,ut),t(Z,mt),f(e,Ae,p),f(e,U,p),t(U,dt),t(U,Y),t(Y,yt),t(U,vt),f(e,Se,p),f(e,v,p),t(v,k),t(k,de),_(R,de,null),t(v,wt),t(v,F),t(F,gt),t(F,ye),t(ye,bt),t(F,Et),f(e,Pe,p),f(e,u,p),t(u,jt),t(u,ve),t(ve,_t),t(u,$t),t(u,H),t(H,xt),t(u,Mt),f(e,We,p),f(e,w,p),t(w,J),t(J,we),_(z,we,null),t(w,Tt),t(w,ge),t(ge,Ut),f(e,Ne,p),f(e,I,p),t(I,kt),t(I,be),t(be,Jt),t(I,It),f(e,Be,p),f(e,A,p),t(A,V),t(V,Q),t(Q,Ee),t(Ee,At),t(V,St),t(V,D),t(D,je),t(je,Pt),t(A,Wt),t(A,L),t(L,_e),_(O,_e,null),t(L,Nt),t(L,$e),_(X,$e,null),f(e,Ge,p),f(e,S,p),t(S,Bt),t(S,xe),t(xe,Gt),t(S,Ct),f(e,Ce,p),_(q,e,p),f(e,Ze,p),f(e,P,p),t(P,Zt),t(P,K),t(K,Yt),t(P,Rt),f(e,Ye,p),f(e,g,p),t(g,W),t(W,Me),_(ee,Me,null),t(g,Ft),t(g,Te),t(Te,Ht),f(e,Re,p),f(e,N,p),t(N,zt),t(N,te),t(te,Vt),t(N,Qt),f(e,Fe,p),_(re,e,p),f(e,He,p),f(e,B,p),t(B,Dt),t(B,se),t(se,Lt),t(B,Ot),f(e,ze,p),f(e,b,p),t(b,G),t(G,Ue),_(ae,Ue,null),t(b,Xt),t(b,ke),t(ke,qt),f(e,Ve,p),f(e,m,p),t(m,ie),t(ie,Kt),t(ie,le),t(le,er),t(m,tr),t(m,pe),t(pe,rr),t(pe,oe),t(oe,sr),t(m,ar),t(m,fe),t(fe,lr),t(fe,ne),t(ne,or),Qe=!0},p:Qr,i(e){Qe||($(C.$$.fragment,e),$(R.$$.fragment,e),$(z.$$.fragment,e),$(O.$$.fragment,e),$(X.$$.fragment,e),$(q.$$.fragment,e),$(ee.$$.fragment,e),$(re.$$.fragment,e),$(ae.$$.fragment,e),Qe=!0)},o(e){x(C.$$.fragment,e),x(R.$$.fragment,e),x(z.$$.fragment,e),x(O.$$.fragment,e),x(X.$$.fragment,e),x(q.$$.fragment,e),x(ee.$$.fragment,e),x(re.$$.fragment,e),x(ae.$$.fragment,e),Qe=!1},d(e){r(d),e&&r(Ie),e&&r(y),M(C),e&&r(Ae),e&&r(U),e&&r(Se),e&&r(v),M(R),e&&r(Pe),e&&r(u),e&&r(We),e&&r(w),M(z),e&&r(Ne),e&&r(I),e&&r(Be),e&&r(A),M(O),M(X),e&&r(Ge),e&&r(S),e&&r(Ce),M(q,e),e&&r(Ze),e&&r(P),e&&r(Ye),e&&r(g),M(ee),e&&r(Re),e&&r(N),e&&r(Fe),M(re,e),e&&r(He),e&&r(B),e&&r(ze),e&&r(b),M(ae),e&&r(Ve),e&&r(m)}}}const Or={local:"using-transformersjs-at-hugging-face",sections:[{local:"exploring-transformersjs-in-the-hub",title:"Exploring `transformers.js` in the Hub"},{local:"quick-tour",title:"Quick tour"},{local:"installation",title:"Installation"},{local:"additional-resources",title:"Additional resources"}],title:"Using `Transformers.js` at Hugging Face"};function Xr(fr){return Dr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ts extends Fr{constructor(d){super();Hr(this,d,Xr,Lr,zr,{})}}export{ts as default,Or as metadata};
