import{s as Ie,n as We,o as Ge}from"../chunks/scheduler.12fdeddc.js";import{S as Ee,i as _e,g as i,s as l,r as o,A as ke,h as r,f as s,c as a,j as S,u as p,x as g,k as ve,y as H,a as n,v as m,d as f,t as c,w as h}from"../chunks/index.88dae322.js";import{C as ce}from"../chunks/CodeBlock.8e54a086.js";import{H as V,E as Be}from"../chunks/getInferenceSnippets.00466244.js";function Ce(ge){let u,z,N,Y,w,A,T,de='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.',Q,b,F,y,we='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>.',X,$,D,J,Te="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,d,Z,be='<th width="440px" align="center"><b>Python (original)</b></th> <th width="440px" align="center"><b>Javascript (ours)</b></th>',he,j,L,M,ue,P,x,O,U,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:",K,v,ee,I,$e='Refer to the <a href="https://huggingface.co/docs/transformers.js" rel="nofollow">documentation</a> for the full list of supported tasks and models.',te,W,se,G,Je='To install via <a href="https://www.npmjs.com/package/@huggingface/transformers" rel="nofollow">NPM</a>, run:',ne,E,le,_,je='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/huggingface/transformers.js/blob/main/README.md#installation" rel="nofollow">README</a>.',ae,k,ie,B,Me='<li>Transformers.js <a href="https://github.com/huggingface/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://huggingface.github.io/transformers.js/" rel="nofollow">demo</a></li>',re,C,oe,R,pe;return w=new V({props:{title:"Using Transformers.js at Hugging Face",local:"using-transformersjs-at-hugging-face",headingTag:"h1"}}),b=new V({props:{title:"Exploring transformers.js in the Hub",local:"exploring-transformersjs-in-the-hub",headingTag:"h2"}}),$=new V({props:{title:"Quick tour",local:"quick-tour",headingTag:"h2"}}),M=new ce({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}}),x=new ce({props:{code:"aW1wb3J0JTIwJTdCJTIwcGlwZWxpbmUlMjAlN0QlMjBmcm9tJTIwJyU0MGh1Z2dpbmdmYWNlJTJGdHJhbnNmb3JtZXJzJyUzQiUwQSUwQSUyRiUyRiUyMEFsbG9jYXRlJTIwYSUyMHBpcGVsaW5lJTIwZm9yJTIwc2VudGltZW50LWFuYWx5c2lzJTBBbGV0JTIwcGlwZSUyMCUzRCUyMGF3YWl0JTIwcGlwZWxpbmUoJ3NlbnRpbWVudC1hbmFseXNpcycpJTNCJTBBJTBBbGV0JTIwb3V0JTIwJTNEJTIwYXdhaXQlMjBwaXBlKCdJJTIwbG92ZSUyMHRyYW5zZm9ybWVycyEnKSUzQiUwQSUyRiUyRiUyMCU1QiU3QidsYWJlbCclM0ElMjAnUE9TSVRJVkUnJTJDJTIwJ3Njb3JlJyUzQSUyMDAuOTk5ODE3Njg2JTdEJTVE",highlighted:`<span class="hljs-keyword">import</span> { pipeline } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/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}}),v=new ce({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 V({props:{title:"Installation",local:"installation",headingTag:"h2"}}),E=new ce({props:{code:"bnBtJTIwaSUyMCU0MGh1Z2dpbmdmYWNlJTJGdHJhbnNmb3JtZXJz",highlighted:"npm i @huggingface/transformers",wrap:!1}}),k=new V({props:{title:"Additional resources",local:"additional-resources",headingTag:"h2"}}),C=new Be({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/hub/transformers-js.md"}}),{c(){u=i("meta"),z=l(),N=i("p"),Y=l(),o(w.$$.fragment),A=l(),T=i("p"),T.innerHTML=de,Q=l(),o(b.$$.fragment),F=l(),y=i("p"),y.innerHTML=we,X=l(),o($.$$.fragment),D=l(),J=i("p"),J.innerHTML=Te,q=l(),d=i("table"),Z=i("tr"),Z.innerHTML=be,he=l(),j=i("tr"),L=i("td"),o(M.$$.fragment),ue=l(),P=i("td"),o(x.$$.fragment),O=l(),U=i("p"),U.innerHTML=ye,K=l(),o(v.$$.fragment),ee=l(),I=i("p"),I.innerHTML=$e,te=l(),o(W.$$.fragment),se=l(),G=i("p"),G.innerHTML=Je,ne=l(),o(E.$$.fragment),le=l(),_=i("p"),_.innerHTML=je,ae=l(),o(k.$$.fragment),ie=l(),B=i("ul"),B.innerHTML=Me,re=l(),o(C.$$.fragment),oe=l(),R=i("p"),this.h()},l(e){const t=ke("svelte-u9bgzb",document.head);u=r(t,"META",{name:!0,content:!0}),t.forEach(s),z=a(e),N=r(e,"P",{}),S(N).forEach(s),Y=a(e),p(w.$$.fragment,e),A=a(e),T=r(e,"P",{"data-svelte-h":!0}),g(T)!=="svelte-jfr84k"&&(T.innerHTML=de),Q=a(e),p(b.$$.fragment,e),F=a(e),y=r(e,"P",{"data-svelte-h":!0}),g(y)!=="svelte-1fvvhlf"&&(y.innerHTML=we),X=a(e),p($.$$.fragment,e),D=a(e),J=r(e,"P",{"data-svelte-h":!0}),g(J)!=="svelte-11oq8sj"&&(J.innerHTML=Te),q=a(e),d=r(e,"TABLE",{});var me=S(d);Z=r(me,"TR",{"data-svelte-h":!0}),g(Z)!=="svelte-171mvpd"&&(Z.innerHTML=be),he=a(me),j=r(me,"TR",{});var fe=S(j);L=r(fe,"TD",{});var xe=S(L);p(M.$$.fragment,xe),xe.forEach(s),ue=a(fe),P=r(fe,"TD",{});var Ue=S(P);p(x.$$.fragment,Ue),Ue.forEach(s),fe.forEach(s),me.forEach(s),O=a(e),U=r(e,"P",{"data-svelte-h":!0}),g(U)!=="svelte-q6076l"&&(U.innerHTML=ye),K=a(e),p(v.$$.fragment,e),ee=a(e),I=r(e,"P",{"data-svelte-h":!0}),g(I)!=="svelte-10nh2ih"&&(I.innerHTML=$e),te=a(e),p(W.$$.fragment,e),se=a(e),G=r(e,"P",{"data-svelte-h":!0}),g(G)!=="svelte-1y7zlz9"&&(G.innerHTML=Je),ne=a(e),p(E.$$.fragment,e),le=a(e),_=r(e,"P",{"data-svelte-h":!0}),g(_)!=="svelte-1qjggj3"&&(_.innerHTML=je),ae=a(e),p(k.$$.fragment,e),ie=a(e),B=r(e,"UL",{"data-svelte-h":!0}),g(B)!=="svelte-3gcwbj"&&(B.innerHTML=Me),re=a(e),p(C.$$.fragment,e),oe=a(e),R=r(e,"P",{}),S(R).forEach(s),this.h()},h(){ve(u,"name","hf:doc:metadata"),ve(u,"content",He)},m(e,t){H(document.head,u),n(e,z,t),n(e,N,t),n(e,Y,t),m(w,e,t),n(e,A,t),n(e,T,t),n(e,Q,t),m(b,e,t),n(e,F,t),n(e,y,t),n(e,X,t),m($,e,t),n(e,D,t),n(e,J,t),n(e,q,t),n(e,d,t),H(d,Z),H(d,he),H(d,j),H(j,L),m(M,L,null),H(j,ue),H(j,P),m(x,P,null),n(e,O,t),n(e,U,t),n(e,K,t),m(v,e,t),n(e,ee,t),n(e,I,t),n(e,te,t),m(W,e,t),n(e,se,t),n(e,G,t),n(e,ne,t),m(E,e,t),n(e,le,t),n(e,_,t),n(e,ae,t),m(k,e,t),n(e,ie,t),n(e,B,t),n(e,re,t),m(C,e,t),n(e,oe,t),n(e,R,t),pe=!0},p:We,i(e){pe||(f(w.$$.fragment,e),f(b.$$.fragment,e),f($.$$.fragment,e),f(M.$$.fragment,e),f(x.$$.fragment,e),f(v.$$.fragment,e),f(W.$$.fragment,e),f(E.$$.fragment,e),f(k.$$.fragment,e),f(C.$$.fragment,e),pe=!0)},o(e){c(w.$$.fragment,e),c(b.$$.fragment,e),c($.$$.fragment,e),c(M.$$.fragment,e),c(x.$$.fragment,e),c(v.$$.fragment,e),c(W.$$.fragment,e),c(E.$$.fragment,e),c(k.$$.fragment,e),c(C.$$.fragment,e),pe=!1},d(e){e&&(s(z),s(N),s(Y),s(A),s(T),s(Q),s(F),s(y),s(X),s(D),s(J),s(q),s(d),s(O),s(U),s(K),s(ee),s(I),s(te),s(se),s(G),s(ne),s(le),s(_),s(ae),s(ie),s(B),s(re),s(oe),s(R)),s(u),h(w,e),h(b,e),h($,e),h(M),h(x),h(v,e),h(W,e),h(E,e),h(k,e),h(C,e)}}}const He='{"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 Ze(ge){return Ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Re extends Ee{constructor(u){super(),_e(this,u,Ze,Ce,Ie,{})}}export{Re as component};
