import{S as Tt,i as vt,s as At,e as n,k as c,w as F,t as s,M as Et,c as r,d as t,m as h,a as p,x as P,h as i,b as u,N as _t,G as l,g as a,y as D,L as Ct,q as K,o as L,B as O,v as It}from"../../chunks/vendor-hf-doc-builder.js";import{I as kt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Je}from"../../chunks/CodeBlock-hf-doc-builder.js";function Wt(ot){let M,ee,w,j,H,J,ge,q,Te,te,U,ve,g,Ae,Ee,le,d,_e,x,Ce,Ie,Z,ke,We,X,Ge,Ze,T,Be,Se,oe,v,ae,f,Ye,z,$e,Qe,B,Re,Ne,se,A,ie,b,Ve,E,He,qe,ne,_,re,S,xe,pe,C,ue,Y,Xe,ce,m,at,he,$,ze,de,I,Fe,k,Pe,me,Q,De,fe,R,Ke,ye,W,Le,G,Oe,Me,N,et,we;return J=new kt({}),v=new Je({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzYW5jaGl0LWdhbmRoaSUyRndoaXNwZXItc21hbGwtZHYlMjIlMjAlMjAlMjMlMjB1cGRhdGUlMjB3aXRoJTIweW91ciUyMG1vZGVsJTIwaWQlMEFwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXV0b21hdGljLXNwZWVjaC1yZWNvZ25pdGlvbiUyMiUyQyUyMG1vZGVsJTNEbW9kZWxfaWQp",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"># update with your model id</span>
pipe = pipeline(<span class="hljs-string">&quot;automatic-speech-recognition&quot;</span>, model=model_id)`}}),A=new Je({props:{code:"ZGVmJTIwdHJhbnNjcmliZV9zcGVlY2goZmlsZXBhdGgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0JTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmaWxlcGF0aCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1heF9uZXdfdG9rZW5zJTNEMjU2JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ2VuZXJhdGVfa3dhcmdzJTNEJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIydGFzayUyMiUzQSUyMCUyMnRyYW5zY3JpYmUlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsYW5ndWFnZSUyMiUzQSUyMCUyMnNpbmhhbGVzZSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUyQyUyMCUyMCUyMyUyMHVwZGF0ZSUyMHdpdGglMjB0aGUlMjBsYW5ndWFnZSUyMHlvdSd2ZSUyMGZpbmUtdHVuZWQlMjBvbiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNodW5rX2xlbmd0aF9zJTNEMzAlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBvdXRwdXQlNUIlMjJ0ZXh0JTIyJTVE",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"># update with the language you&#x27;ve fine-tuned on</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>]`}}),_=new Je({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQWRlbW8lMjAlM0QlMjBnci5CbG9ja3MoKSUwQSUwQW1pY190cmFuc2NyaWJlJTIwJTNEJTIwZ3IuSW50ZXJmYWNlKCUwQSUyMCUyMCUyMCUyMGZuJTNEdHJhbnNjcmliZV9zcGVlY2glMkMlMEElMjAlMjAlMjAlMjBpbnB1dHMlM0Rnci5BdWRpbyhzb3VyY2UlM0QlMjJtaWNyb3Bob25lJTIyJTJDJTIwdHlwZSUzRCUyMmZpbGVwYXRoJTIyKSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dHMlM0Rnci5vdXRwdXRzLlRleHRib3goKSUyQyUwQSklMEElMEFmaWxlX3RyYW5zY3JpYmUlMjAlM0QlMjBnci5JbnRlcmZhY2UoJTBBJTIwJTIwJTIwJTIwZm4lM0R0cmFuc2NyaWJlX3NwZWVjaCUyQyUwQSUyMCUyMCUyMCUyMGlucHV0cyUzRGdyLkF1ZGlvKHNvdXJjZSUzRCUyMnVwbG9hZCUyMiUyQyUyMHR5cGUlM0QlMjJmaWxlcGF0aCUyMiklMkMlMEElMjAlMjAlMjAlMjBvdXRwdXRzJTNEZ3Iub3V0cHV0cy5UZXh0Ym94KCklMkMlMEEp",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(source=<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(source=<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(),
)`}}),C=new Je({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>)`}}),{c(){M=n("meta"),ee=c(),w=n("h1"),j=n("a"),H=n("span"),F(J.$$.fragment),ge=c(),q=n("span"),Te=s("Build a demo with Gradio"),te=c(),U=n("p"),ve=s("Now that we\u2019ve fine-tuned a Whisper model for Dhivehi speech recognition, let\u2019s go ahead and build a "),g=n("a"),Ae=s("Gradio"),Ee=s(`
demo to showcase it to the community!`),le=c(),d=n("p"),_e=s("The first thing to do is load up the fine-tuned checkpoint using the "),x=n("code"),Ce=s("pipeline()"),Ie=s(` class - this is very familiar now from
the section on `),Z=n("a"),ke=s("pre-trained models"),We=s(". You can change the "),X=n("code"),Ge=s("model_id"),Ze=s(` to the namespace of your fine-tuned
model on the Hugging Face Hub, or one of the pre-trained `),T=n("a"),Be=s("Whisper models"),Se=s(`
to perform zero-shot speech recognition:`),oe=c(),F(v.$$.fragment),ae=c(),f=n("p"),Ye=s(`Secondly, we\u2019ll define a function that takes the filepath for an audio input and passes it through the pipeline. Here,
the pipeline automatically takes care of loading the audio file, resampling it to the correct sampling rate, and running
inference with the model. We can then simply return the transcribed text as the output of the function. To ensure our
model can handle audio inputs of arbitrary length, we\u2019ll enable `),z=n("em"),$e=s("chunking"),Qe=s(` as described in the section
on `),B=n("a"),Re=s("pre-trained models"),Ne=s(":"),se=c(),F(A.$$.fragment),ie=c(),b=n("p"),Ve=s("We\u2019ll use the Gradio "),E=n("a"),He=s("blocks"),qe=s(` feature to launch two tabs on our demo: one for microphone
transcription, and the other for file upload.`),ne=c(),F(_.$$.fragment),re=c(),S=n("p"),xe=s("Finally, we launch the Gradio demo using the two blocks that we\u2019ve just defined:"),pe=c(),F(C.$$.fragment),ue=c(),Y=n("p"),Xe=s("This will launch a Gradio demo similar to the one running on the Hugging Face Space:"),ce=c(),m=n("iframe"),he=c(),$=n("p"),ze=s("Should you wish to host your demo on the Hugging Face Hub, you can use this Space as a template for your fine-tuned model."),de=c(),I=n("p"),Fe=s("Click the link to duplicate the template demo to your account: "),k=n("a"),Pe=s("https://huggingface.co/spaces/course-demos/whisper-small?duplicate=true"),me=c(),Q=n("p"),De=s("We recommend giving your space a similar name to your fine-tuned model (e.g. whisper-small-dv-demo) and setting the visibility to \u201CPublic\u201D."),fe=c(),R=n("p"),Ke=s(`Once you\u2019ve duplicated the Space to your account, click \u201CFiles and versions\u201D -> \u201Capp.py\u201D -> \u201Cedit\u201D. Then change the
model identifier to your fine-tuned model (line 6). Scroll to the bottom of the page and click \u201CCommit changes to main\u201D.
The demo will reboot, this time using your fine-tuned model. You can share this demo with your friends and family so that
they can use the model that you\u2019ve trained!`),ye=c(),W=n("p"),Le=s("Checkout our video tutorial to get a better understanding of how to duplicate the Space \u{1F449}\uFE0F "),G=n("a"),Oe=s("YouTube Video"),Me=c(),N=n("p"),et=s("We look forward to seeing your demos on the Hub!"),this.h()},l(e){const o=Et('[data-svelte="svelte-1phssyn"]',document.head);M=r(o,"META",{name:!0,content:!0}),o.forEach(t),ee=h(e),w=r(e,"H1",{class:!0});var je=p(w);j=r(je,"A",{id:!0,class:!0,href:!0});var st=p(j);H=r(st,"SPAN",{});var it=p(H);P(J.$$.fragment,it),it.forEach(t),st.forEach(t),ge=h(je),q=r(je,"SPAN",{});var nt=p(q);Te=i(nt,"Build a demo with Gradio"),nt.forEach(t),je.forEach(t),te=h(e),U=r(e,"P",{});var Ue=p(U);ve=i(Ue,"Now that we\u2019ve fine-tuned a Whisper model for Dhivehi speech recognition, let\u2019s go ahead and build a "),g=r(Ue,"A",{href:!0,rel:!0});var rt=p(g);Ae=i(rt,"Gradio"),rt.forEach(t),Ee=i(Ue,`
demo to showcase it to the community!`),Ue.forEach(t),le=h(e),d=r(e,"P",{});var y=p(d);_e=i(y,"The first thing to do is load up the fine-tuned checkpoint using the "),x=r(y,"CODE",{});var pt=p(x);Ce=i(pt,"pipeline()"),pt.forEach(t),Ie=i(y,` class - this is very familiar now from
the section on `),Z=r(y,"A",{href:!0});var ut=p(Z);ke=i(ut,"pre-trained models"),ut.forEach(t),We=i(y,". You can change the "),X=r(y,"CODE",{});var ct=p(X);Ge=i(ct,"model_id"),ct.forEach(t),Ze=i(y,` to the namespace of your fine-tuned
model on the Hugging Face Hub, or one of the pre-trained `),T=r(y,"A",{href:!0,rel:!0});var ht=p(T);Be=i(ht,"Whisper models"),ht.forEach(t),Se=i(y,`
to perform zero-shot speech recognition:`),y.forEach(t),oe=h(e),P(v.$$.fragment,e),ae=h(e),f=r(e,"P",{});var V=p(f);Ye=i(V,`Secondly, we\u2019ll define a function that takes the filepath for an audio input and passes it through the pipeline. Here,
the pipeline automatically takes care of loading the audio file, resampling it to the correct sampling rate, and running
inference with the model. We can then simply return the transcribed text as the output of the function. To ensure our
model can handle audio inputs of arbitrary length, we\u2019ll enable `),z=r(V,"EM",{});var dt=p(z);$e=i(dt,"chunking"),dt.forEach(t),Qe=i(V,` as described in the section
on `),B=r(V,"A",{href:!0});var mt=p(B);Re=i(mt,"pre-trained models"),mt.forEach(t),Ne=i(V,":"),V.forEach(t),se=h(e),P(A.$$.fragment,e),ie=h(e),b=r(e,"P",{});var be=p(b);Ve=i(be,"We\u2019ll use the Gradio "),E=r(be,"A",{href:!0,rel:!0});var ft=p(E);He=i(ft,"blocks"),ft.forEach(t),qe=i(be,` feature to launch two tabs on our demo: one for microphone
transcription, and the other for file upload.`),be.forEach(t),ne=h(e),P(_.$$.fragment,e),re=h(e),S=r(e,"P",{});var yt=p(S);xe=i(yt,"Finally, we launch the Gradio demo using the two blocks that we\u2019ve just defined:"),yt.forEach(t),pe=h(e),P(C.$$.fragment,e),ue=h(e),Y=r(e,"P",{});var Mt=p(Y);Xe=i(Mt,"This will launch a Gradio demo similar to the one running on the Hugging Face Space:"),Mt.forEach(t),ce=h(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),p(m).forEach(t),he=h(e),$=r(e,"P",{});var wt=p($);ze=i(wt,"Should you wish to host your demo on the Hugging Face Hub, you can use this Space as a template for your fine-tuned model."),wt.forEach(t),de=h(e),I=r(e,"P",{});var tt=p(I);Fe=i(tt,"Click the link to duplicate the template demo to your account: "),k=r(tt,"A",{href:!0,rel:!0});var jt=p(k);Pe=i(jt,"https://huggingface.co/spaces/course-demos/whisper-small?duplicate=true"),jt.forEach(t),tt.forEach(t),me=h(e),Q=r(e,"P",{});var Ut=p(Q);De=i(Ut,"We recommend giving your space a similar name to your fine-tuned model (e.g. whisper-small-dv-demo) and setting the visibility to \u201CPublic\u201D."),Ut.forEach(t),fe=h(e),R=r(e,"P",{});var bt=p(R);Ke=i(bt,`Once you\u2019ve duplicated the Space to your account, click \u201CFiles and versions\u201D -> \u201Capp.py\u201D -> \u201Cedit\u201D. Then change the
model identifier to your fine-tuned model (line 6). Scroll to the bottom of the page and click \u201CCommit changes to main\u201D.
The demo will reboot, this time using your fine-tuned model. You can share this demo with your friends and family so that
they can use the model that you\u2019ve trained!`),bt.forEach(t),ye=h(e),W=r(e,"P",{});var lt=p(W);Le=i(lt,"Checkout our video tutorial to get a better understanding of how to duplicate the Space \u{1F449}\uFE0F "),G=r(lt,"A",{href:!0,rel:!0});var Jt=p(G);Oe=i(Jt,"YouTube Video"),Jt.forEach(t),lt.forEach(t),Me=h(e),N=r(e,"P",{});var gt=p(N);et=i(gt,"We look forward to seeing your demos on the Hub!"),gt.forEach(t),this.h()},h(){u(M,"name","hf:doc:metadata"),u(M,"content",JSON.stringify(Gt)),u(j,"id","build-a-demo-with-gradio"),u(j,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(j,"href","#build-a-demo-with-gradio"),u(w,"class","relative group"),u(g,"href","https://gradio.app"),u(g,"rel","nofollow"),u(Z,"href","asr_models"),u(T,"href","https://huggingface.co/models?sort=downloads&search=openai%2Fwhisper-"),u(T,"rel","nofollow"),u(B,"href","asr_models"),u(E,"href","https://gradio.app/docs/#blocks"),u(E,"rel","nofollow"),_t(m.src,at="https://course-demos-whisper-small.hf.space")||u(m,"src",at),u(m,"frameborder","0"),u(m,"height","450"),u(m,"title","Gradio app"),u(m,"class","container p-0 flex-grow space-iframe"),u(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"),u(m,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),u(k,"href","https://huggingface.co/spaces/course-demos/whisper-small?duplicate=true"),u(k,"rel","nofollow"),u(G,"href","https://www.youtube.com/watch?v=VQYuvl6-9VE"),u(G,"rel","nofollow")},m(e,o){l(document.head,M),a(e,ee,o),a(e,w,o),l(w,j),l(j,H),D(J,H,null),l(w,ge),l(w,q),l(q,Te),a(e,te,o),a(e,U,o),l(U,ve),l(U,g),l(g,Ae),l(U,Ee),a(e,le,o),a(e,d,o),l(d,_e),l(d,x),l(x,Ce),l(d,Ie),l(d,Z),l(Z,ke),l(d,We),l(d,X),l(X,Ge),l(d,Ze),l(d,T),l(T,Be),l(d,Se),a(e,oe,o),D(v,e,o),a(e,ae,o),a(e,f,o),l(f,Ye),l(f,z),l(z,$e),l(f,Qe),l(f,B),l(B,Re),l(f,Ne),a(e,se,o),D(A,e,o),a(e,ie,o),a(e,b,o),l(b,Ve),l(b,E),l(E,He),l(b,qe),a(e,ne,o),D(_,e,o),a(e,re,o),a(e,S,o),l(S,xe),a(e,pe,o),D(C,e,o),a(e,ue,o),a(e,Y,o),l(Y,Xe),a(e,ce,o),a(e,m,o),a(e,he,o),a(e,$,o),l($,ze),a(e,de,o),a(e,I,o),l(I,Fe),l(I,k),l(k,Pe),a(e,me,o),a(e,Q,o),l(Q,De),a(e,fe,o),a(e,R,o),l(R,Ke),a(e,ye,o),a(e,W,o),l(W,Le),l(W,G),l(G,Oe),a(e,Me,o),a(e,N,o),l(N,et),we=!0},p:Ct,i(e){we||(K(J.$$.fragment,e),K(v.$$.fragment,e),K(A.$$.fragment,e),K(_.$$.fragment,e),K(C.$$.fragment,e),we=!0)},o(e){L(J.$$.fragment,e),L(v.$$.fragment,e),L(A.$$.fragment,e),L(_.$$.fragment,e),L(C.$$.fragment,e),we=!1},d(e){t(M),e&&t(ee),e&&t(w),O(J),e&&t(te),e&&t(U),e&&t(le),e&&t(d),e&&t(oe),O(v,e),e&&t(ae),e&&t(f),e&&t(se),O(A,e),e&&t(ie),e&&t(b),e&&t(ne),O(_,e),e&&t(re),e&&t(S),e&&t(pe),O(C,e),e&&t(ue),e&&t(Y),e&&t(ce),e&&t(m),e&&t(he),e&&t($),e&&t(de),e&&t(I),e&&t(me),e&&t(Q),e&&t(fe),e&&t(R),e&&t(ye),e&&t(W),e&&t(Me),e&&t(N)}}}const Gt={local:"build-a-demo-with-gradio",title:"Build a demo with Gradio"};function Zt(ot){return It(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class $t extends Tt{constructor(M){super();vt(this,M,Zt,Wt,At,{})}}export{$t as default,Gt as metadata};
