Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Building Your First AI App with Inference Providers","local":"building-your-first-ai-app-with-inference-providers","sections":[{"title":"Project Overview","local":"project-overview","sections":[],"depth":2},{"title":"Step 1: Set Up Authentication","local":"step-1-set-up-authentication","sections":[],"depth":2},{"title":"Step 2: Build the User Interface","local":"step-2-build-the-user-interface","sections":[],"depth":2},{"title":"Step 3: Add Speech Transcription","local":"step-3-add-speech-transcription","sections":[],"depth":2},{"title":"Step 4: Add AI Summarization","local":"step-4-add-ai-summarization","sections":[],"depth":2},{"title":"Step 5: Deploy on Hugging Face Spaces","local":"step-5-deploy-on-hugging-face-spaces","sections":[],"depth":2},{"title":"Next Steps","local":"next-steps","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/101-course/pr_4/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/entry/start.b6742992.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/scheduler.1d51f4c0.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/singletons.023d1c68.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/index.fa8592cf.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/paths.daa2f795.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/entry/app.8b986792.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/index.fda43871.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/nodes/0.b5fb3b56.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/nodes/12.19ee8d7f.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/Tip.e808fe4c.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/CodeBlock.16130beb.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/getInferenceSnippets.58a43ad0.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/HfOption.42596235.js"> | |
| <link rel="modulepreload" href="/docs/101-course/pr_4/en/_app/immutable/chunks/stores.dae1239c.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Building Your First AI App with Inference Providers","local":"building-your-first-ai-app-with-inference-providers","sections":[{"title":"Project Overview","local":"project-overview","sections":[],"depth":2},{"title":"Step 1: Set Up Authentication","local":"step-1-set-up-authentication","sections":[],"depth":2},{"title":"Step 2: Build the User Interface","local":"step-2-build-the-user-interface","sections":[],"depth":2},{"title":"Step 3: Add Speech Transcription","local":"step-3-add-speech-transcription","sections":[],"depth":2},{"title":"Step 4: Add AI Summarization","local":"step-4-add-ai-summarization","sections":[],"depth":2},{"title":"Step 5: Deploy on Hugging Face Spaces","local":"step-5-deploy-on-hugging-face-spaces","sections":[],"depth":2},{"title":"Next Steps","local":"next-steps","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="building-your-first-ai-app-with-inference-providers" 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" href="#building-your-first-ai-app-with-inference-providers"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Building Your First AI App with Inference Providers</span></h1> <p data-svelte-h="svelte-1xvjfqn">You’ve learned the basics and understand the provider ecosystem. Now let’s build something practical: an <strong>AI Meeting Notes</strong> app that transcribes audio files and generates summaries with action items.</p> <p data-svelte-h="svelte-gz55cx">This project demonstrates real-world AI orchestration using multiple specialized providers within a single application.</p> <h2 class="relative group"><a id="project-overview" 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" href="#project-overview"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Project Overview</span></h2> <p data-svelte-h="svelte-5khb3j">Our app will:</p> <ol data-svelte-h="svelte-8ofcwq"><li><strong>Accept audio</strong> as a microphone input through a web interface</li> <li><strong>Transcribe speech</strong> using a fast speech-to-text model</li> <li><strong>Generate summaries</strong> using a powerful language model</li> <li><strong>Deploy to the web</strong> for easy sharing</li></ol> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-6re1qd"><strong>Tech Stack</strong>: Gradio (for the UI) + Inference Providers (for the AI)</p> </div> <h2 class="relative group"><a id="step-1-set-up-authentication" 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" href="#step-1-set-up-authentication"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 1: Set Up Authentication</span></h2> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-1frpmc9">Before we start coding, authenticate with Hugging Face using the CLI:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->pip install huggingface_hub | |
| hf auth login<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-7amyfj">When prompted, paste your Hugging Face token. This handles authentication automatically for all your inference calls. You can generate one from <a href="https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained" rel="nofollow">your settings page</a>.</p> </div> <h2 class="relative group"><a id="step-2-build-the-user-interface" 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" href="#step-2-build-the-user-interface"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 2: Build the User Interface</span></h2> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-agnmrx">Now let’s create a simple web interface using Gradio:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr | |
| <span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">process_meeting_audio</span>(<span class="hljs-params">audio_file</span>): | |
| <span class="hljs-string">"""Process uploaded audio file and return transcript + summary"""</span> | |
| <span class="hljs-keyword">if</span> audio_file <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>: | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">"Please upload an audio file."</span>, <span class="hljs-string">""</span> | |
| <span class="hljs-comment"># We'll implement the AI logic next</span> | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">"Transcript will appear here..."</span>, <span class="hljs-string">"Summary will appear here..."</span> | |
| <span class="hljs-comment"># Create the Gradio interface</span> | |
| app = gr.Interface( | |
| fn=process_meeting_audio, | |
| inputs=gr.Audio(label=<span class="hljs-string">"Upload Meeting Audio"</span>, <span class="hljs-built_in">type</span>=<span class="hljs-string">"filepath"</span>), | |
| outputs=[ | |
| gr.Textbox(label=<span class="hljs-string">"Transcript"</span>, lines=<span class="hljs-number">10</span>), | |
| gr.Textbox(label=<span class="hljs-string">"Summary & Action Items"</span>, lines=<span class="hljs-number">8</span>) | |
| ], | |
| title=<span class="hljs-string">"🎤 AI Meeting Notes"</span>, | |
| description=<span class="hljs-string">"Upload an audio file to get an instant transcript and summary with action items."</span> | |
| ) | |
| <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>: | |
| app.launch()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-mdm151">Here we’re using Gradio’s <code>gr.Audio</code> component to either upload an audio file or use the microphone input. We’re keeping things simple with two outputs: a transcript and a summary with action items.</p> </div> <h2 class="relative group"><a id="step-3-add-speech-transcription" 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" href="#step-3-add-speech-transcription"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 3: Add Speech Transcription</span></h2> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-yyu0ez">Now let’s implement the transcription using OpenAI’s <code>whisper-large-v3</code> model for fast, reliable speech processing.</p> <div class="course-tip bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400"><p data-svelte-h="svelte-na730p">We’ll use the <code>auto</code> provider to automatically select the first available provider for the model. You can define your own priority list of providers in the <a href="https://huggingface.co/settings/inference-providers" rel="nofollow">Inference Providers</a> page.</p></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">def</span> <span class="hljs-title function_">transcribe_audio</span>(<span class="hljs-params">audio_file_path</span>): | |
| <span class="hljs-string">"""Transcribe audio using fal.ai for speed"""</span> | |
| client = InferenceClient(provider=<span class="hljs-string">"auto"</span>) | |
| <span class="hljs-comment"># Pass the file path directly - the client handles file reading</span> | |
| transcript = client.automatic_speech_recognition( | |
| audio=audio_file_path, | |
| model=<span class="hljs-string">"openai/whisper-large-v3"</span> | |
| ) | |
| <span class="hljs-keyword">return</span> transcript.text<!-- HTML_TAG_END --></pre></div> </div> <h2 class="relative group"><a id="step-4-add-ai-summarization" 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" href="#step-4-add-ai-summarization"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 4: Add AI Summarization</span></h2> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-1hw4xen">Next, we’ll use a powerful language model like <code>deepseek-ai/DeepSeek-R1-0528</code> from DeepSeek via an Inference Provider, and just like in the previous step, we’ll use the <code>auto</code> provider to automatically select the first available provider for the model. | |
| We will define a custom prompt to ensure the output is formatted as a summary with action items and decisions made:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_summary</span>(<span class="hljs-params">transcript</span>): | |
| <span class="hljs-string">"""Generate summary using an Inference Provider"""</span> | |
| client = InferenceClient(provider=<span class="hljs-string">"auto"</span>) | |
| prompt = <span class="hljs-string">f""" | |
| Analyze this meeting transcript and provide: | |
| 1. A concise summary of key points | |
| 2. Action items with responsible parties | |
| 3. Important decisions made | |
| Transcript: <span class="hljs-subst">{transcript}</span> | |
| Format with clear sections: | |
| ## Summary | |
| ## Action Items | |
| ## Decisions Made | |
| """</span> | |
| response = client.chat.completions.create( | |
| model=<span class="hljs-string">"deepseek-ai/DeepSeek-R1-0528"</span>, | |
| messages=[{<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt}], | |
| max_tokens=<span class="hljs-number">1000</span> | |
| ) | |
| <span class="hljs-keyword">return</span> response.choices[<span class="hljs-number">0</span>].message.content<!-- HTML_TAG_END --></pre></div> </div> <h2 class="relative group"><a id="step-5-deploy-on-hugging-face-spaces" 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" href="#step-5-deploy-on-hugging-face-spaces"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Step 5: Deploy on Hugging Face Spaces</span></h2> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">python </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">javascript </div></div> <div class="language-select"><p data-svelte-h="svelte-falld9">To deploy, we’ll need to create an <code>app.py</code> file and upload it to Hugging Face Spaces.</p> <details><summary data-svelte-h="svelte-18nprsf"><strong>📋 Click to view the complete app.py file</strong></summary> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr | |
| <span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> InferenceClient | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">transcribe_audio</span>(<span class="hljs-params">audio_file_path</span>): | |
| <span class="hljs-string">"""Transcribe audio using an Inference Provider"""</span> | |
| client = InferenceClient(provider=<span class="hljs-string">"auto"</span>) | |
| <span class="hljs-comment"># Pass the file path directly - the client handles file reading</span> | |
| transcript = client.automatic_speech_recognition( | |
| audio=audio_file_path, model=<span class="hljs-string">"openai/whisper-large-v3"</span> | |
| ) | |
| <span class="hljs-keyword">return</span> transcript.text | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_summary</span>(<span class="hljs-params">transcript</span>): | |
| <span class="hljs-string">"""Generate summary using an Inference Provider"""</span> | |
| client = InferenceClient(provider=<span class="hljs-string">"auto"</span>) | |
| prompt = <span class="hljs-string">f""" | |
| Analyze this meeting transcript and provide: | |
| 1. A concise summary of key points | |
| 2. Action items with responsible parties | |
| 3. Important decisions made | |
| Transcript: <span class="hljs-subst">{transcript}</span> | |
| Format with clear sections: | |
| ## Summary | |
| ## Action Items | |
| ## Decisions Made | |
| """</span> | |
| response = client.chat.completions.create( | |
| model=<span class="hljs-string">"deepseek-ai/DeepSeek-R1-0528"</span>, | |
| messages=[{<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt}], | |
| max_tokens=<span class="hljs-number">1000</span>, | |
| ) | |
| <span class="hljs-keyword">return</span> response.choices[<span class="hljs-number">0</span>].message.content | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">process_meeting_audio</span>(<span class="hljs-params">audio_file</span>): | |
| <span class="hljs-string">"""Main processing function"""</span> | |
| <span class="hljs-keyword">if</span> audio_file <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>: | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">"Please upload an audio file."</span>, <span class="hljs-string">""</span> | |
| <span class="hljs-keyword">try</span>: | |
| <span class="hljs-comment"># Step 1: Transcribe</span> | |
| transcript = transcribe_audio(audio_file) | |
| <span class="hljs-comment"># Step 2: Summarize</span> | |
| summary = generate_summary(transcript) | |
| <span class="hljs-keyword">return</span> transcript, summary | |
| <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e: | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">f"Error processing audio: <span class="hljs-subst">{<span class="hljs-built_in">str</span>(e)}</span>"</span>, <span class="hljs-string">""</span> | |
| <span class="hljs-comment"># Create Gradio interface</span> | |
| app = gr.Interface( | |
| fn=process_meeting_audio, | |
| inputs=gr.Audio(label=<span class="hljs-string">"Upload Meeting Audio"</span>, <span class="hljs-built_in">type</span>=<span class="hljs-string">"filepath"</span>), | |
| outputs=[ | |
| gr.Textbox(label=<span class="hljs-string">"Transcript"</span>, lines=<span class="hljs-number">10</span>), | |
| gr.Textbox(label=<span class="hljs-string">"Summary & Action Items"</span>, lines=<span class="hljs-number">8</span>), | |
| ], | |
| title=<span class="hljs-string">"🎤 AI Meeting Notes"</span>, | |
| description=<span class="hljs-string">"Upload audio to get instant transcripts and summaries."</span>, | |
| ) | |
| <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>: | |
| app.launch()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1n5m4re">Our app will run on port 7860 and look like this:</p> <p data-svelte-h="svelte-ibsop9"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/inference-providers-guides/gradio-app.png" alt="Gradio app"></p></details> <p data-svelte-h="svelte-13uvzr6">To deploy, we’ll need to create a new Space and upload our files.</p> <ol data-svelte-h="svelte-1yvydwn"><li><strong>Create a new Space</strong>: Go to <a href="https://huggingface.co/new-space" rel="nofollow">huggingface.co/new-space</a></li> <li><strong>Choose Gradio SDK</strong> and make it public</li> <li><strong>Upload your files</strong>: Upload <code>app.py</code></li> <li><strong>Add your token</strong>: In Space settings, add <code>HF_TOKEN</code> as a secret (get it from <a href="https://huggingface.co/settings/tokens" rel="nofollow">your settings</a>)</li> <li><strong>Launch</strong>: Your app will be live at <code>https://huggingface.co/spaces/your-username/your-space-name</code></li></ol> <blockquote data-svelte-h="svelte-1gqrdse"><p><strong>Note</strong>: While we used CLI authentication locally, Spaces requires the token as a secret for the deployment environment.</p></blockquote> </div> <h2 class="relative group"><a id="next-steps" 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" href="#next-steps"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Next Steps</span></h2> <p data-svelte-h="svelte-cyuk9m">Congratulations! You’ve created a production-ready AI application that: handles real-world tasks, provides a professional interface, scales automatically, and costs efficiently. If you want to explore more providers, you can check out the <a href="https://huggingface.co/inference-providers" rel="nofollow">Inference Providers</a> page. Or here are some ideas for next steps:</p> <ul data-svelte-h="svelte-i47df0"><li><strong>Improve your prompt</strong>: Try different prompts to improve the quality for your use case</li> <li><strong>Try different models</strong>: Experiment with various speech and text models</li> <li><strong>Compare performance</strong>: Benchmark speed vs. accuracy across providers</li></ul> <p data-svelte-h="svelte-2ddwnb">Up next: learn how to deploy a dedicated Inference Endpoint and call it from your apps.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/101-course/blob/main/chapters/en/chapter2/3.mdx" target="_blank"><span data-svelte-h="svelte-1kd6by1"><</span> <span data-svelte-h="svelte-x0xyl0">></span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_kib1ob = { | |
| assets: "/docs/101-course/pr_4/en", | |
| base: "/docs/101-course/pr_4/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/101-course/pr_4/en/_app/immutable/entry/start.b6742992.js"), | |
| import("/docs/101-course/pr_4/en/_app/immutable/entry/app.8b986792.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 12], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 36.9 kB
- Xet hash:
- a4cbfba647aa02aa792624879d1fb9c1b4d67c0b047a1005c38fe454004cab90
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.