import{S as Ke,i as Oe,s as el,e as o,k as f,w as O,t as s,M as ll,c as r,d as a,m as h,a as c,x as ee,h as t,b as p,N as al,G as l,g as d,y as le,L as sl,q as ae,o as se,B as te,v as tl}from"../../chunks/vendor-hf-doc-builder.js";import{I as nl}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Ie}from"../../chunks/CodeBlock-hf-doc-builder.js";function ol(Ce){let M,x,w,y,k,_,ne,T,oe,Q,n,re,b,q,ie,ce,g,ue,pe,B,de,me,I,fe,he,C,Me,we,G,ye,ve,R,je,_e,Z,be,ge,A,Ee,Je,V,E,S,v,Ue,W,Ge,$e,H,J,z,$,ke,X,U,Y,j,Te,N,qe,Be,P,m,Re,D;return _=new nl({}),E=new Ie({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJzYW5jaGl0LWdhbmRoaSUyRmRpc3RpbGh1YmVydC1maW5ldHVuZWQtZ3R6YW4lMjIlMEFwaXBlJTIwJTNEJTIwcGlwZWxpbmUoJTIyYXVkaW8tY2xhc3NpZmljYXRpb24lMjIlMkMlMjBtb2RlbCUzRG1vZGVsX2lkKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

model_id = <span class="hljs-string">&quot;sanchit-gandhi/distilhubert-finetuned-gtzan&quot;</span>
pipe = pipeline(<span class="hljs-string">&quot;audio-classification&quot;</span>, model=model_id)`}}),J=new Ie({props:{code:"ZGVmJTIwY2xhc3NpZnlfYXVkaW8oZmlsZXBhdGgpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZHMlMjAlM0QlMjBwaXBlKGZpbGVwYXRoKSUwQSUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjAlN0IlN0QlMEElMjAlMjAlMjAlMjBmb3IlMjBwJTIwaW4lMjBwcmVkcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlNUJwJTVCJTIybGFiZWwlMjIlNUQlNUQlMjAlM0QlMjBwJTVCJTIyc2NvcmUlMjIlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBvdXRwdXRz",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">classify_audio</span>(<span class="hljs-params">filepath</span>):
    preds = pipe(filepath)
    outputs = {}
    <span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> preds:
        outputs[p[<span class="hljs-string">&quot;label&quot;</span>]] = p[<span class="hljs-string">&quot;score&quot;</span>]
    <span class="hljs-keyword">return</span> outputs`}}),U=new Ie({props:{code:"aW1wb3J0JTIwZ3JhZGlvJTIwYXMlMjBnciUwQSUwQWRlbW8lMjAlM0QlMjBnci5JbnRlcmZhY2UoJTBBJTIwJTIwJTIwJTIwZm4lM0RjbGFzc2lmeV9hdWRpbyUyQyUyMGlucHV0cyUzRGdyLkF1ZGlvKHR5cGUlM0QlMjJmaWxlcGF0aCUyMiklMkMlMjBvdXRwdXRzJTNEZ3Iub3V0cHV0cy5MYWJlbCgpJTBBKSUwQWRlbW8ubGF1bmNoKGRlYnVnJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr

demo = gr.Interface(
    fn=classify_audio, inputs=gr.Audio(<span class="hljs-built_in">type</span>=<span class="hljs-string">&quot;filepath&quot;</span>), outputs=gr.outputs.Label()
)
demo.launch(debug=<span class="hljs-literal">True</span>)`}}),{c(){M=o("meta"),x=f(),w=o("h1"),y=o("a"),k=o("span"),O(_.$$.fragment),ne=f(),T=o("span"),oe=s("Construire une d\xE9mo avec Gradio"),Q=f(),n=o("p"),re=s("Dans cette derni\xE8re section sur la classification audio, nous allons construire une d\xE9mo avec "),b=o("a"),q=o("em"),ie=s("Gradio"),ce=s(" pour pr\xE9senter le mod\xE8le de classification musicale que nous venons d\u2019entra\xEEner sur le jeu de donn\xE9es "),g=o("a"),ue=s("GTZAN"),pe=s(`.
La premi\xE8re chose \xE0 faire est de charger le `),B=o("em"),de=s("checkpoint"),me=f(),I=o("em"),fe=s("finetun\xE9"),he=s(" en utilisant la classe "),C=o("code"),Me=s("pipeline()"),we=s(" que vous connaissez gr\xE2ce \xE0 la section sur les "),G=o("a"),ye=s("mod\xE8les pr\xE9-entra\xEEn\xE9s"),ve=s(". Vous pouvez changer le "),R=o("code"),je=s("model_id"),_e=s(" avec le nom de votre mod\xE8le "),Z=o("em"),be=s("finetun\xE9"),ge=s(" et pr\xE9sent sur "),A=o("em"),Ee=s("Hub"),Je=s(" :"),V=f(),O(E.$$.fragment),S=f(),v=o("p"),Ue=s(`Deuxi\xE8mement, nous allons d\xE9finir une fonction qui prend le chemin du fichier d\u2019une entr\xE9e audio et le passe \xE0 travers le pipeline.
Ici, le pipeline s\u2019occupe automatiquement de charger le fichier audio, de le r\xE9-\xE9chantillonner \xE0 la bonne fr\xE9quence d\u2019\xE9chantillonnage, et de lancer l\u2019inf\xE9rence avec le mod\xE8le.
Nous prenons les pr\xE9dictions de `),W=o("code"),Ge=s("preds"),$e=s(" du mod\xE8le et les formatons en tant qu\u2019objet dictionnaire \xE0 afficher sur la sortie :"),H=f(),O(J.$$.fragment),z=f(),$=o("p"),ke=s("Enfin, nous lan\xE7ons la d\xE9mo Gradio en utilisant la fonction que nous venons de d\xE9finir :"),X=f(),O(U.$$.fragment),Y=f(),j=o("p"),Te=s("Ceci lancera une d\xE9mo similaire \xE0 celle qui tourne sur le "),N=o("em"),qe=s("Space"),Be=s(" :"),P=f(),m=o("iframe"),this.h()},l(e){const i=ll('[data-svelte="svelte-1phssyn"]',document.head);M=r(i,"META",{name:!0,content:!0}),i.forEach(a),x=h(e),w=r(e,"H1",{class:!0});var L=c(w);y=r(L,"A",{id:!0,class:!0,href:!0});var Ze=c(y);k=r(Ze,"SPAN",{});var Ae=c(k);ee(_.$$.fragment,Ae),Ae.forEach(a),Ze.forEach(a),ne=h(L),T=r(L,"SPAN",{});var We=c(T);oe=t(We,"Construire une d\xE9mo avec Gradio"),We.forEach(a),L.forEach(a),Q=h(e),n=r(e,"P",{});var u=c(n);re=t(u,"Dans cette derni\xE8re section sur la classification audio, nous allons construire une d\xE9mo avec "),b=r(u,"A",{href:!0,rel:!0});var Ne=c(b);q=r(Ne,"EM",{});var xe=c(q);ie=t(xe,"Gradio"),xe.forEach(a),Ne.forEach(a),ce=t(u," pour pr\xE9senter le mod\xE8le de classification musicale que nous venons d\u2019entra\xEEner sur le jeu de donn\xE9es "),g=r(u,"A",{href:!0,rel:!0});var Qe=c(g);ue=t(Qe,"GTZAN"),Qe.forEach(a),pe=t(u,`.
La premi\xE8re chose \xE0 faire est de charger le `),B=r(u,"EM",{});var Ve=c(B);de=t(Ve,"checkpoint"),Ve.forEach(a),me=h(u),I=r(u,"EM",{});var Se=c(I);fe=t(Se,"finetun\xE9"),Se.forEach(a),he=t(u," en utilisant la classe "),C=r(u,"CODE",{});var He=c(C);Me=t(He,"pipeline()"),He.forEach(a),we=t(u," que vous connaissez gr\xE2ce \xE0 la section sur les "),G=r(u,"A",{href:!0});var ze=c(G);ye=t(ze,"mod\xE8les pr\xE9-entra\xEEn\xE9s"),ze.forEach(a),ve=t(u,". Vous pouvez changer le "),R=r(u,"CODE",{});var Xe=c(R);je=t(Xe,"model_id"),Xe.forEach(a),_e=t(u," avec le nom de votre mod\xE8le "),Z=r(u,"EM",{});var Ye=c(Z);be=t(Ye,"finetun\xE9"),Ye.forEach(a),ge=t(u," et pr\xE9sent sur "),A=r(u,"EM",{});var Pe=c(A);Ee=t(Pe,"Hub"),Pe.forEach(a),Je=t(u," :"),u.forEach(a),V=h(e),ee(E.$$.fragment,e),S=h(e),v=r(e,"P",{});var F=c(v);Ue=t(F,`Deuxi\xE8mement, nous allons d\xE9finir une fonction qui prend le chemin du fichier d\u2019une entr\xE9e audio et le passe \xE0 travers le pipeline.
Ici, le pipeline s\u2019occupe automatiquement de charger le fichier audio, de le r\xE9-\xE9chantillonner \xE0 la bonne fr\xE9quence d\u2019\xE9chantillonnage, et de lancer l\u2019inf\xE9rence avec le mod\xE8le.
Nous prenons les pr\xE9dictions de `),W=r(F,"CODE",{});var De=c(W);Ge=t(De,"preds"),De.forEach(a),$e=t(F," du mod\xE8le et les formatons en tant qu\u2019objet dictionnaire \xE0 afficher sur la sortie :"),F.forEach(a),H=h(e),ee(J.$$.fragment,e),z=h(e),$=r(e,"P",{});var Le=c($);ke=t(Le,"Enfin, nous lan\xE7ons la d\xE9mo Gradio en utilisant la fonction que nous venons de d\xE9finir :"),Le.forEach(a),X=h(e),ee(U.$$.fragment,e),Y=h(e),j=r(e,"P",{});var K=c(j);Te=t(K,"Ceci lancera une d\xE9mo similaire \xE0 celle qui tourne sur le "),N=r(K,"EM",{});var Fe=c(N);qe=t(Fe,"Space"),Fe.forEach(a),Be=t(K," :"),K.forEach(a),P=h(e),m=r(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),c(m).forEach(a),this.h()},h(){p(M,"name","hf:doc:metadata"),p(M,"content",JSON.stringify(rl)),p(y,"id","construire-une-dmo-avec-gradio"),p(y,"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"),p(y,"href","#construire-une-dmo-avec-gradio"),p(w,"class","relative group"),p(b,"href","https://gradio.app"),p(b,"rel","nofollow"),p(g,"href","https://huggingface.co/datasets/marsyas/gtzan"),p(g,"rel","nofollow"),p(G,"href","classification_models"),al(m.src,Re="https://course-demos-song-classifier.hf.space")||p(m,"src",Re),p(m,"frameborder","0"),p(m,"height","450"),p(m,"title","Gradio app"),p(m,"class","container p-0 flex-grow space-iframe"),p(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"),p(m,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads")},m(e,i){l(document.head,M),d(e,x,i),d(e,w,i),l(w,y),l(y,k),le(_,k,null),l(w,ne),l(w,T),l(T,oe),d(e,Q,i),d(e,n,i),l(n,re),l(n,b),l(b,q),l(q,ie),l(n,ce),l(n,g),l(g,ue),l(n,pe),l(n,B),l(B,de),l(n,me),l(n,I),l(I,fe),l(n,he),l(n,C),l(C,Me),l(n,we),l(n,G),l(G,ye),l(n,ve),l(n,R),l(R,je),l(n,_e),l(n,Z),l(Z,be),l(n,ge),l(n,A),l(A,Ee),l(n,Je),d(e,V,i),le(E,e,i),d(e,S,i),d(e,v,i),l(v,Ue),l(v,W),l(W,Ge),l(v,$e),d(e,H,i),le(J,e,i),d(e,z,i),d(e,$,i),l($,ke),d(e,X,i),le(U,e,i),d(e,Y,i),d(e,j,i),l(j,Te),l(j,N),l(N,qe),l(j,Be),d(e,P,i),d(e,m,i),D=!0},p:sl,i(e){D||(ae(_.$$.fragment,e),ae(E.$$.fragment,e),ae(J.$$.fragment,e),ae(U.$$.fragment,e),D=!0)},o(e){se(_.$$.fragment,e),se(E.$$.fragment,e),se(J.$$.fragment,e),se(U.$$.fragment,e),D=!1},d(e){a(M),e&&a(x),e&&a(w),te(_),e&&a(Q),e&&a(n),e&&a(V),te(E,e),e&&a(S),e&&a(v),e&&a(H),te(J,e),e&&a(z),e&&a($),e&&a(X),te(U,e),e&&a(Y),e&&a(j),e&&a(P),e&&a(m)}}}const rl={local:"construire-une-dmo-avec-gradio",title:"Construire une d\xE9mo avec Gradio"};function il(Ce){return tl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dl extends Ke{constructor(M){super();Oe(this,M,il,ol,el,{})}}export{dl as default,rl as metadata};
