import{s as ve,n as Je,o as Ie}from"../chunks/scheduler.d6170356.js";import{S as We,i as ke,g as i,s as l,r as p,A as Ce,h as r,f as s,c as a,j as E,u as m,x as f,k as Ue,y as Z,a as n,v as c,d as h,t as u,w as d}from"../chunks/index.fcd4cc08.js";import{C as me}from"../chunks/CodeBlock.7b16bdef.js";import{H as N}from"../chunks/Heading.8660bd0e.js";function He(he){let o,R,S,A,w,F,y,ue='Transformers.js is a JavaScript library for running 🤗 Transformers directly in your browser, with no need for a server! It is designed to be functionally equivalent to the original <a href="https://github.com/huggingface/transformers" rel="nofollow">Python library</a>, meaning you can run the same pretrained models using a very similar API.',z,M,V,b,de='You can find <code>transformers.js</code> models by filtering by library in the <a href="https://huggingface.co/models?library=transformers.js" rel="nofollow">models page</a>.',Q,$,X,T,ge="It’s super simple to translate from existing code! Just like the Python library, we support the <code>pipeline</code> 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.",q,g,_,we='<th width="440px" align="center"><b>Python (original)</b></th> <th width="440px" align="center"><b>Javascript (ours)</b></th>',fe,j,L,x,ce,P,U,D,v,ye="You can also use a different model by specifying the model id or path as the second argument to the <code>pipeline</code> function. For example:",O,J,K,I,Me='Refer to the <a href="https://huggingface.co/docs/transformers.js" rel="nofollow">documentation</a> for the full list of supported tasks and models.',ee,W,te,k,be='To install via <a href="https://www.npmjs.com/package/@xenova/transformers" rel="nofollow">NPM</a>, run:',se,C,ne,H,$e='For more information, including how to use it in vanilla JS (without any bundler) via a CDN or static hosting, refer to the <a href="https://github.com/xenova/transformers.js/blob/main/README.md#installation" rel="nofollow">README</a>.',le,B,ae,G,Te='<li>Transformers.js <a href="https://github.com/xenova/transformers.js" rel="nofollow">repository</a></li> <li>Transformers.js <a href="https://huggingface.co/docs/transformers.js" rel="nofollow">docs</a></li> <li>Transformers.js <a href="https://xenova.github.io/transformers.js/" rel="nofollow">demo</a></li>',ie,Y,re;return w=new N({props:{title:"Using Transformers.js at Hugging Face",local:"using-transformersjs-at-hugging-face",headingTag:"h1"}}),M=new N({props:{title:"Exploring transformers.js in the Hub",local:"exploring-transformersjs-in-the-hub",headingTag:"h2"}}),$=new N({props:{title:"Quick tour",local:"quick-tour",headingTag:"h2"}}),x=new me({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>`,wrap:!1}}),U=new me({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>`,wrap:!1}}),J=new me({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>);`,wrap:!1}}),W=new N({props:{title:"Installation",local:"installation",headingTag:"h2"}}),C=new me({props:{code:"bnBtJTIwaSUyMCU0MHhlbm92YSUyRnRyYW5zZm9ybWVycw==",highlighted:"npm i @xenova/transformers",wrap:!1}}),B=new N({props:{title:"Additional resources",local:"additional-resources",headingTag:"h2"}}),{c(){o=i("meta"),R=l(),S=i("p"),A=l(),p(w.$$.fragment),F=l(),y=i("p"),y.innerHTML=ue,z=l(),p(M.$$.fragment),V=l(),b=i("p"),b.innerHTML=de,Q=l(),p($.$$.fragment),X=l(),T=i("p"),T.innerHTML=ge,q=l(),g=i("table"),_=i("tr"),_.innerHTML=we,fe=l(),j=i("tr"),L=i("td"),p(x.$$.fragment),ce=l(),P=i("td"),p(U.$$.fragment),D=l(),v=i("p"),v.innerHTML=ye,O=l(),p(J.$$.fragment),K=l(),I=i("p"),I.innerHTML=Me,ee=l(),p(W.$$.fragment),te=l(),k=i("p"),k.innerHTML=be,se=l(),p(C.$$.fragment),ne=l(),H=i("p"),H.innerHTML=$e,le=l(),p(B.$$.fragment),ae=l(),G=i("ul"),G.innerHTML=Te,ie=l(),Y=i("p"),this.h()},l(e){const t=Ce("svelte-u9bgzb",document.head);o=r(t,"META",{name:!0,content:!0}),t.forEach(s),R=a(e),S=r(e,"P",{}),E(S).forEach(s),A=a(e),m(w.$$.fragment,e),F=a(e),y=r(e,"P",{"data-svelte-h":!0}),f(y)!=="svelte-jfr84k"&&(y.innerHTML=ue),z=a(e),m(M.$$.fragment,e),V=a(e),b=r(e,"P",{"data-svelte-h":!0}),f(b)!=="svelte-1fvvhlf"&&(b.innerHTML=de),Q=a(e),m($.$$.fragment,e),X=a(e),T=r(e,"P",{"data-svelte-h":!0}),f(T)!=="svelte-11oq8sj"&&(T.innerHTML=ge),q=a(e),g=r(e,"TABLE",{});var oe=E(g);_=r(oe,"TR",{"data-svelte-h":!0}),f(_)!=="svelte-171mvpd"&&(_.innerHTML=we),fe=a(oe),j=r(oe,"TR",{});var pe=E(j);L=r(pe,"TD",{});var je=E(L);m(x.$$.fragment,je),je.forEach(s),ce=a(pe),P=r(pe,"TD",{});var xe=E(P);m(U.$$.fragment,xe),xe.forEach(s),pe.forEach(s),oe.forEach(s),D=a(e),v=r(e,"P",{"data-svelte-h":!0}),f(v)!=="svelte-q6076l"&&(v.innerHTML=ye),O=a(e),m(J.$$.fragment,e),K=a(e),I=r(e,"P",{"data-svelte-h":!0}),f(I)!=="svelte-10nh2ih"&&(I.innerHTML=Me),ee=a(e),m(W.$$.fragment,e),te=a(e),k=r(e,"P",{"data-svelte-h":!0}),f(k)!=="svelte-15u6aec"&&(k.innerHTML=be),se=a(e),m(C.$$.fragment,e),ne=a(e),H=r(e,"P",{"data-svelte-h":!0}),f(H)!=="svelte-1mmwayo"&&(H.innerHTML=$e),le=a(e),m(B.$$.fragment,e),ae=a(e),G=r(e,"UL",{"data-svelte-h":!0}),f(G)!=="svelte-1ltctub"&&(G.innerHTML=Te),ie=a(e),Y=r(e,"P",{}),E(Y).forEach(s),this.h()},h(){Ue(o,"name","hf:doc:metadata"),Ue(o,"content",Be)},m(e,t){Z(document.head,o),n(e,R,t),n(e,S,t),n(e,A,t),c(w,e,t),n(e,F,t),n(e,y,t),n(e,z,t),c(M,e,t),n(e,V,t),n(e,b,t),n(e,Q,t),c($,e,t),n(e,X,t),n(e,T,t),n(e,q,t),n(e,g,t),Z(g,_),Z(g,fe),Z(g,j),Z(j,L),c(x,L,null),Z(j,ce),Z(j,P),c(U,P,null),n(e,D,t),n(e,v,t),n(e,O,t),c(J,e,t),n(e,K,t),n(e,I,t),n(e,ee,t),c(W,e,t),n(e,te,t),n(e,k,t),n(e,se,t),c(C,e,t),n(e,ne,t),n(e,H,t),n(e,le,t),c(B,e,t),n(e,ae,t),n(e,G,t),n(e,ie,t),n(e,Y,t),re=!0},p:Je,i(e){re||(h(w.$$.fragment,e),h(M.$$.fragment,e),h($.$$.fragment,e),h(x.$$.fragment,e),h(U.$$.fragment,e),h(J.$$.fragment,e),h(W.$$.fragment,e),h(C.$$.fragment,e),h(B.$$.fragment,e),re=!0)},o(e){u(w.$$.fragment,e),u(M.$$.fragment,e),u($.$$.fragment,e),u(x.$$.fragment,e),u(U.$$.fragment,e),u(J.$$.fragment,e),u(W.$$.fragment,e),u(C.$$.fragment,e),u(B.$$.fragment,e),re=!1},d(e){e&&(s(R),s(S),s(A),s(F),s(y),s(z),s(V),s(b),s(Q),s(X),s(T),s(q),s(g),s(D),s(v),s(O),s(K),s(I),s(ee),s(te),s(k),s(se),s(ne),s(H),s(le),s(ae),s(G),s(ie),s(Y)),s(o),d(w,e),d(M,e),d($,e),d(x),d(U),d(J,e),d(W,e),d(C,e),d(B,e)}}}const Be='{"title":"Using Transformers.js at Hugging Face","local":"using-transformersjs-at-hugging-face","sections":[{"title":"Exploring transformers.js in the Hub","local":"exploring-transformersjs-in-the-hub","sections":[],"depth":2},{"title":"Quick tour","local":"quick-tour","sections":[],"depth":2},{"title":"Installation","local":"installation","sections":[],"depth":2},{"title":"Additional resources","local":"additional-resources","sections":[],"depth":2}],"depth":1}';function Ge(he){return Ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends We{constructor(o){super(),ke(this,o,Ge,He,ve,{})}}export{Le as component};
