import{s as Ie,f as me,n as $e,o as je}from"../chunks/scheduler.37c15a92.js";import{S as ve,i as He,g as n,s,r as d,A as ke,h as r,f as a,c as i,j as _,u as f,x as g,k as o,y as Ze,a as l,v as h,d as b,t as y,w}from"../chunks/index.7cb9c9b8.js";import{C as ce}from"../chunks/CodeBlock.abae2786.js";import{C as Ge}from"../chunks/CourseFloatingBanner.df82c153.js";import{H as pe,E as We}from"../chunks/getInferenceSnippets.1f335395.js";function Be(ue){let u,F,Y,z,M,L,J,N,T,ge=`To make your life even easier, Gradio integrates directly with Hugging Face Hub and Hugging Face Spaces.
You can load demos from the Hub and Spaces with only <em>one line of code</em>.`,Q,U,E,x,de='To start with, choose one of the thousands of models Hugging Face offers through the Hub, as described in <a href="/course/chapter4/2">Chapter 4</a>.',V,I,fe=`Using the special <code>Interface.load()</code> method, you pass <code>&quot;model/&quot;</code> (or, equivalently, <code>&quot;huggingface/&quot;</code>)
followed by the model name.
For example, here is the code to build a demo for <a href="https://huggingface.co/EleutherAI/gpt-j-6B" rel="nofollow">GPT-J</a>, a large language model, add a couple of example inputs:`,q,$,X,j,he="The code above will produce the interface below:",A,m,be,P,v,ye=`Loading a model in this way uses Hugging Face’s <a href="https://huggingface.co/inference-api" rel="nofollow">Inference API</a>,
instead of loading the model in memory. This is ideal for huge models like GPT-J or T0pp which
require lots of RAM.`,D,H,K,k,we="To load any Space from the Hugging Face Hub and recreate it locally, you can pass <code>spaces/</code> to the <code>Interface</code>, followed by the name of the Space.",O,Z,Me="Remember the demo from section 1 that removes the background of an image? Let’s load it from Hugging Face Spaces:",ee,G,te,c,Je,ae,W,Te=`One of the cool things about loading demos from the Hub or Spaces is that you customize them
by overriding any of the
parameters. Here, we add a title and get it to work with a webcam instead:`,le,B,oe,p,Ue,se,C,xe="Now that we’ve explored a few ways to integrate Gradio with the Hugging Face Hub, let’s take a look at some advanced features of the <code>Interface</code> class. That’s the topic of the next section!",ie,R,ne,S,re;return M=new pe({props:{title:"Integrations with the Hugging Face Hub",local:"integrations-with-the-hugging-face-hub",headingTag:"h1"}}),J=new Ge({props:{chapter:9,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter9/section5.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter9/section5.ipynb"}]}}),U=new pe({props:{title:"Loading models from the Hugging Face Hub",local:"loading-models-from-the-hugging-face-hub",headingTag:"h3"}}),$=new ce({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQXRpdGxlJTIwJTNEJTIwJTIyR1BULUotNkIlMjIlMEFkZXNjcmlwdGlvbiUyMCUzRCUyMCUyMkdyYWRpbyUyMERlbW8lMjBmb3IlMjBHUFQtSiUyMDZCJTJDJTIwYSUyMHRyYW5zZm9ybWVyJTIwbW9kZWwlMjB0cmFpbmVkJTIwdXNpbmclMjBCZW4lMjBXYW5nJ3MlMjBNZXNoJTIwVHJhbnNmb3JtZXIlMjBKQVguJTIwJ0dQVC1KJyUyMHJlZmVycyUyMHRvJTIwdGhlJTIwY2xhc3MlMjBvZiUyMG1vZGVsJTJDJTIwd2hpbGUlMjAnNkInJTIwcmVwcmVzZW50cyUyMHRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5hYmxlJTIwcGFyYW1ldGVycy4lMjBUbyUyMHVzZSUyMGl0JTJDJTIwc2ltcGx5JTIwYWRkJTIweW91ciUyMHRleHQlMkMlMjBvciUyMGNsaWNrJTIwb25lJTIwb2YlMjB0aGUlMjBleGFtcGxlcyUyMHRvJTIwbG9hZCUyMHRoZW0uJTIwUmVhZCUyMG1vcmUlMjBhdCUyMHRoZSUyMGxpbmtzJTIwYmVsb3cuJTIyJTBBYXJ0aWNsZSUyMCUzRCUyMCUyMiUzQ3AlMjBzdHlsZSUzRCd0ZXh0LWFsaWduJTNBJTIwY2VudGVyJyUzRSUzQ2ElMjBocmVmJTNEJ2h0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmtpbmdvZmxvbHolMkZtZXNoLXRyYW5zZm9ybWVyLWpheCclMjB0YXJnZXQlM0QnX2JsYW5rJyUzRUdQVC1KLTZCJTNBJTIwQSUyMDYlMjBCaWxsaW9uJTIwUGFyYW1ldGVyJTIwQXV0b3JlZ3Jlc3NpdmUlMjBMYW5ndWFnZSUyME1vZGVsJTNDJTJGYSUzRSUzQyUyRnAlM0UlMjIlMEElMEFnci5JbnRlcmZhY2UubG9hZCglMEElMjAlMjAlMjAlMjAlMjJodWdnaW5nZmFjZSUyRkVsZXV0aGVyQUklMkZncHQtai02QiUyMiUyQyUwQSUyMCUyMCUyMCUyMGlucHV0cyUzRGdyLlRleHRib3gobGluZXMlM0Q1JTJDJTIwbGFiZWwlM0QlMjJJbnB1dCUyMFRleHQlMjIpJTJDJTBBJTIwJTIwJTIwJTIwdGl0bGUlM0R0aXRsZSUyQyUwQSUyMCUyMCUyMCUyMGRlc2NyaXB0aW9uJTNEZGVzY3JpcHRpb24lMkMlMEElMjAlMjAlMjAlMjBhcnRpY2xlJTNEYXJ0aWNsZSUyQyUwQSkubGF1bmNoKCk=",highlighted:`<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr

title = <span class="hljs-string">&quot;GPT-J-6B&quot;</span>
description = <span class="hljs-string">&quot;Gradio Demo for GPT-J 6B, a transformer model trained using Ben Wang&#x27;s Mesh Transformer JAX. &#x27;GPT-J&#x27; refers to the class of model, while &#x27;6B&#x27; represents the number of trainable parameters. To use it, simply add your text, or click one of the examples to load them. Read more at the links below.&quot;</span>
article = <span class="hljs-string">&quot;&lt;p style=&#x27;text-align: center&#x27;&gt;&lt;a href=&#x27;https://github.com/kingoflolz/mesh-transformer-jax&#x27; target=&#x27;_blank&#x27;&gt;GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model&lt;/a&gt;&lt;/p&gt;&quot;</span>

gr.Interface.load(
    <span class="hljs-string">&quot;huggingface/EleutherAI/gpt-j-6B&quot;</span>,
    inputs=gr.Textbox(lines=<span class="hljs-number">5</span>, label=<span class="hljs-string">&quot;Input Text&quot;</span>),
    title=title,
    description=description,
    article=article,
).launch()`,wrap:!1}}),H=new pe({props:{title:"Loading from Hugging Face Spaces",local:"loading-from-hugging-face-spaces",headingTag:"h3"}}),G=new ce({props:{code:"Z3IuSW50ZXJmYWNlLmxvYWQoJTIyc3BhY2VzJTJGYWJpZGxhYnMlMkZyZW1vdmUtYmclMjIpLmxhdW5jaCgp",highlighted:'gr.Interface.load(<span class="hljs-string">&quot;spaces/abidlabs/remove-bg&quot;</span>).launch()',wrap:!1}}),B=new ce({props:{code:"Z3IuSW50ZXJmYWNlLmxvYWQoJTBBJTIwJTIwJTIwJTIwJTIyc3BhY2VzJTJGYWJpZGxhYnMlMkZyZW1vdmUtYmclMjIlMkMlMjBpbnB1dHMlM0QlMjJ3ZWJjYW0lMjIlMkMlMjB0aXRsZSUzRCUyMlJlbW92ZSUyMHlvdXIlMjB3ZWJjYW0lMjBiYWNrZ3JvdW5kISUyMiUwQSkubGF1bmNoKCk=",highlighted:`gr.Interface.load(
    <span class="hljs-string">&quot;spaces/abidlabs/remove-bg&quot;</span>, inputs=<span class="hljs-string">&quot;webcam&quot;</span>, title=<span class="hljs-string">&quot;Remove your webcam background!&quot;</span>
).launch()`,wrap:!1}}),R=new We({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter9/5.mdx"}}),{c(){u=n("meta"),F=s(),Y=n("p"),z=s(),d(M.$$.fragment),L=s(),d(J.$$.fragment),N=s(),T=n("p"),T.innerHTML=ge,Q=s(),d(U.$$.fragment),E=s(),x=n("p"),x.innerHTML=de,V=s(),I=n("p"),I.innerHTML=fe,q=s(),d($.$$.fragment),X=s(),j=n("p"),j.textContent=he,A=s(),m=n("iframe"),P=s(),v=n("p"),v.innerHTML=ye,D=s(),d(H.$$.fragment),K=s(),k=n("p"),k.innerHTML=we,O=s(),Z=n("p"),Z.textContent=Me,ee=s(),d(G.$$.fragment),te=s(),c=n("iframe"),ae=s(),W=n("p"),W.textContent=Te,le=s(),d(B.$$.fragment),oe=s(),p=n("iframe"),se=s(),C=n("p"),C.innerHTML=xe,ie=s(),d(R.$$.fragment),ne=s(),S=n("p"),this.h()},l(e){const t=ke("svelte-u9bgzb",document.head);u=r(t,"META",{name:!0,content:!0}),t.forEach(a),F=i(e),Y=r(e,"P",{}),_(Y).forEach(a),z=i(e),f(M.$$.fragment,e),L=i(e),f(J.$$.fragment,e),N=i(e),T=r(e,"P",{"data-svelte-h":!0}),g(T)!=="svelte-12pis40"&&(T.innerHTML=ge),Q=i(e),f(U.$$.fragment,e),E=i(e),x=r(e,"P",{"data-svelte-h":!0}),g(x)!=="svelte-lxoemb"&&(x.innerHTML=de),V=i(e),I=r(e,"P",{"data-svelte-h":!0}),g(I)!=="svelte-3z199z"&&(I.innerHTML=fe),q=i(e),f($.$$.fragment,e),X=i(e),j=r(e,"P",{"data-svelte-h":!0}),g(j)!=="svelte-1fjc49g"&&(j.textContent=he),A=i(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),_(m).forEach(a),P=i(e),v=r(e,"P",{"data-svelte-h":!0}),g(v)!=="svelte-fyleft"&&(v.innerHTML=ye),D=i(e),f(H.$$.fragment,e),K=i(e),k=r(e,"P",{"data-svelte-h":!0}),g(k)!=="svelte-1k2bhow"&&(k.innerHTML=we),O=i(e),Z=r(e,"P",{"data-svelte-h":!0}),g(Z)!=="svelte-z16y7l"&&(Z.textContent=Me),ee=i(e),f(G.$$.fragment,e),te=i(e),c=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),_(c).forEach(a),ae=i(e),W=r(e,"P",{"data-svelte-h":!0}),g(W)!=="svelte-m60st2"&&(W.textContent=Te),le=i(e),f(B.$$.fragment,e),oe=i(e),p=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),_(p).forEach(a),se=i(e),C=r(e,"P",{"data-svelte-h":!0}),g(C)!=="svelte-19g2kvj"&&(C.innerHTML=xe),ie=i(e),f(R.$$.fragment,e),ne=i(e),S=r(e,"P",{}),_(S).forEach(a),this.h()},h(){o(u,"name","hf:doc:metadata"),o(u,"content",Ce),me(m.src,be="https://course-demos-gpt-j-6B.hf.space")||o(m,"src",be),o(m,"frameborder","0"),o(m,"height","750"),o(m,"title","Gradio app"),o(m,"class","container p-0 flex-grow space-iframe"),o(m,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),o(m,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),me(c.src,Je="https://course-demos-remove-bg-original.hf.space")||o(c,"src",Je),o(c,"frameborder","0"),o(c,"height","650"),o(c,"title","Gradio app"),o(c,"class","container p-0 flex-grow space-iframe"),o(c,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),o(c,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),me(p.src,Ue="https://course-demos-Remove-bg.hf.space")||o(p,"src",Ue),o(p,"frameborder","0"),o(p,"height","550"),o(p,"title","Gradio app"),o(p,"class","container p-0 flex-grow space-iframe"),o(p,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),o(p,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(e,t){Ze(document.head,u),l(e,F,t),l(e,Y,t),l(e,z,t),h(M,e,t),l(e,L,t),h(J,e,t),l(e,N,t),l(e,T,t),l(e,Q,t),h(U,e,t),l(e,E,t),l(e,x,t),l(e,V,t),l(e,I,t),l(e,q,t),h($,e,t),l(e,X,t),l(e,j,t),l(e,A,t),l(e,m,t),l(e,P,t),l(e,v,t),l(e,D,t),h(H,e,t),l(e,K,t),l(e,k,t),l(e,O,t),l(e,Z,t),l(e,ee,t),h(G,e,t),l(e,te,t),l(e,c,t),l(e,ae,t),l(e,W,t),l(e,le,t),h(B,e,t),l(e,oe,t),l(e,p,t),l(e,se,t),l(e,C,t),l(e,ie,t),h(R,e,t),l(e,ne,t),l(e,S,t),re=!0},p:$e,i(e){re||(b(M.$$.fragment,e),b(J.$$.fragment,e),b(U.$$.fragment,e),b($.$$.fragment,e),b(H.$$.fragment,e),b(G.$$.fragment,e),b(B.$$.fragment,e),b(R.$$.fragment,e),re=!0)},o(e){y(M.$$.fragment,e),y(J.$$.fragment,e),y(U.$$.fragment,e),y($.$$.fragment,e),y(H.$$.fragment,e),y(G.$$.fragment,e),y(B.$$.fragment,e),y(R.$$.fragment,e),re=!1},d(e){e&&(a(F),a(Y),a(z),a(L),a(N),a(T),a(Q),a(E),a(x),a(V),a(I),a(q),a(X),a(j),a(A),a(m),a(P),a(v),a(D),a(K),a(k),a(O),a(Z),a(ee),a(te),a(c),a(ae),a(W),a(le),a(oe),a(p),a(se),a(C),a(ie),a(ne),a(S)),a(u),w(M,e),w(J,e),w(U,e),w($,e),w(H,e),w(G,e),w(B,e),w(R,e)}}}const Ce='{"title":"Integrations with the Hugging Face Hub","local":"integrations-with-the-hugging-face-hub","sections":[{"title":"Loading models from the Hugging Face Hub","local":"loading-models-from-the-hugging-face-hub","sections":[],"depth":3},{"title":"Loading from Hugging Face Spaces","local":"loading-from-hugging-face-spaces","sections":[],"depth":3}],"depth":1}';function Re(ue){return je(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Le extends ve{constructor(u){super(),He(this,u,Re,Be,Ie,{})}}export{Le as component};
