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