import{s as Ue,f as ne,n as je,o as Ie}from"../chunks/scheduler.37c15a92.js";import{S as xe,i as He,g as n,s as o,r as B,A as Ge,h as r,f as l,c as i,j as S,u as v,x as M,k as s,y as Ze,a,v as C,d as $,t as W,w as k}from"../chunks/index.2bf4358c.js";import{C as re}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as Be}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{H as ce}from"../chunks/Heading.8ada512a.js";function ve(pe){let u,F,R,V,g,Q,y,N,J,me="为了让你的生活更轻松, Gradio 直接与 Hugging Face Hub 和 Hugging Face Spaces 集成。你可以仅使用 <em>一行代码</em> 从中心和空间加载演示。",X,d,E,b,ue='首先, 从 Hugging Face 通过 Hub 提供的数千个模型中选择一个, 如 <a href="/course/chapter4/2">第四章</a> 中所述。',z,f,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>构建演示的代码, 添加几个示例输入:',_,w,A,h,ge="上述代码将生成以下界面:",q,c,ye,L,T,Je='以这种方式加载模型使用 Hugging Face 的 <a href="https://huggingface.co/inference-api" rel="nofollow">Inference API</a>,而不是将模型加载到内存中。这对于像 GPT-J 或 T0pp这样需要大量 RAM 的大型模型是理想的。',P,U,D,j,de="要从hugs Face Hub加载任何空间并在本地重新创建它, 你可以将 <code>spaces/</code> 传递给 <code>Interface</code>, 再加上空间的名称。",K,I,be="还记得第 1 节中删除图像背景的演示吗? 让我们从 Hugging Face Spaces 加载它:",O,x,ee,p,fe,te,H,we="从Hub或Spaces加载演示的一个很酷的地方是, 你可以通过覆盖任何参数来自定义它们。在这里, 我们添加一个标题并让它与网络摄像头一起使用:",le,G,ae,m,he,se,Z,Te="现在我们已经探索了几种将Gradio与hugs Face Hub集成的方法, 让我们来看看 <code>Interface</code> 类的一些高级功能。这就是下一节的主题！",oe,Y,ie;return g=new ce({props:{title:"与 Hugging Face Hub 整合",local:"与 Hugging Face Hub 整合",headingTag:"h1"}}),y=new Be({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"}]}}),d=new ce({props:{title:"从 Hugging Face Hub 加载模型",local:"从 Hugging Face Hub 加载模型",headingTag:"h3"}}),w=new re({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQXRpdGxlJTIwJTNEJTIwJTIyR1BULUotNkIlMjIlMEFkZXNjcmlwdGlvbiUyMCUzRCUyMCUyMkdyYWRpbyUyMERlbW8lMjBmb3IlMjBHUFQtSiUyMDZCJTJDJTIwYSUyMHRyYW5zZm9ybWVyJTIwbW9kZWwlMjB0cmFpbmVkJTIwdXNpbmclMjBCZW4lMjBXYW5nJ3MlMjBNZXNoJTIwVHJhbnNmb3JtZXIlMjBKQVguJTIwJ0dQVC1KJyUyMHJlZmVycyUyMHRvJTIwdGhlJTIwY2xhc3MlMjBvZiUyMG1vZGVsJTJDJTIwd2hpbGUlMjAnNkInJTIwcmVwcmVzZW50cyUyMHRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5hYmxlJTIwcGFyYW1ldGVycy4lMjBUbyUyMHVzZSUyMGl0JTJDJTIwc2ltcGx5JTIwYWRkJTIweW91ciUyMHRleHQlMkMlMjBvciUyMGNsaWNrJTIwb25lJTIwb2YlMjB0aGUlMjBleGFtcGxlcyUyMHRvJTIwbG9hZCUyMHRoZW0uJTIwUmVhZCUyMG1vcmUlMjBhdCUyMHRoZSUyMGxpbmtzJTIwYmVsb3cuJTIyJTBBYXJ0aWNsZSUyMCUzRCUyMCUyMiUzQ3AlMjBzdHlsZSUzRCd0ZXh0LWFsaWduJTNBJTI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SUyMCUyMCUyMCUyMGV4YW1wbGVzJTNEZXhhbXBsZXMlMkMlMEElMjAlMjAlMjAlMjBlbmFibGVfcXVldWUlM0RUcnVlJTJDJTBBKS5sYXVuY2goKQ==",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()`,wrap:!1}}),U=new ce({props:{title:"从 Hugging Face Spaces 空间加载",local:"从 Hugging Face Spaces 空间加载",headingTag:"h3"}}),x=new re({props:{code:"Z3IuSW50ZXJmYWNlLmxvYWQoJTIyc3BhY2VzJTJGYWJpZGxhYnMlMkZyZW1vdmUtYmclMjIpLmxhdW5jaCgp",highlighted:'gr.Interface.load(<span class="hljs-string">&quot;spaces/abidlabs/remove-bg&quot;</span>).launch()',wrap:!1}}),G=new re({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}}),{c(){u=n("meta"),F=o(),R=n("p"),V=o(),B(g.$$.fragment),Q=o(),B(y.$$.fragment),N=o(),J=n("p"),J.innerHTML=me,X=o(),B(d.$$.fragment),E=o(),b=n("p"),b.innerHTML=ue,z=o(),f=n("p"),f.innerHTML=Me,_=o(),B(w.$$.fragment),A=o(),h=n("p"),h.textContent=ge,q=o(),c=n("iframe"),L=o(),T=n("p"),T.innerHTML=Je,P=o(),B(U.$$.fragment),D=o(),j=n("p"),j.innerHTML=de,K=o(),I=n("p"),I.textContent=be,O=o(),B(x.$$.fragment),ee=o(),p=n("iframe"),te=o(),H=n("p"),H.textContent=we,le=o(),B(G.$$.fragment),ae=o(),m=n("iframe"),se=o(),Z=n("p"),Z.innerHTML=Te,oe=o(),Y=n("p"),this.h()},l(e){const t=Ge("svelte-u9bgzb",document.head);u=r(t,"META",{name:!0,content:!0}),t.forEach(l),F=i(e),R=r(e,"P",{}),S(R).forEach(l),V=i(e),v(g.$$.fragment,e),Q=i(e),v(y.$$.fragment,e),N=i(e),J=r(e,"P",{"data-svelte-h":!0}),M(J)!=="svelte-1iqr7t5"&&(J.innerHTML=me),X=i(e),v(d.$$.fragment,e),E=i(e),b=r(e,"P",{"data-svelte-h":!0}),M(b)!=="svelte-1he69b9"&&(b.innerHTML=ue),z=i(e),f=r(e,"P",{"data-svelte-h":!0}),M(f)!=="svelte-oq0ae0"&&(f.innerHTML=Me),_=i(e),v(w.$$.fragment,e),A=i(e),h=r(e,"P",{"data-svelte-h":!0}),M(h)!=="svelte-142worf"&&(h.textContent=ge),q=i(e),c=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),S(c).forEach(l),L=i(e),T=r(e,"P",{"data-svelte-h":!0}),M(T)!=="svelte-1aiizym"&&(T.innerHTML=Je),P=i(e),v(U.$$.fragment,e),D=i(e),j=r(e,"P",{"data-svelte-h":!0}),M(j)!=="svelte-3o5d20"&&(j.innerHTML=de),K=i(e),I=r(e,"P",{"data-svelte-h":!0}),M(I)!=="svelte-jhzm02"&&(I.textContent=be),O=i(e),v(x.$$.fragment,e),ee=i(e),p=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),S(p).forEach(l),te=i(e),H=r(e,"P",{"data-svelte-h":!0}),M(H)!=="svelte-d4ebv6"&&(H.textContent=we),le=i(e),v(G.$$.fragment,e),ae=i(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),S(m).forEach(l),se=i(e),Z=r(e,"P",{"data-svelte-h":!0}),M(Z)!=="svelte-alc05g"&&(Z.innerHTML=Te),oe=i(e),Y=r(e,"P",{}),S(Y).forEach(l),this.h()},h(){s(u,"name","hf:doc:metadata"),s(u,"content",Ce),ne(c.src,ye="https://course-demos-gpt-j-6B.hf.space")||s(c,"src",ye),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"),ne(p.src,fe="https://course-demos-remove-bg-original.hf.space")||s(p,"src",fe),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"),ne(m.src,he="https://course-demos-Remove-bg.hf.space")||s(m,"src",he),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){Ze(document.head,u),a(e,F,t),a(e,R,t),a(e,V,t),C(g,e,t),a(e,Q,t),C(y,e,t),a(e,N,t),a(e,J,t),a(e,X,t),C(d,e,t),a(e,E,t),a(e,b,t),a(e,z,t),a(e,f,t),a(e,_,t),C(w,e,t),a(e,A,t),a(e,h,t),a(e,q,t),a(e,c,t),a(e,L,t),a(e,T,t),a(e,P,t),C(U,e,t),a(e,D,t),a(e,j,t),a(e,K,t),a(e,I,t),a(e,O,t),C(x,e,t),a(e,ee,t),a(e,p,t),a(e,te,t),a(e,H,t),a(e,le,t),C(G,e,t),a(e,ae,t),a(e,m,t),a(e,se,t),a(e,Z,t),a(e,oe,t),a(e,Y,t),ie=!0},p:je,i(e){ie||($(g.$$.fragment,e),$(y.$$.fragment,e),$(d.$$.fragment,e),$(w.$$.fragment,e),$(U.$$.fragment,e),$(x.$$.fragment,e),$(G.$$.fragment,e),ie=!0)},o(e){W(g.$$.fragment,e),W(y.$$.fragment,e),W(d.$$.fragment,e),W(w.$$.fragment,e),W(U.$$.fragment,e),W(x.$$.fragment,e),W(G.$$.fragment,e),ie=!1},d(e){e&&(l(F),l(R),l(V),l(Q),l(N),l(J),l(X),l(E),l(b),l(z),l(f),l(_),l(A),l(h),l(q),l(c),l(L),l(T),l(P),l(D),l(j),l(K),l(I),l(O),l(ee),l(p),l(te),l(H),l(le),l(ae),l(m),l(se),l(Z),l(oe),l(Y)),l(u),k(g,e),k(y,e),k(d,e),k(w,e),k(U,e),k(x,e),k(G,e)}}}const Ce='{"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 $e(pe){return Ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Fe extends xe{constructor(u){super(),He(this,u,$e,ve,Ue,{})}}export{Fe as component};
