{"course":{"slug":"hugging-face","title":"Hugging Face, End to End","url":"https://addaly.com/learn/hugging-face","level":"intermediate","track":"create"},"lesson":{"slug":"duplicate-a-space","title":"Duplicate it, and the app becomes yours to change","url":"https://addaly.com/learn/hugging-face/duplicate-a-space","position":31,"of":75,"minutes":9,"answer":"Duplicating a Space gives you a private copy with no queue, but paid hardware bills for wall-clock time and does not sleep the way free hardware does: set the sleep timer before you upgrade.","keyIdea":"Duplicating a Space gives you a private copy with no queue, but paid hardware bills for wall-clock time and does not sleep the way free hardware does: set the sleep timer before you upgrade."},"body":{"format":"markdown","text":"## One click is the whole difference\n\nOn any Space, the menu at the top right has *Duplicate this Space*. You choose an owner, a name, public or private, and hardware: free CPU is the default and stays the default unless you pick otherwise. A few seconds later there is a copy in your account, running your build, with no queue but yours.\n\nThis is the single most valuable thing on the Hub for someone who does not write much code, because it converts *using a tool* into *owning a tool*. Duplicating is also how you handle sensitive files: the code now runs in a container you control, and you can make it private so nobody else can reach it.\n\n## What you actually get\n\nUsually three files.\n\n- **`app.py`**: the whole program. For a Gradio Space this is typically a model load, a function, and a description of the interface. Under two hundred lines is normal.\n- **`requirements.txt`**: the Python packages to install at build time.\n- **`README.md`**: which is also the deployment configuration, because the YAML block at the top is read by the Hub:\n\n```yaml\n---\ntitle: Background Remover\nsdk: gradio\nsdk_version: 4.44.0\napp_file: app.py\nsuggested_hardware: cpu-basic\n---\n```\n\nEdit any file in the browser. Committing triggers a rebuild, and the Logs tab shows the build output and the running application's output separately. When something goes wrong, the traceback is one click away in there. This is the habit that separates people who can fix a Space from people who delete it and try another.\n\n## The failure you will meet first\n\nYou duplicate a Space written two years ago. It builds, then dies with a `TypeError` about an unexpected keyword argument. Nothing you did is wrong. The `sdk_version` line was absent or loose, the build picked a newer Gradio, and an argument was renamed between major versions.\n\nThe fix is to pin: set `sdk_version` in the README to the version the original was written against, and pin the packages in `requirements.txt` that matter. It is the same lesson as pinning a model revision in lesson one, and for the same reason: anything unpinned changes under you eventually.\n\n## Hardware is a rental, so treat it like one\n\nSettings lets you change hardware on a running Space. This is where people get a surprising bill, and the mechanism is worth stating plainly.\n\n**Free hardware sleeps. Paid hardware does not, by default.** The 48-hour sleep that pauses idle free Spaces is a cost-control measure for the Hub, and it does not apply to a GPU you are renting. A rented GPU bills for wall-clock time from the moment it starts until you pause it or downgrade it, whether or not anyone uses the Space. Leaving one on over a weekend costs the same as using it hard for the weekend.\n\nSo: rent the GPU, do the work, and then either pause the Space or set it back to CPU basic. In Settings there is also a sleep timer for paid hardware: set it to something small, like fifteen minutes, the moment you upgrade. Do it before you start the job, not after, because *after* is when you forget.\n\n## Secrets and variables\n\nSettings has a *Variables and secrets* section. Variables are visible to anyone; secrets are stored encrypted, handed to your code as environment variables, never shown on the page, and not carried over when somebody duplicates your Space: they are prompted for their own. Read them normally:\n\n```python\nimport os\n\ntoken = os.environ[\"HF_TOKEN\"]\n```\n\nWhat you must never do is put the key in `app.py`. A public Space's files are public, permanently and to everyone, and the next lesson is about exactly what that costs.\n\n## When the free GPU you need is somewhere else\n\nIf what you want is a one-off render rather than a hosted app, renting is often the wrong shape. Kaggle notebooks give roughly thirty GPU-hours a week free with a verified phone number, which is a generous allocation and enough to fine-tune a small model. Colab's free tier is smaller and can be interrupted. Both let you pull models and datasets straight from the Hub, so the skills transfer completely.\n\n## Do this now\n\nDuplicate one Space you use. Change one visible string in `app.py` (a title, a label, a default value) commit, and watch the rebuild in the Logs tab. That loop is the whole of deploying software on this platform."},"check":{"question":"Someone duplicates a Space, switches it to a rented A10G on Friday afternoon to render a batch, finishes in twenty minutes, closes the browser tab and goes home. On Monday the bill is far larger than expected. What is the mechanism?","options":[{"text":"Rebuilds triggered by upstream package updates over the weekend each consumed GPU time.","correct":false,"tempting":"Imagines automatic rebuilds happening on an idle Space rather than only on a commit."},{"text":"The Space stayed publicly reachable, so other people used it and their requests were billed to the owner.","correct":false,"tempting":"Assumes billing follows requests served rather than time the hardware is held."},{"text":"Closing the browser tab did not stop the container, and it kept running until the next visit woke it properly.","correct":false,"tempting":"Ties the container's lifetime to the owner's browser session."},{"text":"Rented hardware bills for wall-clock time and does not auto-sleep the way free hardware does, so the GPU was held all weekend doing nothing.","correct":true}]},"prev":{"slug":"gradio-blocks-and-state","title":"Blocks, when Interface is no longer enough","url":"https://addaly.com/learn/hugging-face/gradio-blocks-and-state"},"next":{"slug":"the-space-configuration","title":"The README front matter is the deployment config","url":"https://addaly.com/learn/hugging-face/the-space-configuration"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Duplicate it, and the app becomes yours to change', in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/duplicate-a-space (Accessed: 31 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Duplicate it, and the app becomes yours to change","courseTitle":"Hugging Face, End to End","module":{"index":4,"slug":"spaces-and-shipping-something","title":"Spaces: putting something in front of people"},"answer":null,"keyIdea":"Duplicating a Space gives you a private copy with no queue, but paid hardware bills for wall-clock time and does not sleep the way free hardware does: set the sleep timer before you upgrade.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"one-click-is-the-whole-difference","runs":[{"text":"One click is the whole difference"}]},{"t":"p","runs":[{"text":"On any Space, the menu at the top right has "},{"text":"Duplicate this Space","i":true},{"text":". You choose an owner, a name, public or private, and hardware: free CPU is the default and stays the default unless you pick otherwise. A few seconds later there is a copy in your account, running your build, with no queue but yours."}]},{"t":"p","runs":[{"text":"This is the single most valuable thing on the Hub for someone who does not write much code, because it converts "},{"text":"using a tool","i":true},{"text":" into "},{"text":"owning a tool","i":true},{"text":". Duplicating is also how you handle sensitive files: the code now runs in a container you control, and you can make it private so nobody else can reach it."}]},{"t":"h2","id":"what-you-actually-get","runs":[{"text":"What you actually get"}]},{"t":"p","runs":[{"text":"Usually three files."}]},{"t":"ul","items":[[{"text":"app.py","b":true,"code":true},{"text":": the whole program. For a Gradio Space this is typically a model load, a function, and a description of the interface. Under two hundred lines is normal."}],[{"text":"requirements.txt","b":true,"code":true},{"text":": the Python packages to install at build time."}],[{"text":"README.md","b":true,"code":true},{"text":": which is also the deployment configuration, because the YAML block at the top is read by the Hub:"}]]},{"t":"code","lang":"yaml","label":"YAML","text":"---\ntitle: Background Remover\nsdk: gradio\nsdk_version: 4.44.0\napp_file: app.py\nsuggested_hardware: cpu-basic\n---"},{"t":"p","runs":[{"text":"Edit any file in the browser. Committing triggers a rebuild, and the Logs tab shows the build output and the running application’s output separately. When something goes wrong, the traceback is one click away in there. This is the habit that separates people who can fix a Space from people who delete it and try another."}]},{"t":"h2","id":"the-failure-you-will-meet-first","runs":[{"text":"The failure you will meet first"}]},{"t":"p","runs":[{"text":"You duplicate a Space written two years ago. It builds, then dies with a "},{"text":"TypeError","code":true},{"text":" about an unexpected keyword argument. Nothing you did is wrong. The "},{"text":"sdk_version","code":true},{"text":" line was absent or loose, the build picked a newer Gradio, and an argument was renamed between major versions."}]},{"t":"p","runs":[{"text":"The fix is to pin: set "},{"text":"sdk_version","code":true},{"text":" in the README to the version the original was written against, and pin the packages in "},{"text":"requirements.txt","code":true},{"text":" that matter. It is the same lesson as pinning a model revision in lesson one, and for the same reason: anything unpinned changes under you eventually."}]},{"t":"h2","id":"hardware-is-a-rental-so-treat-it-like-one","runs":[{"text":"Hardware is a rental, so treat it like one"}]},{"t":"p","runs":[{"text":"Settings lets you change hardware on a running Space. This is where people get a surprising bill, and the mechanism is worth stating plainly."}]},{"t":"p","runs":[{"text":"Free hardware sleeps. Paid hardware does not, by default.","b":true},{"text":" The 48-hour sleep that pauses idle free Spaces is a cost-control measure for the Hub, and it does not apply to a GPU you are renting. A rented GPU bills for wall-clock time from the moment it starts until you pause it or downgrade it, whether or not anyone uses the Space. Leaving one on over a weekend costs the same as using it hard for the weekend."}]},{"t":"p","runs":[{"text":"So: rent the GPU, do the work, and then either pause the Space or set it back to CPU basic. In Settings there is also a sleep timer for paid hardware: set it to something small, like fifteen minutes, the moment you upgrade. Do it before you start the job, not after, because "},{"text":"after","i":true},{"text":" is when you forget."}]},{"t":"h2","id":"secrets-and-variables","runs":[{"text":"Secrets and variables"}]},{"t":"p","runs":[{"text":"Settings has a "},{"text":"Variables and secrets","i":true},{"text":" section. Variables are visible to anyone; secrets are stored encrypted, handed to your code as environment variables, never shown on the page, and not carried over when somebody duplicates your Space: they are prompted for their own. Read them normally:"}]},{"t":"code","lang":"python","label":"Python","text":"import os\n\ntoken = os.environ[\"HF_TOKEN\"]"},{"t":"p","runs":[{"text":"What you must never do is put the key in "},{"text":"app.py","code":true},{"text":". A public Space’s files are public, permanently and to everyone, and the next lesson is about exactly what that costs."}]},{"t":"h2","id":"when-the-free-gpu-you-need-is-somewhere-else","runs":[{"text":"When the free GPU you need is somewhere else"}]},{"t":"p","runs":[{"text":"If what you want is a one-off render rather than a hosted app, renting is often the wrong shape. Kaggle notebooks give roughly thirty GPU-hours a week free with a verified phone number, which is a generous allocation and enough to fine-tune a small model. Colab’s free tier is smaller and can be interrupted. Both let you pull models and datasets straight from the Hub, so the skills transfer completely."}]},{"t":"h2","id":"do-this-now","runs":[{"text":"Do this now"}],"role":"try"},{"t":"p","runs":[{"text":"Duplicate one Space you use. Change one visible string in "},{"text":"app.py","code":true},{"text":" (a title, a label, a default value) commit, and watch the rebuild in the Logs tab. That loop is the whole of deploying software on this platform."}]}],"check":{"question":[{"text":"Someone duplicates a Space, switches it to a rented A10G on Friday afternoon to render a batch, finishes in twenty minutes, closes the browser tab and goes home. On Monday the bill is far larger than expected. What is the mechanism?"}],"options":[{"text":[{"text":"Rebuilds triggered by upstream package updates over the weekend each consumed GPU time."}],"correct":false,"tempting":[{"text":"Imagines automatic rebuilds happening on an idle Space rather than only on a commit."}]},{"text":[{"text":"The Space stayed publicly reachable, so other people used it and their requests were billed to the owner."}],"correct":false,"tempting":[{"text":"Assumes billing follows requests served rather than time the hardware is held."}]},{"text":[{"text":"Closing the browser tab did not stop the container, and it kept running until the next visit woke it properly."}],"correct":false,"tempting":[{"text":"Ties the container’s lifetime to the owner’s browser session."}]},{"text":[{"text":"Rented hardware bills for wall-clock time and does not auto-sleep the way free hardware does, so the GPU was held all weekend doing nothing."}],"correct":true,"tempting":null}],"order":[1,3,0,2],"why":null},"prev":{"slug":"gradio-blocks-and-state","title":"Blocks, when Interface is no longer enough","minutes":9},"next":{"slug":"the-space-configuration","title":"The README front matter is the deployment config","minutes":8}}}