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