import{S as Et,i as Tt,s as qt,e as s,k as u,w as J,t as c,M as Pt,c as l,d as t,m as h,a as n,x as L,h as p,b as o,N as et,G as a,g as i,y as M,L as At,q as C,o as N,B as R,v as Ft}from"../../chunks/vendor-hf-doc-builder.js";import{I as tt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as at}from"../../chunks/CodeBlock-hf-doc-builder.js";import{C as It}from"../../chunks/CourseFloatingBanner-hf-doc-builder.js";function St(ot){let w,oe,v,$,U,q,Te,W,qe,re,P,se,_,Pe,X,Ae,Fe,le,y,k,Y,A,Ie,K,Se,ie,m,Ge,Q,je,Be,V,Je,Le,Z,Me,Ce,F,Ne,Re,ne,I,ce,z,ze,pe,f,rt,ue,H,Oe,S,De,Ue,he,x,E,ee,G,We,te,Xe,me,O,Ye,fe,j,ge,g,st,de,D,Ke,be,B,we,d,lt,ve,T,Qe,ae,Ve,Ze,ye;return q=new tt({}),P=new It({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"}]}}),A=new tt({}),I=new at({props:{code:`import gradio as gr

title = "GPT-J-6B"
description = "Gradio Demo for GPT-J 6B, a transformer model trained using Ben Wang's Mesh Transformer JAX. 'GPT-J' refers to the class of model, while '6B' 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."
article = "<p style='text-align: center'><a href='https://github.com/kingoflolz/mesh-transformer-jax' target='_blank'>GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model</a></p>"
examples = [
    ["The tower is 324 metres (1,063 ft) tall,"],
    ["The Moon's orbit around Earth has"],
    ["The smooth Borealis basin in the Northern Hemisphere covers 40%"],
]
gr.Interface.load(
    "huggingface/EleutherAI/gpt-j-6B",
    inputs=gr.Textbox(lines=5, label="Input Text"),
    title=title,
    description=description,
    article=article,
    examples=examples,
    enable_queue=True,
).launch()`,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>
examples = [
    [<span class="hljs-string">&quot;The tower is 324 metres (1,063 ft) tall,&quot;</span>],
    [<span class="hljs-string">&quot;The Moon&#x27;s orbit around Earth has&quot;</span>],
    [<span class="hljs-string">&quot;The smooth Borealis basin in the Northern Hemisphere covers 40%&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,
    examples=examples,
    enable_queue=<span class="hljs-literal">True</span>,
).launch()`}}),G=new tt({}),j=new at({props:{code:'gr.Interface.load("spaces/abidlabs/remove-bg").launch()',highlighted:'gr.Interface.load(<span class="hljs-string">&quot;spaces/abidlabs/remove-bg&quot;</span>).launch()'}}),B=new at({props:{code:`gr.Interface.load(
    "spaces/abidlabs/remove-bg", inputs="webcam", title="Remove your webcam background!"
).launch()`,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()`}}),{c(){w=s("meta"),oe=u(),v=s("h1"),$=s("a"),U=s("span"),J(q.$$.fragment),Te=u(),W=s("span"),qe=c("Integrations with the Hugging Face Hub"),re=u(),J(P.$$.fragment),se=u(),_=s("p"),Pe=c(`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 `),X=s("em"),Ae=c("one line of code"),Fe=c("."),le=u(),y=s("h3"),k=s("a"),Y=s("span"),J(A.$$.fragment),Ie=u(),K=s("span"),Se=c("Loading models from the Hugging Face Hub"),ie=c(`

To start with, choose one of the thousands of models Hugging Face offers through the Hub, as described in [Chapter 4](/course/chapter4/2).
`),m=s("p"),Ge=c("Using the special "),Q=s("code"),je=c("Interface.load()"),Be=c(" method, you pass "),V=s("code"),Je=c('"model/"'),Le=c(" (or, equivalently, "),Z=s("code"),Me=c('"huggingface/"'),Ce=c(`)
followed by the model name.
For example, here is the code to build a demo for `),F=s("a"),Ne=c("GPT-J"),Re=c(", a large language model, add a couple of example inputs:"),ne=u(),J(I.$$.fragment),ce=u(),z=s("p"),ze=c("The code above will produce the interface below:"),pe=u(),f=s("iframe"),ue=u(),H=s("p"),Oe=c("Loading a model in this way uses Hugging Face\u2019s "),S=s("a"),De=c("Inference API"),Ue=c(`,
instead of loading the model in memory. This is ideal for huge models like GPT-J or T0pp which
require lots of RAM.`),he=u(),x=s("h3"),E=s("a"),ee=s("span"),J(G.$$.fragment),We=u(),te=s("span"),Xe=c("Loading from Hugging Face Spaces"),me=c("\n\nTo load any Space from the Hugging Face Hub and recreate it locally, you can pass `spaces/` to the `Interface`, followed by the name of the Space.\n"),O=s("p"),Ye=c("Remember the demo from section 1 that removes the background of an image? Let\u2019s load it from Hugging Face Spaces:"),fe=u(),J(j.$$.fragment),ge=u(),g=s("iframe"),de=u(),D=s("p"),Ke=c(`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:`),be=u(),J(B.$$.fragment),we=u(),d=s("iframe"),ve=u(),T=s("p"),Qe=c("Now that we\u2019ve explored a few ways to integrate Gradio with the Hugging Face Hub, let\u2019s take a look at some advanced features of the "),ae=s("code"),Ve=c("Interface"),Ze=c(" class. That\u2019s the topic of the next section!"),this.h()},l(e){const r=Pt('[data-svelte="svelte-1phssyn"]',document.head);w=l(r,"META",{name:!0,content:!0}),r.forEach(t),oe=h(e),v=l(e,"H1",{class:!0});var xe=n(v);$=l(xe,"A",{id:!0,class:!0,href:!0});var it=n($);U=l(it,"SPAN",{});var nt=n(U);L(q.$$.fragment,nt),nt.forEach(t),it.forEach(t),Te=h(xe),W=l(xe,"SPAN",{});var ct=n(W);qe=p(ct,"Integrations with the Hugging Face Hub"),ct.forEach(t),xe.forEach(t),re=h(e),L(P.$$.fragment,e),se=h(e),_=l(e,"P",{});var $e=n(_);Pe=p($e,`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 `),X=l($e,"EM",{});var pt=n(X);Ae=p(pt,"one line of code"),pt.forEach(t),Fe=p($e,"."),$e.forEach(t),le=h(e),y=l(e,"H3",{class:!0});var _e=n(y);k=l(_e,"A",{id:!0,class:!0,href:!0});var ut=n(k);Y=l(ut,"SPAN",{});var ht=n(Y);L(A.$$.fragment,ht),ht.forEach(t),ut.forEach(t),Ie=h(_e),K=l(_e,"SPAN",{});var mt=n(K);Se=p(mt,"Loading models from the Hugging Face Hub"),mt.forEach(t),_e.forEach(t),ie=p(e,`

To start with, choose one of the thousands of models Hugging Face offers through the Hub, as described in [Chapter 4](/course/chapter4/2).
`),m=l(e,"P",{});var b=n(m);Ge=p(b,"Using the special "),Q=l(b,"CODE",{});var ft=n(Q);je=p(ft,"Interface.load()"),ft.forEach(t),Be=p(b," method, you pass "),V=l(b,"CODE",{});var gt=n(V);Je=p(gt,'"model/"'),gt.forEach(t),Le=p(b," (or, equivalently, "),Z=l(b,"CODE",{});var dt=n(Z);Me=p(dt,'"huggingface/"'),dt.forEach(t),Ce=p(b,`)
followed by the model name.
For example, here is the code to build a demo for `),F=l(b,"A",{href:!0,rel:!0});var bt=n(F);Ne=p(bt,"GPT-J"),bt.forEach(t),Re=p(b,", a large language model, add a couple of example inputs:"),b.forEach(t),ne=h(e),L(I.$$.fragment,e),ce=h(e),z=l(e,"P",{});var wt=n(z);ze=p(wt,"The code above will produce the interface below:"),wt.forEach(t),pe=h(e),f=l(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),n(f).forEach(t),ue=h(e),H=l(e,"P",{});var ke=n(H);Oe=p(ke,"Loading a model in this way uses Hugging Face\u2019s "),S=l(ke,"A",{href:!0,rel:!0});var vt=n(S);De=p(vt,"Inference API"),vt.forEach(t),Ue=p(ke,`,
instead of loading the model in memory. This is ideal for huge models like GPT-J or T0pp which
require lots of RAM.`),ke.forEach(t),he=h(e),x=l(e,"H3",{class:!0});var He=n(x);E=l(He,"A",{id:!0,class:!0,href:!0});var yt=n(E);ee=l(yt,"SPAN",{});var xt=n(ee);L(G.$$.fragment,xt),xt.forEach(t),yt.forEach(t),We=h(He),te=l(He,"SPAN",{});var $t=n(te);Xe=p($t,"Loading from Hugging Face Spaces"),$t.forEach(t),He.forEach(t),me=p(e,"\n\nTo load any Space from the Hugging Face Hub and recreate it locally, you can pass `spaces/` to the `Interface`, followed by the name of the Space.\n"),O=l(e,"P",{});var _t=n(O);Ye=p(_t,"Remember the demo from section 1 that removes the background of an image? Let\u2019s load it from Hugging Face Spaces:"),_t.forEach(t),fe=h(e),L(j.$$.fragment,e),ge=h(e),g=l(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),n(g).forEach(t),de=h(e),D=l(e,"P",{});var kt=n(D);Ke=p(kt,`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:`),kt.forEach(t),be=h(e),L(B.$$.fragment,e),we=h(e),d=l(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),n(d).forEach(t),ve=h(e),T=l(e,"P",{});var Ee=n(T);Qe=p(Ee,"Now that we\u2019ve explored a few ways to integrate Gradio with the Hugging Face Hub, let\u2019s take a look at some advanced features of the "),ae=l(Ee,"CODE",{});var Ht=n(ae);Ve=p(Ht,"Interface"),Ht.forEach(t),Ze=p(Ee," class. That\u2019s the topic of the next section!"),Ee.forEach(t),this.h()},h(){o(w,"name","hf:doc:metadata"),o(w,"content",JSON.stringify(Gt)),o($,"id","integrations-with-the-hugging-face-hub"),o($,"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($,"href","#integrations-with-the-hugging-face-hub"),o(v,"class","relative group"),o(k,"id","loading-models-from-the-hugging-face-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","#loading-models-from-the-hugging-face-hub"),o(y,"class","relative group"),o(F,"href","https://huggingface.co/EleutherAI/gpt-j-6B"),o(F,"rel","nofollow"),et(f.src,rt="https://course-demos-gpt-j-6B.hf.space")||o(f,"src",rt),o(f,"frameborder","0"),o(f,"height","750"),o(f,"title","Gradio app"),o(f,"class","container p-0 flex-grow space-iframe"),o(f,"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(f,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),o(S,"href","https://huggingface.co/inference-api"),o(S,"rel","nofollow"),o(E,"id","loading-from-hugging-face-spaces"),o(E,"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(E,"href","#loading-from-hugging-face-spaces"),o(x,"class","relative group"),et(g.src,st="https://course-demos-remove-bg-original.hf.space")||o(g,"src",st),o(g,"frameborder","0"),o(g,"height","650"),o(g,"title","Gradio app"),o(g,"class","container p-0 flex-grow space-iframe"),o(g,"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(g,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),et(d.src,lt="https://course-demos-Remove-bg.hf.space")||o(d,"src",lt),o(d,"frameborder","0"),o(d,"height","550"),o(d,"title","Gradio app"),o(d,"class","container p-0 flex-grow space-iframe"),o(d,"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(d,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(e,r){a(document.head,w),i(e,oe,r),i(e,v,r),a(v,$),a($,U),M(q,U,null),a(v,Te),a(v,W),a(W,qe),i(e,re,r),M(P,e,r),i(e,se,r),i(e,_,r),a(_,Pe),a(_,X),a(X,Ae),a(_,Fe),i(e,le,r),i(e,y,r),a(y,k),a(k,Y),M(A,Y,null),a(y,Ie),a(y,K),a(K,Se),i(e,ie,r),i(e,m,r),a(m,Ge),a(m,Q),a(Q,je),a(m,Be),a(m,V),a(V,Je),a(m,Le),a(m,Z),a(Z,Me),a(m,Ce),a(m,F),a(F,Ne),a(m,Re),i(e,ne,r),M(I,e,r),i(e,ce,r),i(e,z,r),a(z,ze),i(e,pe,r),i(e,f,r),i(e,ue,r),i(e,H,r),a(H,Oe),a(H,S),a(S,De),a(H,Ue),i(e,he,r),i(e,x,r),a(x,E),a(E,ee),M(G,ee,null),a(x,We),a(x,te),a(te,Xe),i(e,me,r),i(e,O,r),a(O,Ye),i(e,fe,r),M(j,e,r),i(e,ge,r),i(e,g,r),i(e,de,r),i(e,D,r),a(D,Ke),i(e,be,r),M(B,e,r),i(e,we,r),i(e,d,r),i(e,ve,r),i(e,T,r),a(T,Qe),a(T,ae),a(ae,Ve),a(T,Ze),ye=!0},p:At,i(e){ye||(C(q.$$.fragment,e),C(P.$$.fragment,e),C(A.$$.fragment,e),C(I.$$.fragment,e),C(G.$$.fragment,e),C(j.$$.fragment,e),C(B.$$.fragment,e),ye=!0)},o(e){N(q.$$.fragment,e),N(P.$$.fragment,e),N(A.$$.fragment,e),N(I.$$.fragment,e),N(G.$$.fragment,e),N(j.$$.fragment,e),N(B.$$.fragment,e),ye=!1},d(e){t(w),e&&t(oe),e&&t(v),R(q),e&&t(re),R(P,e),e&&t(se),e&&t(_),e&&t(le),e&&t(y),R(A),e&&t(ie),e&&t(m),e&&t(ne),R(I,e),e&&t(ce),e&&t(z),e&&t(pe),e&&t(f),e&&t(ue),e&&t(H),e&&t(he),e&&t(x),R(G),e&&t(me),e&&t(O),e&&t(fe),R(j,e),e&&t(ge),e&&t(g),e&&t(de),e&&t(D),e&&t(be),R(B,e),e&&t(we),e&&t(d),e&&t(ve),e&&t(T)}}}const Gt={local:"integrations-with-the-hugging-face-hub",sections:[{local:"loading-models-from-the-hugging-face-hub",title:"Loading models from the Hugging Face Hub"},{local:"loading-from-hugging-face-spaces",title:"Loading from Hugging Face Spaces"}],title:"Integrations with the Hugging Face Hub"};function jt(ot){return Ft(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ct extends Et{constructor(w){super();Tt(this,w,jt,St,qt,{})}}export{Ct as default,Gt as metadata};
