import{s as Ie,f as ce,n as xe,o as Ge}from"../chunks/scheduler.37c15a92.js";import{S as Ze,i as $e,g as i,s as o,r as g,A as ve,h as r,f as l,c as n,j as Q,u as y,x as M,k as s,y as Be,a,v as f,d as h,t as J,w as b}from"../chunks/index.2bf4358c.js";import{C as pe}from"../chunks/CodeBlock.4e987730.js";import{D as He}from"../chunks/DocNotebookDropdown.efc1fb7c.js";import{H as me,E as Ce}from"../chunks/getInferenceSnippets.80a69898.js";function We(ue){let u,S,Y,E,d,N,w,X,T,Me="為了讓你的生活更輕鬆, Gradio 直接與 Hugging Face Hub 和 Hugging Face Spaces 集成。你可以僅使用 <em>一行代碼</em> 從中心和空間加載演示。",F,U,_,j,ge='首先, 從 Hugging Face 通過 Hub 提供的數千個模型中選擇一個, 如 <a href="/course/chapter4/2">第四章</a> 中所述。',z,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,G,fe="上述代碼將生成以下界面:",L,c,he,P,Z,Je='以這種方式加載模型使用 Hugging Face 的 <a href="https://huggingface.co/inference-api" rel="nofollow">Inference API</a>,而不是將模型加載到內存中。這對於像 GPT-J 或 T0pp這樣需要大量 RAM 的大型模型是理想的。',D,$,K,v,be="要從hugs Face Hub加載任何空間並在本地重新創建它, 你可以將 <code>spaces/</code> 傳遞給 <code>Interface</code>, 再加上空間的名稱。",O,B,de="還記得第 1 節中刪除圖像背景的演示嗎? 讓我們從 Hugging Face Spaces 加載它:",ee,H,te,p,we,le,C,Te="從Hub或Spaces加載演示的一個很酷的地方是, 你可以通過覆蓋任何參數來自定義它們。在這裡, 我們添加一個標題並讓它與網絡攝像頭一起使用:",ae,W,se,m,Ue,oe,k,je="現在我們已經探索了幾種將Gradio與hugs Face Hub集成的方法, 讓我們來看看 <code>Interface</code> 類的一些高級功能。這就是下一節的主題！",ne,R,ie,V,re;return d=new me({props:{title:"與 Hugging Face Hub 整合",local:"與-hugging-face-hub-整合",headingTag:"h1"}}),w=new He({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:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQXRpdGxlJTIwJTNEJTIwJTIyR1BULUotNkIlMjIlMEFkZXNjcmlwdGlvbiUyMCUzRCUyMCUyMkdyYWRpbyUyMERlbW8lMjBmb3IlMjBHUFQtSiUyMDZCJTJDJTIwYSUyMHRyYW5zZm9ybWVyJTIwbW9kZWwlMjB0cmFpbmVkJTIwdXNpbmclMjBCZW4lMjBXYW5nJ3MlMjBNZXNoJTIwVHJhbnNmb3JtZXIlMjBKQVguJTIwJ0dQVC1KJyUyMHJlZmVycyUyMHRvJTIwdGhlJTIwY2xhc3MlMjBvZiUyMG1vZGVsJTJDJTIwd2hpbGUlMjAnNkInJTIwcmVwcmVzZW50cyUyMHRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5hYmxlJTIwcGFyYW1ldGVycy4lMjBUbyUyMHVzZSUyMGl0JTJDJTIwc2ltcGx5JTIwYWRkJTIweW91ciUyMHRleHQlMkMlMjBvciUyMGNsaWNrJTIwb25lJTIwb2YlMjB0aGUlMjBleGFtcGxlcyUyMHRvJTIwbG9hZCUyMHRoZW0uJTIwUmVhZCUyMG1vcmUlMjBhdCUyMHRoZSUyMGxpbmtzJTIwYmVsb3cuJTIyJTBBYXJ0aWNsZSUyMCUzRCUyMCUyMiUzQ3A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AlMjBhcnRpY2xlJTNEYXJ0aWNsZSUyQyUwQSUyMCUyMCUyMCUyMGV4YW1wbGVzJTNEZXhhbXBsZXMlMkMlMEElMjAlMjAlMjAlMjBlbmFibGVfcXVldWUlM0RUcnVlJTJDJTBBKS5sYXVuY2goKQ==",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}}),$=new me({props:{title:"從 Hugging Face Spaces 空間加載",local:"從-hugging-face-spaces-空間加載",headingTag:"h3"}}),H=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-TW/chapter9/5.mdx"}}),{c(){u=i("meta"),S=o(),Y=i("p"),E=o(),g(d.$$.fragment),N=o(),g(w.$$.fragment),X=o(),T=i("p"),T.innerHTML=Me,F=o(),g(U.$$.fragment),_=o(),j=i("p"),j.innerHTML=ge,z=o(),I=i("p"),I.innerHTML=ye,A=o(),g(x.$$.fragment),q=o(),G=i("p"),G.textContent=fe,L=o(),c=i("iframe"),P=o(),Z=i("p"),Z.innerHTML=Je,D=o(),g($.$$.fragment),K=o(),v=i("p"),v.innerHTML=be,O=o(),B=i("p"),B.textContent=de,ee=o(),g(H.$$.fragment),te=o(),p=i("iframe"),le=o(),C=i("p"),C.textContent=Te,ae=o(),g(W.$$.fragment),se=o(),m=i("iframe"),oe=o(),k=i("p"),k.innerHTML=je,ne=o(),g(R.$$.fragment),ie=o(),V=i("p"),this.h()},l(e){const t=ve("svelte-u9bgzb",document.head);u=r(t,"META",{name:!0,content:!0}),t.forEach(l),S=n(e),Y=r(e,"P",{}),Q(Y).forEach(l),E=n(e),y(d.$$.fragment,e),N=n(e),y(w.$$.fragment,e),X=n(e),T=r(e,"P",{"data-svelte-h":!0}),M(T)!=="svelte-pi5nrq"&&(T.innerHTML=Me),F=n(e),y(U.$$.fragment,e),_=n(e),j=r(e,"P",{"data-svelte-h":!0}),M(j)!=="svelte-1nyj3v3"&&(j.innerHTML=ge),z=n(e),I=r(e,"P",{"data-svelte-h":!0}),M(I)!=="svelte-1yyrm88"&&(I.innerHTML=ye),A=n(e),y(x.$$.fragment,e),q=n(e),G=r(e,"P",{"data-svelte-h":!0}),M(G)!=="svelte-1rnenil"&&(G.textContent=fe),L=n(e),c=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Q(c).forEach(l),P=n(e),Z=r(e,"P",{"data-svelte-h":!0}),M(Z)!=="svelte-1lih2u2"&&(Z.innerHTML=Je),D=n(e),y($.$$.fragment,e),K=n(e),v=r(e,"P",{"data-svelte-h":!0}),M(v)!=="svelte-1wgfb6m"&&(v.innerHTML=be),O=n(e),B=r(e,"P",{"data-svelte-h":!0}),M(B)!=="svelte-n133xu"&&(B.textContent=de),ee=n(e),y(H.$$.fragment,e),te=n(e),p=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Q(p).forEach(l),le=n(e),C=r(e,"P",{"data-svelte-h":!0}),M(C)!=="svelte-1nr7jv2"&&(C.textContent=Te),ae=n(e),y(W.$$.fragment,e),se=n(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Q(m).forEach(l),oe=n(e),k=r(e,"P",{"data-svelte-h":!0}),M(k)!=="svelte-37gjek"&&(k.innerHTML=je),ne=n(e),y(R.$$.fragment,e),ie=n(e),V=r(e,"P",{}),Q(V).forEach(l),this.h()},h(){s(u,"name","hf:doc:metadata"),s(u,"content",ke),ce(c.src,he="https://course-demos-gpt-j-6B.hf.space")||s(c,"src",he),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,S,t),a(e,Y,t),a(e,E,t),f(d,e,t),a(e,N,t),f(w,e,t),a(e,X,t),a(e,T,t),a(e,F,t),f(U,e,t),a(e,_,t),a(e,j,t),a(e,z,t),a(e,I,t),a(e,A,t),f(x,e,t),a(e,q,t),a(e,G,t),a(e,L,t),a(e,c,t),a(e,P,t),a(e,Z,t),a(e,D,t),f($,e,t),a(e,K,t),a(e,v,t),a(e,O,t),a(e,B,t),a(e,ee,t),f(H,e,t),a(e,te,t),a(e,p,t),a(e,le,t),a(e,C,t),a(e,ae,t),f(W,e,t),a(e,se,t),a(e,m,t),a(e,oe,t),a(e,k,t),a(e,ne,t),f(R,e,t),a(e,ie,t),a(e,V,t),re=!0},p:xe,i(e){re||(h(d.$$.fragment,e),h(w.$$.fragment,e),h(U.$$.fragment,e),h(x.$$.fragment,e),h($.$$.fragment,e),h(H.$$.fragment,e),h(W.$$.fragment,e),h(R.$$.fragment,e),re=!0)},o(e){J(d.$$.fragment,e),J(w.$$.fragment,e),J(U.$$.fragment,e),J(x.$$.fragment,e),J($.$$.fragment,e),J(H.$$.fragment,e),J(W.$$.fragment,e),J(R.$$.fragment,e),re=!1},d(e){e&&(l(S),l(Y),l(E),l(N),l(X),l(T),l(F),l(_),l(j),l(z),l(I),l(A),l(q),l(G),l(L),l(c),l(P),l(Z),l(D),l(K),l(v),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(ne),l(ie),l(V)),l(u),b(d,e),b(w,e),b(U,e),b(x,e),b($,e),b(H,e),b(W,e),b(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 Ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ne extends Ze{constructor(u){super(),$e(this,u,Re,We,Ie,{})}}export{Ne as component};
