Buckets:

hf-doc-build/doc-dev / hub /pr_2521 /en /spaces-overview.html
HuggingFaceDocBuilder's picture
download
raw
39.7 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Spaces Overview&quot;,&quot;local&quot;:&quot;spaces-overview&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Creating a new Space&quot;,&quot;local&quot;:&quot;creating-a-new-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Space visibility&quot;,&quot;local&quot;:&quot;space-visibility&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Hardware resources&quot;,&quot;local&quot;:&quot;hardware-resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Managing secrets and environment variables&quot;,&quot;local&quot;:&quot;managing-secrets&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Duplicating a Space&quot;,&quot;local&quot;:&quot;duplicating-a-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Networking&quot;,&quot;local&quot;:&quot;networking&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Lifecycle management&quot;,&quot;local&quot;:&quot;lifecycle-management&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Built-in environment variables&quot;,&quot;local&quot;:&quot;built-in-environment-variables&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Clone the Repository&quot;,&quot;local&quot;:&quot;clone-the-repository&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Linking Models and Datasets on the Hub&quot;,&quot;local&quot;:&quot;linking-models-and-datasets-on-the-hub&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/hub/pr_2521/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/entry/start.d19e5ca7.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/scheduler.409792a1.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/singletons.1ece723a.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/index.0f0d9f26.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/paths.a67d9216.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/entry/app.98ab229a.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/preload-helper.78e52d9f.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/index.92d389ff.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/nodes/0.7799902b.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/nodes/209.7772a816.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/CopyLLMTxtMenu.dcf7fb47.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.0c189c7e.js">
<link rel="modulepreload" href="/docs/hub/pr_2521/en/_app/immutable/chunks/CodeBlock.5ed269c1.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Spaces Overview&quot;,&quot;local&quot;:&quot;spaces-overview&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Creating a new Space&quot;,&quot;local&quot;:&quot;creating-a-new-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Space visibility&quot;,&quot;local&quot;:&quot;space-visibility&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Hardware resources&quot;,&quot;local&quot;:&quot;hardware-resources&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Managing secrets and environment variables&quot;,&quot;local&quot;:&quot;managing-secrets&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Duplicating a Space&quot;,&quot;local&quot;:&quot;duplicating-a-space&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Networking&quot;,&quot;local&quot;:&quot;networking&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Lifecycle management&quot;,&quot;local&quot;:&quot;lifecycle-management&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Built-in environment variables&quot;,&quot;local&quot;:&quot;built-in-environment-variables&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Clone the Repository&quot;,&quot;local&quot;:&quot;clone-the-repository&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Linking Models and Datasets on the Hub&quot;,&quot;local&quot;:&quot;linking-models-and-datasets-on-the-hub&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" 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></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="spaces-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="#spaces-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>Spaces Overview</span></h1> <p data-svelte-h="svelte-1byh6no">Hugging Face Spaces make it easy for you to create and deploy ML-powered demos in minutes. Watch the following video for a quick introduction to Spaces:</p> <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/3bSVKNKb_PY" title="Spaces intro" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe> <p data-svelte-h="svelte-4yxmow">In the following sections, you’ll learn the basics of creating a Space, configuring it, and deploying your code to it.</p> <h2 class="relative group"><a id="creating-a-new-space" 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="#creating-a-new-space"><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>Creating a new Space</span></h2> <p data-svelte-h="svelte-1kuusn2"><strong>To make a new Space</strong>, visit the <a href="https://huggingface.co/spaces" rel="nofollow">Spaces main page</a> and click on <strong>Create new Space</strong>. Along with choosing a name for your Space, selecting an optional license, and setting your Space’s <a href="#space-visibility">visibility</a> (public, protected, or private), you’ll be prompted to choose the <strong>SDK</strong> for your Space. The Hub offers three SDK options: Gradio, Docker and static HTML. If you select “Gradio” as your SDK, you’ll be navigated to a new repo showing the following page:</p> <div class="flex justify-center" data-svelte-h="svelte-kp77b"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/spaces-blank-space.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/spaces-blank-space-dark.png"></div> <p data-svelte-h="svelte-sra6d6">Under the hood, Spaces stores your code inside a git repository, just like the model and dataset repositories. Thanks to this, the same tools we use for all the <a href="./repositories">other repositories on the Hub</a> (<code>git</code> and <code>git-xet</code>) also work for Spaces. Follow the same flow as in <a href="./repositories-getting-started">Getting Started with Repositories</a> to add files to your Space. Each time a new commit is pushed, the Space will automatically rebuild and restart.</p> <p data-svelte-h="svelte-175nn98">For step-by-step tutorials to creating your first Space, see the guides below:</p> <ul data-svelte-h="svelte-uh8u7l"><li><a href="./spaces-sdks-gradio">Creating a Gradio Space</a></li> <li><a href="./spaces-sdks-docker-first-demo">Creating a Docker Space</a></li></ul> <h2 class="relative group"><a id="space-visibility" 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="#space-visibility"><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>Space visibility</span></h2> <p data-svelte-h="svelte-2gsyhj">You can set a Space’s visibility from the <strong>Settings</strong> tab using the visibility dropdown. Spaces support three visibility levels: <strong>public</strong>, <strong>protected</strong>, and <strong>private</strong>.</p> <blockquote class="warning" data-svelte-h="svelte-vab5u6"><p>Protected visibility is part of <a href="https://huggingface.co/pro">PRO</a> or <a href="https://huggingface.co/enterprise">Team &amp; Enterprise</a> plans.</p></blockquote> <table data-svelte-h="svelte-ld0670"><thead><tr><th></th> <th>Public</th> <th>Protected</th> <th>Private</th></tr></thead> <tbody><tr><td>Source code on the Hub</td> <td>Visible to everyone</td> <td>Private (only owner/collaborators)</td> <td>Private (only owner/collaborators)</td></tr> <tr><td>App accessible via embed URL</td> <td>Yes</td> <td>Yes</td> <td>No</td></tr> <tr><td>App accessible via <a href="./spaces-custom-domain">custom domain</a></td> <td>Yes</td> <td>Yes</td> <td>No</td></tr> <tr><td>Clonable by others</td> <td>Yes</td> <td>No</td> <td>No</td></tr></tbody></table> <p data-svelte-h="svelte-1xpri1p"><strong>Public</strong> Spaces are fully open: anyone can view the source code, access the running app, and clone the repository.</p> <p data-svelte-h="svelte-wxwni7"><strong>Protected</strong> Spaces keep their source code private on the Hub — only the owner and collaborators can view or clone the repository. However, the running app is publicly accessible through its embed URL (<code>https://&lt;space-subdomain&gt;.hf.space</code>) or through a <a href="./spaces-custom-domain">custom domain</a> when one is configured. This is especially useful for hosting websites or apps without publishing the source code.</p> <p data-svelte-h="svelte-zlhwa6"><strong>Private</strong> Spaces are fully private: the source code and the running app are only accessible to the owner and collaborators. The Space will not appear in search results and other users will receive a <code>404</code> error when visiting its URL.</p> <h2 class="relative group"><a id="hardware-resources" 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="#hardware-resources"><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>Hardware resources</span></h2> <p data-svelte-h="svelte-i0ik24">Each Spaces environment is limited to 16GB RAM, 2 CPU cores and 50GB of (not persistent) disk space by default, which you can use free of charge. You can upgrade to better hardware, including a variety of GPU accelerators, for a <a href="https://huggingface.co/pricing#spaces" rel="nofollow">competitive price</a>. To request an upgrade, please click the <em>Settings</em> button in your Space and select your preferred hardware environment.</p> <table data-svelte-h="svelte-170d6hk"><thead><tr><th><strong>Hardware</strong></th> <th><strong>CPU</strong></th> <th><strong>Memory</strong></th> <th><strong>GPU Memory</strong></th> <th><strong>Hourly Price</strong></th></tr></thead> <tbody><tr><td>CPU Basic</td> <td>2 vCPU</td> <td>16 GB</td> <td></td> <td>FREE</td></tr> <tr><td>CPU Upgrade</td> <td>8 vCPU</td> <td>32 GB</td> <td></td> <td>$0.03</td></tr> <tr><td>Nvidia T4 - small</td> <td>4 vCPU</td> <td>15 GB</td> <td>16 GB</td> <td>$0.40</td></tr> <tr><td>Nvidia T4 - medium</td> <td>8 vCPU</td> <td>30 GB</td> <td>16 GB</td> <td>$0.60</td></tr> <tr><td>1x Nvidia L4</td> <td>8 vCPU</td> <td>30 GB</td> <td>24 GB</td> <td>$0.80</td></tr> <tr><td>4x Nvidia L4</td> <td>48 vCPU</td> <td>186 GB</td> <td>96 GB</td> <td>$3.80</td></tr> <tr><td>1x Nvidia L40S</td> <td>8 vCPU</td> <td>62 GB</td> <td>48 GB</td> <td>$1.80</td></tr> <tr><td>4x Nvidia L40S</td> <td>48 vCPU</td> <td>382 GB</td> <td>192 GB</td> <td>$8.30</td></tr> <tr><td>8x Nvidia L40S</td> <td>192 vCPU</td> <td>1534 GB</td> <td>384 GB</td> <td>$23.50</td></tr> <tr><td>Nvidia A10G - small</td> <td>4 vCPU</td> <td>15 GB</td> <td>24 GB</td> <td>$1.00</td></tr> <tr><td>Nvidia A10G - large</td> <td>12 vCPU</td> <td>46 GB</td> <td>24 GB</td> <td>$1.50</td></tr> <tr><td>2x Nvidia A10G - large</td> <td>24 vCPU</td> <td>92 GB</td> <td>48 GB</td> <td>$3.00</td></tr> <tr><td>4x Nvidia A10G - large</td> <td>48 vCPU</td> <td>184 GB</td> <td>96 GB</td> <td>$5.00</td></tr> <tr><td>Nvidia A100 - large</td> <td>12 vCPU</td> <td>142 GB</td> <td>80 GB</td> <td>$2.50</td></tr> <tr><td>4x Nvidia A100</td> <td>48 vCPU</td> <td>568 GB</td> <td>320 GB</td> <td>$10.00</td></tr> <tr><td>8x Nvidia A100</td> <td>96 vCPU</td> <td>1136 GB</td> <td>640 GB</td> <td>$20.00</td></tr></tbody></table> <p data-svelte-h="svelte-n7rtka">Note: Find more detailed and comprehensive pricing information on <a href="https://huggingface.co/pricing" rel="nofollow">our pricing page</a>.</p> <p data-svelte-h="svelte-wgzaw3">Do you have an awesome Space but need help covering the hardware upgrade costs? We love helping out those with an innovative Space so please feel free to apply for a community GPU grant using the link in the <em>Settings</em> tab of your Space and see if yours makes the cut!</p> <p data-svelte-h="svelte-1jswizx">Read more in our dedicated sections on <a href="./spaces-gpus">Spaces GPU Upgrades</a> and <a href="./spaces-storage">Spaces Disk Usage &amp; Storage</a>.</p> <div class="flex justify-center" data-svelte-h="svelte-195xp0n"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/spaces-gpu-settings.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/spaces-gpu-settings-dark.png"></div> <h2 class="relative group"><a id="managing-secrets" 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="#managing-secrets"><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>Managing secrets and environment variables</span></h2> <a id="managing-secrets"></a> <p data-svelte-h="svelte-ymimzr">If your app requires environment variables (for instance, secret keys or tokens), do not hard-code them inside your app! Instead, go to the Settings page of your Space repository and add a new <strong>variable</strong> or <strong>secret</strong>. Use variables if you need to store non-sensitive configuration values and secrets for storing access tokens, API keys, or any sensitive value or credentials.</p> <div class="flex justify-center" data-svelte-h="svelte-14hd4nx"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/secrets-and-variables.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/secrets-and-variables-dark.png"></div> <p data-svelte-h="svelte-gupaho">You can use:</p> <ul data-svelte-h="svelte-8c1m25"><li><strong>Variables</strong> if you need to store non-sensitive configuration values. They are publicly accessible and viewable and will be automatically added to Spaces duplicated from yours.</li> <li><strong>Secrets</strong> to store access tokens, API keys, or any sensitive values or credentials. They are private and their value cannot be read from the Space’s settings page once set. They won’t be added to Spaces duplicated from your repository.</li></ul> <p data-svelte-h="svelte-1c2e82y">Accessing secrets and variables is different depending on your Space SDK:</p> <ul data-svelte-h="svelte-116i5dc"><li>For Static Spaces, both are available through client-side JavaScript in <code>window.huggingface.variables</code></li> <li>For Docker Spaces, check out <a href="./spaces-sdks-docker#secrets-and-variables-management">environment management with Docker</a></li></ul> <p data-svelte-h="svelte-1bveqyq">For other Spaces, both are exposed to your app as environment variables. Here is a very simple example of accessing the previously declared <code>MODEL_REPO_ID</code> variable in Python (it would be the same for secrets):</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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> os
<span class="hljs-built_in">print</span>(os.getenv(<span class="hljs-string">&#x27;MODEL_REPO_ID&#x27;</span>))<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1v84tkz">Spaces owners are warned when our <code>Spaces Secrets Scanner</code> <a href="./security-secrets">finds hard-coded secrets</a>.</p> <h2 class="relative group"><a id="duplicating-a-space" 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="#duplicating-a-space"><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>Duplicating a Space</span></h2> <p data-svelte-h="svelte-z7bwe5">Duplicating a Space can be useful if you want to build a new demo using another demo as an initial template. Duplicated Spaces can also be useful if you want to have an individual Upgraded Space for your use with fast inference.</p> <p data-svelte-h="svelte-zgffzw">If you want to duplicate a Space, you can click the three dots at the top right of the space and click <strong>Duplicate this Space</strong>. Once you do this, you will be able to change the following attributes:</p> <ul data-svelte-h="svelte-1hympk"><li>Owner: The duplicated Space can be under your account or any organization in which you have write access</li> <li>Space name</li> <li>Visibility: The Space is private by default. Read more about visibility options <a href="./repositories-settings#repository-visibility">here</a>.</li> <li>Hardware: You can choose the hardware on which the Space will be running. Read more about hardware upgrades <a href="./spaces-gpus">here</a>.</li> <li>Storage: If the original repo uses a storage bucket, you will be prompted to configure storage. Read more about disk usage and storage <a href="./spaces-storage">here</a>.</li> <li>Secrets and variables: If the original repo has set some secrets and variables, you’ll be able to set them while duplicating the repo.</li></ul> <p data-svelte-h="svelte-1bm0pjk">Some Spaces might have environment variables that you may need to set up. In these cases, the duplicate workflow will auto-populate the public Variables from the source Space, and give you a warning about setting up the Secrets. The duplicated Space will use a free CPU hardware by default, but you can later upgrade if needed.</p> <h2 class="relative group"><a id="networking" 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="#networking"><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>Networking</span></h2> <p data-svelte-h="svelte-1epumyh">If your Space needs to make any network requests, you can make requests through the standard HTTP and HTTPS ports (80 and 443) along with port 8080. Any requests going to other ports will be blocked.</p> <h2 class="relative group"><a id="lifecycle-management" 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="#lifecycle-management"><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>Lifecycle management</span></h2> <p data-svelte-h="svelte-x3n4qj">On free hardware, your Space will “go to sleep” and stop executing after a period of time if unused. If you wish for your Space to run indefinitely, consider <a href="./spaces-gpus">upgrading to paid hardware</a>. You can also manually pause your Space from the <strong>Settings</strong> tab. A paused Space stops executing until manually restarted by its owner.
Paused time is not billed.</p> <h2 class="relative group"><a id="built-in-environment-variables" 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="#built-in-environment-variables"><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>Built-in environment variables</span></h2> <p data-svelte-h="svelte-jh0npg">In some cases, you might be interested in having programmatic access to the Space author or repository name. This feature is particularly useful when you expect users to duplicate your Space. To help with this, Spaces exposes different environment variables at runtime (see also <a href="./jobs-configuration#built-in-environment-variables">built-in environment variables in Jobs</a>). Given a Space <a href="https://huggingface.co/spaces/osanseviero/i-like-flan" rel="nofollow"><code>osanseviero/i-like-flan</code></a>:</p> <ul data-svelte-h="svelte-1hmum4s"><li><code>ACCELERATOR</code>: The type of accelerator available (e.g., <code>t4-medium</code>, <code>a10g-small</code>), or <code>none</code> for CPU-only Spaces.</li> <li><code>CPU_CORES</code>: 4</li> <li><code>MEMORY</code>: 15Gi</li> <li><code>SPACE_AUTHOR_NAME</code>: osanseviero</li> <li><code>SPACE_REPO_NAME</code>: i-like-flan</li> <li><code>SPACE_TITLE</code>: I Like Flan (specified in the README file)</li> <li><code>SPACE_ID</code>: <code>osanseviero/i-like-flan</code></li> <li><code>SPACE_HOST</code>: <code>osanseviero-i-like-flan.hf.space</code></li> <li><code>SPACE_CREATOR_USER_ID</code>: <code>6032802e1f993496bc14d9e3</code> - This is the ID of the user that originally created the Space. It’s useful if the Space is under an organization. You can get the user information with an API call to <code>https://huggingface.co/api/users/{SPACE_CREATOR_USER_ID}/overview</code>.</li></ul> <p data-svelte-h="svelte-11liddo">In case <a href="./spaces-oauth">OAuth</a> is enabled for your Space, the following variables will also be available:</p> <ul data-svelte-h="svelte-xqogzb"><li><code>OAUTH_CLIENT_ID</code>: the client ID of your OAuth app (public)</li> <li><code>OAUTH_CLIENT_SECRET</code>: the client secret of your OAuth app</li> <li><code>OAUTH_SCOPES</code>: scopes accessible by your OAuth app. Currently, this is always <code>&quot;openid profile&quot;</code>.</li> <li><code>OPENID_PROVIDER_URL</code>: The URL of the OpenID provider. The OpenID metadata will be available at <a href="https://huggingface.co/.well-known/openid-configuration" rel="nofollow"><code>{OPENID_PROVIDER_URL}/.well-known/openid-configuration</code></a>.</li></ul> <h2 class="relative group"><a id="clone-the-repository" 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="#clone-the-repository"><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>Clone the Repository</span></h2> <p data-svelte-h="svelte-88ak7z">You can easily clone your Space repo locally. Start by clicking on the dropdown menu in the top right of your Space page:</p> <div class="flex justify-center" data-svelte-h="svelte-r0ejq5"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/SpacesCloneRepo2.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/SpacesCloneRepo1.png"></div> <p data-svelte-h="svelte-1ng273c">Select “Clone repository”, and then you’ll be able to follow the instructions to clone the Space repo to your local machine using HTTPS or SSH.</p> <div class="flex justify-center" data-svelte-h="svelte-1cf9dof"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/HttpsClone2.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/HttpsClone1.png"></div> <div class="flex justify-center" data-svelte-h="svelte-19uvgzf"><img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/SSHClone2.png"> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/SSHClone1.png"></div> <h2 class="relative group"><a id="linking-models-and-datasets-on-the-hub" 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="#linking-models-and-datasets-on-the-hub"><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>Linking Models and Datasets on the Hub</span></h2> <p data-svelte-h="svelte-dpjyhk">You can showcase all the models and datasets that your Space links to by adding their identifier in your Space’s README metadata. To do so, you can define them under the <code>models</code> and <code>datasets</code> keys. In addition to listing the artefacts in the README file, you can also record them in any <code>.py</code>, <code>.ini</code> or <code>.html</code> file as well. We’ll parse it auto-magically!</p> <p data-svelte-h="svelte-1f8atbc">Here’s an example linking two models from a space:</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-attribute">title</span>: My lovely space
<span class="hljs-attribute">emoji</span>: 🤗
<span class="hljs-attribute">colorFrom</span>: blue
<span class="hljs-attribute">colorTo</span>: green
<span class="hljs-attribute">sdk</span>: docker
<span class="hljs-attribute">pinned</span>: false
<span class="hljs-attribute">models</span>:
<span class="hljs-literal">-</span> reach-vb/musicgen-large-fp16-endpoint
<span class="hljs-literal">-</span> reach-vb/wav2vec2-large-xls-r-1B-common_voice7-lt-ft<!-- HTML_TAG_END --></pre></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-overview.md" target="_blank"><svg class="mr-1" 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="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1bollga = {
assets: "/docs/hub/pr_2521/en",
base: "/docs/hub/pr_2521/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/hub/pr_2521/en/_app/immutable/entry/start.d19e5ca7.js"),
import("/docs/hub/pr_2521/en/_app/immutable/entry/app.98ab229a.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 209],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
39.7 kB
·
Xet hash:
74c6e8c6e65398855928d8a5d63dd595d338a085ca5674541686c3efceb42038

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.