import{s as Je,f as Ce,n as be,o as ge}from"../chunks/scheduler.f7e1785c.js";import{S as Ae,i as Ie,g as p,s as a,r as V,A as Be,h as i,f as t,c as n,j as ie,u as E,x as M,k as m,y as _e,a as s,v as $,d as R,t as x,w as W}from"../chunks/index.9f8f0838.js";import{C as pe}from"../chunks/CodeBlock.4baef5d7.js";import{H as Ve,E as Ee}from"../chunks/getInferenceSnippets.ba5f4cd0.js";function $e(oe){let r,v,Z,Q,c,G,u,Me='现在我们已经对迪维希语语音识别微调了 Whisper 模型，让我们继续前进，构建一个 <a href="https://gradio.app" rel="nofollow">Gradio</a> demo 来向社区展示它！',S,y,re=`首先，我们需要使用 <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> 来进行零样本语音识别：`,N,d,Y,j,me=`其次，我们将定义一个函数，该函数接收输入音频的文件路径并将其输入 pipeline。在这里，pipeline 会自动加载音频文件，
将其重采样到正确的采样率，并使用模型运行推理。然后我们可以简单地返回转写文本作为函数的输出。
为了确保我们的模型可以处理任意长度的音频输入，我们将启用 <em>分块</em>，正如 <a href="asr_models">预训练模型</a> 章节所描述的：`,H,w,z,U,ce='我们将使用 Gradio 的 <a href="https://gradio.app/docs/#blocks" rel="nofollow">blocks</a> 功能在我们的 demo 中启动两个标签页：一个用于麦克风转写，另一个用于文件上传。',F,h,q,T,ue="最后，我们使用刚刚定义的两个 blocks 启动 Gradio demo：",X,f,P,J,ye="这将启动一个类似于在 Hugging Face Space 上运行的 Gradio demo：",L,o,de,O,C,je="如果您希望在 Hugging Face Hub 上托管您的 demo，您可以使用这个 Space 作为您微调的模型的模板。",K,b,we='点击链接将模板 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>',D,g,Ue="我们建议将您的 Space 命名为与您的微调模型类似的名称（例如 whisper-small-dv-demo）并将可见性设置为“公开”。",ee,A,he=`将 Space 复制到您的账户后，请点击“Files and versions”->“app.py”->“edit”，然后更改模型标识符为您的微调模型（第6行）。滚动到页面底部并点击
“Commit changes to main”，demo 将重启，这次使用的是您的微调模型。您可以与您的朋友和家人分享这个 demo，以便他们可以使用您训练的模型！`,le,I,Te='查看我们的视频教程，以更好地了解如何复制 Space 👉️ <a href="https://www.youtube.com/watch?v=VQYuvl6-9VE" rel="nofollow">YouTube 视频</a>',te,B,fe="我们期待在 Hub 上看到您的 demos！",se,_,ae,k,ne;return c=new Ve({props:{title:"用 Gradio 创建 demo",local:"用-gradio-创建-demo",headingTag:"h1"}}),d=new pe({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 pe({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}}),h=new pe({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}}),f=new pe({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}}),_=new Ee({props:{source:"https://github.com/huggingface/audio-transformers-course/blob/main/chapters/zh-CN/chapter5/demo.mdx"}}),{c(){r=p("meta"),v=a(),Z=p("p"),Q=a(),V(c.$$.fragment),G=a(),u=p("p"),u.innerHTML=Me,S=a(),y=p("p"),y.innerHTML=re,N=a(),V(d.$$.fragment),Y=a(),j=p("p"),j.innerHTML=me,H=a(),V(w.$$.fragment),z=a(),U=p("p"),U.innerHTML=ce,F=a(),V(h.$$.fragment),q=a(),T=p("p"),T.textContent=ue,X=a(),V(f.$$.fragment),P=a(),J=p("p"),J.textContent=ye,L=a(),o=p("iframe"),O=a(),C=p("p"),C.textContent=je,K=a(),b=p("p"),b.innerHTML=we,D=a(),g=p("p"),g.textContent=Ue,ee=a(),A=p("p"),A.textContent=he,le=a(),I=p("p"),I.innerHTML=Te,te=a(),B=p("p"),B.textContent=fe,se=a(),V(_.$$.fragment),ae=a(),k=p("p"),this.h()},l(e){const l=Be("svelte-u9bgzb",document.head);r=i(l,"META",{name:!0,content:!0}),l.forEach(t),v=n(e),Z=i(e,"P",{}),ie(Z).forEach(t),Q=n(e),E(c.$$.fragment,e),G=n(e),u=i(e,"P",{"data-svelte-h":!0}),M(u)!=="svelte-7l6kj1"&&(u.innerHTML=Me),S=n(e),y=i(e,"P",{"data-svelte-h":!0}),M(y)!=="svelte-bg3xoj"&&(y.innerHTML=re),N=n(e),E(d.$$.fragment,e),Y=n(e),j=i(e,"P",{"data-svelte-h":!0}),M(j)!=="svelte-1765vil"&&(j.innerHTML=me),H=n(e),E(w.$$.fragment,e),z=n(e),U=i(e,"P",{"data-svelte-h":!0}),M(U)!=="svelte-vfg16e"&&(U.innerHTML=ce),F=n(e),E(h.$$.fragment,e),q=n(e),T=i(e,"P",{"data-svelte-h":!0}),M(T)!=="svelte-1i8mdon"&&(T.textContent=ue),X=n(e),E(f.$$.fragment,e),P=n(e),J=i(e,"P",{"data-svelte-h":!0}),M(J)!=="svelte-1dsx4ri"&&(J.textContent=ye),L=n(e),o=i(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),ie(o).forEach(t),O=n(e),C=i(e,"P",{"data-svelte-h":!0}),M(C)!=="svelte-clm7sv"&&(C.textContent=je),K=n(e),b=i(e,"P",{"data-svelte-h":!0}),M(b)!=="svelte-o410wd"&&(b.innerHTML=we),D=n(e),g=i(e,"P",{"data-svelte-h":!0}),M(g)!=="svelte-hml3bd"&&(g.textContent=Ue),ee=n(e),A=i(e,"P",{"data-svelte-h":!0}),M(A)!=="svelte-100etwn"&&(A.textContent=he),le=n(e),I=i(e,"P",{"data-svelte-h":!0}),M(I)!=="svelte-1djfzil"&&(I.innerHTML=Te),te=n(e),B=i(e,"P",{"data-svelte-h":!0}),M(B)!=="svelte-1qlynro"&&(B.textContent=fe),se=n(e),E(_.$$.fragment,e),ae=n(e),k=i(e,"P",{}),ie(k).forEach(t),this.h()},h(){m(r,"name","hf:doc:metadata"),m(r,"content",Re),Ce(o.src,de="https://course-demos-whisper-small.hf.space")||m(o,"src",de),m(o,"frameborder","0"),m(o,"height","450"),m(o,"title","Gradio app"),m(o,"class","container p-0 flex-grow space-iframe"),m(o,"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"),m(o,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(e,l){_e(document.head,r),s(e,v,l),s(e,Z,l),s(e,Q,l),$(c,e,l),s(e,G,l),s(e,u,l),s(e,S,l),s(e,y,l),s(e,N,l),$(d,e,l),s(e,Y,l),s(e,j,l),s(e,H,l),$(w,e,l),s(e,z,l),s(e,U,l),s(e,F,l),$(h,e,l),s(e,q,l),s(e,T,l),s(e,X,l),$(f,e,l),s(e,P,l),s(e,J,l),s(e,L,l),s(e,o,l),s(e,O,l),s(e,C,l),s(e,K,l),s(e,b,l),s(e,D,l),s(e,g,l),s(e,ee,l),s(e,A,l),s(e,le,l),s(e,I,l),s(e,te,l),s(e,B,l),s(e,se,l),$(_,e,l),s(e,ae,l),s(e,k,l),ne=!0},p:be,i(e){ne||(R(c.$$.fragment,e),R(d.$$.fragment,e),R(w.$$.fragment,e),R(h.$$.fragment,e),R(f.$$.fragment,e),R(_.$$.fragment,e),ne=!0)},o(e){x(c.$$.fragment,e),x(d.$$.fragment,e),x(w.$$.fragment,e),x(h.$$.fragment,e),x(f.$$.fragment,e),x(_.$$.fragment,e),ne=!1},d(e){e&&(t(v),t(Z),t(Q),t(G),t(u),t(S),t(y),t(N),t(Y),t(j),t(H),t(z),t(U),t(F),t(q),t(T),t(X),t(P),t(J),t(L),t(o),t(O),t(C),t(K),t(b),t(D),t(g),t(ee),t(A),t(le),t(I),t(te),t(B),t(se),t(ae),t(k)),t(r),W(c,e),W(d,e),W(w,e),W(h,e),W(f,e),W(_,e)}}}const Re='{"title":"用 Gradio 创建 demo","local":"用-gradio-创建-demo","sections":[],"depth":1}';function xe(oe){return ge(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qe extends Ae{constructor(r){super(),Ie(this,r,xe,$e,Je,{})}}export{Qe as component};
