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