import{s as hl,f as Jl,n as fl,o as Cl}from"../chunks/scheduler.f6b352c8.js";import{S as bl,i as gl,g as p,s as a,r as R,A as Al,h as i,f as t,c as n,j as nl,u as E,x as o,k as c,y as Il,a as s,v as W,d as x,t as Z,w as k}from"../chunks/index.7f38e934.js";import{C as al}from"../chunks/CodeBlock.2a338b68.js";import{H as Bl}from"../chunks/Heading.333929c4.js";function _l(pl){let r,v,_,Q,m,$,u,il='现在我们已经对迪维希语语音识别微调了 Whisper 模型，让我们继续前进，构建一个 <a href="https://gradio.app" rel="nofollow">Gradio</a> demo 来向社区展示它！',G,y,Ml=`首先，我们需要使用 <code>pipeline()</code> 类加载微调后的检查点——这一点我们从 <a href="asr_models">预训练模型</a> 章节开始就非常熟悉了。
您可以更改 <code>model_id</code> 为您在 Hugging Face Hub 上微调模型的命名空间，或者使用预训练的 <a href="https://huggingface.co/models?sort=downloads&amp;search=openai%2Fwhisper-" rel="nofollow">Whisper 模型</a> 来进行零样本语音识别：`,S,d,N,j,ol=`其次，我们将定义一个函数，该函数接收输入音频的文件路径并将其输入 pipeline。在这里，pipeline 会自动加载音频文件，
将其重采样到正确的采样率，并使用模型运行推理。然后我们可以简单地返回转写文本作为函数的输出。
为了确保我们的模型可以处理任意长度的音频输入，我们将启用 <em>分块</em>，正如 <a href="asr_models">预训练模型</a> 章节所描述的：`,Y,w,H,U,rl='我们将使用 Gradio 的 <a href="https://gradio.app/docs/#blocks" rel="nofollow">blocks</a> 功能在我们的 demo 中启动两个标签页：一个用于麦克风转写，另一个用于文件上传。',F,T,q,h,cl="最后，我们使用刚刚定义的两个 blocks 启动 Gradio demo：",z,J,X,f,ml="这将启动一个类似于在 Hugging Face Space 上运行的 Gradio demo：",P,M,ul,L,C,yl="如果您希望在 Hugging Face Hub 上托管您的 demo，您可以使用这个 Space 作为您微调的模型的模板。",O,b,dl='点击链接将模板 demo 复制到您的账户：<a href="https://huggingface.co/spaces/course-demos/whisper-small?duplicate=true" rel="nofollow">https://huggingface.co/spaces/course-demos/whisper-small?duplicate=true</a>',K,g,jl="我们建议将您的 Space 命名为与您的微调模型类似的名称（例如 whisper-small-dv-demo）并将可见性设置为“公开”。",D,A,wl=`将 Space 复制到您的账户后，请点击“Files and versions”->“app.py”->“edit”，然后更改模型标识符为您的微调模型（第6行）。滚动到页面底部并点击
“Commit changes to main”，demo 将重启，这次使用的是您的微调模型。您可以与您的朋友和家人分享这个 demo，以便他们可以使用您训练的模型！`,ll,I,Ul='查看我们的视频教程，以更好地了解如何复制 Space 👉️ <a href="https://www.youtube.com/watch?v=VQYuvl6-9VE" rel="nofollow">YouTube 视频</a>',el,B,Tl="我们期待在 Hub 上看到您的 demos！",tl,V,sl;return m=new Bl({props:{title:"用 Gradio 创建 demo",local:"用-gradio-创建-demo",headingTag:"h1"}}),d=new al({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzYW5jaGl0LWdhbmRoaSUyRndoaXNwZXItc21hbGwtZHYlMjIlMjAlMjAlMjMlMjAlRTYlOTQlQjklRTQlQjglQkElRTYlODIlQTglRTclOUElODQlRTYlQTglQTElRTUlOUUlOEIlMjBpZCUwQXBpcGUlMjAlM0QlMjBwaXBlbGluZSglMjJhdXRvbWF0aWMtc3BlZWNoLXJlY29nbml0aW9uJTIyJTJDJTIwbW9kZWwlM0Rtb2RlbF9pZCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

model_id = <span class="hljs-string">&quot;sanchit-gandhi/whisper-small-dv&quot;</span>  <span class="hljs-comment"># 改为您的模型 id</span>
pipe = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>, model=model_id)`,wrap:!1}}),w=new al({props:{code:"ZGVmJTIwdHJhbnNjcmliZV9zcGVlY2goZmlsZXBhdGgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmaWxlcGF0aCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1heF9uZXdfdG9rZW5zJTNEMjU2JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ2VuZXJhdGVfa3dhcmdzJTNEJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydGFzayUyMiUzQSUyMCUyMnRyYW5zY3JpYmUlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsYW5ndWFnZSUyMiUzQSUyMCUyMnNpbmhhbGVzZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUyQyUyMCUyMCUyMyUyMCVFNCVCRiVBRSVFNiU5NCVCOSVFNiU4OCU5MCVFNiU4MiVBOCVFNSVCRSVBRSVFOCVCMCU4MyVFOCVCRiU4NyVFNyU5QSU4NCVFOCVBRiVBRCVFOCVBOCU4MCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNodW5rX2xlbmd0aF9zJTNEMzAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBvdXRwdXQlNUIlMjJ0ZXh0JTIyJTVE",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">transcribe_speech</span>(<span class="hljs-params">filepath</span>):
    output = pipe(
        filepath,
        max_new_tokens=<span class="hljs-number">256</span>,
        generate_kwargs={
            <span class="hljs-string">&quot;task&quot;</span>: <span class="hljs-string">&quot;transcribe&quot;</span>,
            <span class="hljs-string">&quot;language&quot;</span>: <span class="hljs-string">&quot;sinhalese&quot;</span>,
        },  <span class="hljs-comment"># 修改成您微调过的语言</span>
        chunk_length_s=<span class="hljs-number">30</span>,
        batch_size=<span class="hljs-number">8</span>,
    )
    <span class="hljs-keyword">return</span> output[<span class="hljs-string">&quot;text&quot;</span>]`,wrap:!1}}),T=new al({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQWRlbW8lMjAlM0QlMjBnci5CbG9ja3MoKSUwQSUwQW1pY190cmFuc2NyaWJlJTIwJTNEJTIwZ3IuSW50ZXJmYWNlKCUwQSUyMCUyMCUyMCUyMGZuJTNEdHJhbnNjcmliZV9zcGVlY2glMkMlMEElMjAlMjAlMjAlMjBpbnB1dHMlM0Rnci5BdWRpbyhzb3VyY2VzJTNEJTIybWljcm9waG9uZSUyMiUyQyUyMHR5cGUlM0QlMjJmaWxlcGF0aCUyMiklMkMlMEElMjAlMjAlMjAlMjBvdXRwdXRzJTNEZ3Iub3V0cHV0cy5UZXh0Ym94KCklMkMlMEEpJTBBJTBBZmlsZV90cmFuc2NyaWJlJTIwJTNEJTIwZ3IuSW50ZXJmYWNlKCUwQSUyMCUyMCUyMCUyMGZuJTNEdHJhbnNjcmliZV9zcGVlY2glMkMlMEElMjAlMjAlMjAlMjBpbnB1dHMlM0Rnci5BdWRpbyhzb3VyY2VzJTNEJTIydXBsb2FkJTIyJTJDJTIwdHlwZSUzRCUyMmZpbGVwYXRoJTIyKSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dHMlM0Rnci5vdXRwdXRzLlRleHRib3goKSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr

demo = gr.Blocks()

mic_transcribe = gr.Interface(
    fn=transcribe_speech,
    inputs=gr.Audio(sources=<span class="hljs-string">&quot;microphone&quot;</span>, <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;filepath&quot;</span>),
    outputs=gr.outputs.Textbox(),
)

file_transcribe = gr.Interface(
    fn=transcribe_speech,
    inputs=gr.Audio(sources=<span class="hljs-string">&quot;upload&quot;</span>, <span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;filepath&quot;</span>),
    outputs=gr.outputs.Textbox(),
)`,wrap:!1}}),J=new al({props:{code:"d2l0aCUyMGRlbW8lM0ElMEElMjAlMjAlMjAlMjBnci5UYWJiZWRJbnRlcmZhY2UoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCbWljX3RyYW5zY3JpYmUlMkMlMjBmaWxlX3RyYW5zY3JpYmUlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUIlMjJUcmFuc2NyaWJlJTIwTWljcm9waG9uZSUyMiUyQyUyMCUyMlRyYW5zY3JpYmUlMjBBdWRpbyUyMEZpbGUlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjApJTBBJTBBZGVtby5sYXVuY2goZGVidWclM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">with</span> demo:
    gr.TabbedInterface(
        [mic_transcribe, file_transcribe],
        [<span class="hljs-string">&quot;Transcribe Microphone&quot;</span>, <span class="hljs-string">&quot;Transcribe Audio File&quot;</span>],
    )

demo.launch(debug=<span class="hljs-literal">True</span>)`,wrap:!1}}),{c(){r=p("meta"),v=a(),_=p("p"),Q=a(),R(m.$$.fragment),$=a(),u=p("p"),u.innerHTML=il,G=a(),y=p("p"),y.innerHTML=Ml,S=a(),R(d.$$.fragment),N=a(),j=p("p"),j.innerHTML=ol,Y=a(),R(w.$$.fragment),H=a(),U=p("p"),U.innerHTML=rl,F=a(),R(T.$$.fragment),q=a(),h=p("p"),h.textContent=cl,z=a(),R(J.$$.fragment),X=a(),f=p("p"),f.textContent=ml,P=a(),M=p("iframe"),L=a(),C=p("p"),C.textContent=yl,O=a(),b=p("p"),b.innerHTML=dl,K=a(),g=p("p"),g.textContent=jl,D=a(),A=p("p"),A.textContent=wl,ll=a(),I=p("p"),I.innerHTML=Ul,el=a(),B=p("p"),B.textContent=Tl,tl=a(),V=p("p"),this.h()},l(l){const e=Al("svelte-u9bgzb",document.head);r=i(e,"META",{name:!0,content:!0}),e.forEach(t),v=n(l),_=i(l,"P",{}),nl(_).forEach(t),Q=n(l),E(m.$$.fragment,l),$=n(l),u=i(l,"P",{"data-svelte-h":!0}),o(u)!=="svelte-7l6kj1"&&(u.innerHTML=il),G=n(l),y=i(l,"P",{"data-svelte-h":!0}),o(y)!=="svelte-bg3xoj"&&(y.innerHTML=Ml),S=n(l),E(d.$$.fragment,l),N=n(l),j=i(l,"P",{"data-svelte-h":!0}),o(j)!=="svelte-1765vil"&&(j.innerHTML=ol),Y=n(l),E(w.$$.fragment,l),H=n(l),U=i(l,"P",{"data-svelte-h":!0}),o(U)!=="svelte-vfg16e"&&(U.innerHTML=rl),F=n(l),E(T.$$.fragment,l),q=n(l),h=i(l,"P",{"data-svelte-h":!0}),o(h)!=="svelte-1i8mdon"&&(h.textContent=cl),z=n(l),E(J.$$.fragment,l),X=n(l),f=i(l,"P",{"data-svelte-h":!0}),o(f)!=="svelte-1dsx4ri"&&(f.textContent=ml),P=n(l),M=i(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),nl(M).forEach(t),L=n(l),C=i(l,"P",{"data-svelte-h":!0}),o(C)!=="svelte-clm7sv"&&(C.textContent=yl),O=n(l),b=i(l,"P",{"data-svelte-h":!0}),o(b)!=="svelte-o410wd"&&(b.innerHTML=dl),K=n(l),g=i(l,"P",{"data-svelte-h":!0}),o(g)!=="svelte-hml3bd"&&(g.textContent=jl),D=n(l),A=i(l,"P",{"data-svelte-h":!0}),o(A)!=="svelte-100etwn"&&(A.textContent=wl),ll=n(l),I=i(l,"P",{"data-svelte-h":!0}),o(I)!=="svelte-1djfzil"&&(I.innerHTML=Ul),el=n(l),B=i(l,"P",{"data-svelte-h":!0}),o(B)!=="svelte-1qlynro"&&(B.textContent=Tl),tl=n(l),V=i(l,"P",{}),nl(V).forEach(t),this.h()},h(){c(r,"name","hf:doc:metadata"),c(r,"content",Vl),Jl(M.src,ul="https://course-demos-whisper-small.hf.space")||c(M,"src",ul),c(M,"frameborder","0"),c(M,"height","450"),c(M,"title","Gradio app"),c(M,"class","container p-0 flex-grow space-iframe"),c(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"),c(M,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(l,e){Il(document.head,r),s(l,v,e),s(l,_,e),s(l,Q,e),W(m,l,e),s(l,$,e),s(l,u,e),s(l,G,e),s(l,y,e),s(l,S,e),W(d,l,e),s(l,N,e),s(l,j,e),s(l,Y,e),W(w,l,e),s(l,H,e),s(l,U,e),s(l,F,e),W(T,l,e),s(l,q,e),s(l,h,e),s(l,z,e),W(J,l,e),s(l,X,e),s(l,f,e),s(l,P,e),s(l,M,e),s(l,L,e),s(l,C,e),s(l,O,e),s(l,b,e),s(l,K,e),s(l,g,e),s(l,D,e),s(l,A,e),s(l,ll,e),s(l,I,e),s(l,el,e),s(l,B,e),s(l,tl,e),s(l,V,e),sl=!0},p:fl,i(l){sl||(x(m.$$.fragment,l),x(d.$$.fragment,l),x(w.$$.fragment,l),x(T.$$.fragment,l),x(J.$$.fragment,l),sl=!0)},o(l){Z(m.$$.fragment,l),Z(d.$$.fragment,l),Z(w.$$.fragment,l),Z(T.$$.fragment,l),Z(J.$$.fragment,l),sl=!1},d(l){l&&(t(v),t(_),t(Q),t($),t(u),t(G),t(y),t(S),t(N),t(j),t(Y),t(H),t(U),t(F),t(q),t(h),t(z),t(X),t(f),t(P),t(M),t(L),t(C),t(O),t(b),t(K),t(g),t(D),t(A),t(ll),t(I),t(el),t(B),t(tl),t(V)),t(r),k(m,l),k(d,l),k(w,l),k(T,l),k(J,l)}}}const Vl='{"title":"用 Gradio 创建 demo","local":"用-gradio-创建-demo","sections":[],"depth":1}';function Rl(pl){return Cl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class kl extends bl{constructor(r){super(),gl(this,r,Rl,_l,hl,{})}}export{kl as component};
