import{s as Ie,f as ce,n as $e,o as je}from"../chunks/scheduler.37c15a92.js";import{S as He,i as Ze,g as n,s as o,r as f,A as ve,h as r,f as l,c as i,j as F,u as M,x as g,k as s,y as Ge,a,v as d,d as b,t as y,w}from"../chunks/index.2bf4358c.js";import{C as pe}from"../chunks/CodeBlock.4e987730.js";import{D as ke}from"../chunks/DocNotebookDropdown.efc1fb7c.js";import{H as me,E as We}from"../chunks/getInferenceSnippets.8229e22a.js";function Ce(ue){let u,_,S,N,J,Q,h,V,T,ge="如果觉得本地加载模型有些麻烦，为了让使用模型更轻松，Gradio 可以直接与 Hugging Face Hub 和 Hugging Face Spaces 集成。你可以仅使用一行代码从 Hub 和 Spaces 加载在线的数千个模型。",z,U,q,x,fe='首先，在 <a href="/course/chapter4/2">第四章</a> 中所述的数千个模型中选择一个。',E,I,Me='使用特殊的 <code>Interface.load()</code> 方法，你可以传递 <code>&quot;model/模型名称&quot;</code> （或等效的 <code>&quot;huggingface/模型名称&quot;</code> ）。例如，下面的代码是使用 <a href="https://huggingface.co/EleutherAI/gpt-j-6B" rel="nofollow">GPT-J</a> 构建的一个演示，它是一个大型语言模型，示例代码如下：',X,$,A,j,de="运行上述代码将生成以下界面：",P,c,be,L,H,ye='以这种方式加载模型使用的是 Hugging Face 的 <a href="https://huggingface.co/inference-api" rel="nofollow">Inference API</a> ，而不是将模型加载到内存中。这对于像 GPT-J 或 T0pp 这样需要大量 RAM 的大型模型是最理想的方式。',D,Z,K,v,we="除了模型，还可以将 <code>spaces/space名称</code> 传递给 Interface，这样就可以在本地修改和运行 Hugging Face Spaces 中的任何 Space。",O,G,Je="还记得第 1 节中删除图像背景的演示吗？让我们从 Hugging Face Spaces 加载它：",ee,k,te,p,he,le,W,Te="从Hub 或 Spaces 加载演示的一个很酷的地方是，你可以通过覆盖任何参数来进行一些自定义的调整。在这里，我们添加一个标题并将输入改为了网络摄像头：",ae,C,se,m,Ue,oe,B,xe="现在我们已经探索了一些将 Gradio 与 hugs Face Hub 集成的方法，在下一节让我们来看看 <code>Interface</code> 类的一些高级功能。",ie,R,ne,Y,re;return J=new me({props:{title:"与 Hugging Face Hub 整合",local:"与 Hugging Face Hub 整合",headingTag:"h1"}}),h=new ke({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter9/section5.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter9/section5.ipynb"}]}}),U=new me({props:{title:"从 Hugging Face Hub 加载模型",local:"从 Hugging Face Hub 加载模型",headingTag:"h3"}}),$=new pe({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQXRpdGxlJTIwJTNEJTIwJTIyR1BULUotNkIlMjIlMEFkZXNjcmlwdGlvbiUyMCUzRCUyMCUyMkdyYWRpbyUyMERlbW8lMjBmb3IlMjBHUFQtSiUyMDZCJTJDJTIwYSUyMHRyYW5zZm9ybWVyJTIwbW9kZWwlMjB0cmFpbmVkJTIwdXNpbmclMjBCZW4lMjBXYW5nJ3MlMjBNZXNoJTIwVHJhbnNmb3JtZXIlMjBKQVguJTIwJ0dQVC1KJyUyMHJlZmVycyUyMHRvJTIwdGhlJTIwY2xhc3MlMjBvZiUyMG1vZGVsJTJDJTIwd2hpbGUlMjAnNkInJTIwcmVwcmVzZW50cyUyMHRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5hYmxlJTIwcGFyYW1ldGVycy4lMjBUbyUyMHVzZSUyMGl0JTJDJTIwc2ltcGx5JTIwYWRkJTIweW91ciUyMHRleHQlMkMlMjBvciUyMGNsaWNrJTIwb25lJTIwb2YlMjB0aGUlMjBleGFtcGxlcyUyMHRvJTIwbG9hZCUyMHRoZW0uJTIwUmVhZCUyMG1vcmUlMjBhdCUyMHRoZSUyMGxpbmtzJTIwYmVsb3cuJTIyJTBBYXJ0aWNsZSUyMCUzRCUyMCUyMiUzQ3AlMjBzdHlsZSUzRCd0ZXh0LWFsaWduJTNBJTIwY2VudGVyJyUzRSUzQ2ElMjBocmVmJTNEJ2h0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmtpbmdvZmxvbHolMkZtZXNoLXRyYW5zZm9ybWVyLWpheCclMjB0YXJnZXQlM0QnX2JsYW5rJyUzRUdQVC1KLTZCJTNBJTIwQSUyMDYlMjBCaWxsaW9uJTIwUGFyYW1ldGVyJTIwQXV0b3JlZ3Jlc3NpdmUlMjBMYW5ndWFnZSUyME1vZGVsJTNDJTJGYSUzRSUzQyUyRnAlM0UlMjIlMEFnci5JbnRlcmZhY2UubG9hZCglMEElMjAlMjAlMjAlMjAlMjJodWdnaW5nZmFjZSUyRkVsZXV0aGVyQUklMkZncHQtai02QiUyMiUyQyUwQSUyMCUyMCUyMCUyMGlucHV0cyUzRGdyLlRleHRib3gobGluZXMlM0Q1JTJDJTIwbGFiZWwlM0QlMjJJbnB1dCUyMFRleHQlMjIpJTJDJTBBJTIwJTIwJTIwJTIwdGl0bGUlM0R0aXRsZSUyQyUwQSUyMCUyMCUyMCUyMGRlc2NyaXB0aW9uJTNEZGVzY3JpcHRpb24lMkMlMEElMjAlMjAlMjAlMjBhcnRpY2xlJTNEYXJ0aWNsZSUyQyUwQSkubGF1bmNoKCk=",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}}),Z=new me({props:{title:"从 Hugging Face Spaces 中加载",local:"从 Hugging Face Spaces 中加载",headingTag:"h3"}}),k=new pe({props:{code:"Z3IuSW50ZXJmYWNlLmxvYWQoJTIyc3BhY2VzJTJGYWJpZGxhYnMlMkZyZW1vdmUtYmclMjIpLmxhdW5jaCgp",highlighted:'gr.Interface.load(<span class="hljs-string">&quot;spaces/abidlabs/remove-bg&quot;</span>).launch()',wrap:!1}}),C=new pe({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/zh-CN/chapter9/5.mdx"}}),{c(){u=n("meta"),_=o(),S=n("p"),N=o(),f(J.$$.fragment),Q=o(),f(h.$$.fragment),V=o(),T=n("p"),T.textContent=ge,z=o(),f(U.$$.fragment),q=o(),x=n("p"),x.innerHTML=fe,E=o(),I=n("p"),I.innerHTML=Me,X=o(),f($.$$.fragment),A=o(),j=n("p"),j.textContent=de,P=o(),c=n("iframe"),L=o(),H=n("p"),H.innerHTML=ye,D=o(),f(Z.$$.fragment),K=o(),v=n("p"),v.innerHTML=we,O=o(),G=n("p"),G.textContent=Je,ee=o(),f(k.$$.fragment),te=o(),p=n("iframe"),le=o(),W=n("p"),W.textContent=Te,ae=o(),f(C.$$.fragment),se=o(),m=n("iframe"),oe=o(),B=n("p"),B.innerHTML=xe,ie=o(),f(R.$$.fragment),ne=o(),Y=n("p"),this.h()},l(e){const t=ve("svelte-u9bgzb",document.head);u=r(t,"META",{name:!0,content:!0}),t.forEach(l),_=i(e),S=r(e,"P",{}),F(S).forEach(l),N=i(e),M(J.$$.fragment,e),Q=i(e),M(h.$$.fragment,e),V=i(e),T=r(e,"P",{"data-svelte-h":!0}),g(T)!=="svelte-16ur3xn"&&(T.textContent=ge),z=i(e),M(U.$$.fragment,e),q=i(e),x=r(e,"P",{"data-svelte-h":!0}),g(x)!=="svelte-5eqkdq"&&(x.innerHTML=fe),E=i(e),I=r(e,"P",{"data-svelte-h":!0}),g(I)!=="svelte-1ieboek"&&(I.innerHTML=Me),X=i(e),M($.$$.fragment,e),A=i(e),j=r(e,"P",{"data-svelte-h":!0}),g(j)!=="svelte-gnsl9j"&&(j.textContent=de),P=i(e),c=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),F(c).forEach(l),L=i(e),H=r(e,"P",{"data-svelte-h":!0}),g(H)!=="svelte-ah707l"&&(H.innerHTML=ye),D=i(e),M(Z.$$.fragment,e),K=i(e),v=r(e,"P",{"data-svelte-h":!0}),g(v)!=="svelte-x9h5se"&&(v.innerHTML=we),O=i(e),G=r(e,"P",{"data-svelte-h":!0}),g(G)!=="svelte-1c94qi8"&&(G.textContent=Je),ee=i(e),M(k.$$.fragment,e),te=i(e),p=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),F(p).forEach(l),le=i(e),W=r(e,"P",{"data-svelte-h":!0}),g(W)!=="svelte-1kec2x3"&&(W.textContent=Te),ae=i(e),M(C.$$.fragment,e),se=i(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),F(m).forEach(l),oe=i(e),B=r(e,"P",{"data-svelte-h":!0}),g(B)!=="svelte-dju8ct"&&(B.innerHTML=xe),ie=i(e),M(R.$$.fragment,e),ne=i(e),Y=r(e,"P",{}),F(Y).forEach(l),this.h()},h(){s(u,"name","hf:doc:metadata"),s(u,"content",Be),ce(c.src,be="https://course-demos-gpt-j-6B.hf.space")||s(c,"src",be),s(c,"frameborder","0"),s(c,"height","750"),s(c,"title","Gradio app"),s(c,"class","container p-0 flex-grow space-iframe"),s(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"),s(c,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),ce(p.src,he="https://course-demos-remove-bg-original.hf.space")||s(p,"src",he),s(p,"frameborder","0"),s(p,"height","650"),s(p,"title","Gradio app"),s(p,"class","container p-0 flex-grow space-iframe"),s(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"),s(p,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),ce(m.src,Ue="https://course-demos-Remove-bg.hf.space")||s(m,"src",Ue),s(m,"frameborder","0"),s(m,"height","550"),s(m,"title","Gradio app"),s(m,"class","container p-0 flex-grow space-iframe"),s(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"),s(m,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(e,t){Ge(document.head,u),a(e,_,t),a(e,S,t),a(e,N,t),d(J,e,t),a(e,Q,t),d(h,e,t),a(e,V,t),a(e,T,t),a(e,z,t),d(U,e,t),a(e,q,t),a(e,x,t),a(e,E,t),a(e,I,t),a(e,X,t),d($,e,t),a(e,A,t),a(e,j,t),a(e,P,t),a(e,c,t),a(e,L,t),a(e,H,t),a(e,D,t),d(Z,e,t),a(e,K,t),a(e,v,t),a(e,O,t),a(e,G,t),a(e,ee,t),d(k,e,t),a(e,te,t),a(e,p,t),a(e,le,t),a(e,W,t),a(e,ae,t),d(C,e,t),a(e,se,t),a(e,m,t),a(e,oe,t),a(e,B,t),a(e,ie,t),d(R,e,t),a(e,ne,t),a(e,Y,t),re=!0},p:$e,i(e){re||(b(J.$$.fragment,e),b(h.$$.fragment,e),b(U.$$.fragment,e),b($.$$.fragment,e),b(Z.$$.fragment,e),b(k.$$.fragment,e),b(C.$$.fragment,e),b(R.$$.fragment,e),re=!0)},o(e){y(J.$$.fragment,e),y(h.$$.fragment,e),y(U.$$.fragment,e),y($.$$.fragment,e),y(Z.$$.fragment,e),y(k.$$.fragment,e),y(C.$$.fragment,e),y(R.$$.fragment,e),re=!1},d(e){e&&(l(_),l(S),l(N),l(Q),l(V),l(T),l(z),l(q),l(x),l(E),l(I),l(X),l(A),l(j),l(P),l(c),l(L),l(H),l(D),l(K),l(v),l(O),l(G),l(ee),l(te),l(p),l(le),l(W),l(ae),l(se),l(m),l(oe),l(B),l(ie),l(ne),l(Y)),l(u),w(J,e),w(h,e),w(U,e),w($,e),w(Z,e),w(k,e),w(C,e),w(R,e)}}}const Be='{"title":"与 Hugging Face Hub 整合","local":"与 Hugging Face Hub 整合","sections":[{"title":"从 Hugging Face Hub 加载模型","local":"从 Hugging Face Hub 加载模型","sections":[],"depth":3},{"title":"从 Hugging Face Spaces 中加载","local":"从 Hugging Face Spaces 中加载","sections":[],"depth":3}],"depth":1}';function Re(ue){return je(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qe extends He{constructor(u){super(),Ze(this,u,Re,Ce,Ie,{})}}export{Qe as component};
