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