Hugging Face Spaces Tutorial: Deploy a Demo Without a Server
Hugging Face Spaces tutorial: deploy a Gradio demo without a server, step by step — create the Space, write app.py, push and share the link.
By Galactic News Editorial · Published 2026-11-17T13:47:13+00:00 · Updated 2026-11-17T13:47:13+00:00
Hugging Face Spaces Tutorial: Deploy a Demo Without a Server
Hugging Face Spaces hosts a machine learning demo at a public URL with no server to manage. You push code to a git repository and Hugging Face builds and serves it. This tutorial walks through a Gradio demo from an empty folder to a live link.
A Space is a git repository that holds the app code, a dependencies file and a README whose YAML header describes the configuration. Spaces offer three SDK options: Gradio, Docker and static HTML. Gradio is the usual choice for a model demo.
Before You Start: The Hugging Face Spaces Tutorial Checklist
You need a free Hugging Face account and Python installed on your machine. No server, no domain and no deployment pipeline are needed. Hugging Face provides the hosting.
Know the limits before you build. Each Spaces environment is limited to 16 GB of RAM, 2 CPU cores and 50 GB of disk space by default, and that disk is not persistent. Static Spaces are free for everyone. Gradio and Docker Spaces run on compute and require a paid plan to create, although free personal accounts in good standing can host up to 2 Gradio Spaces running on ZeroGPU.
Plan the demo around those limits. A small text classifier or image demo fits easily. A large model that needs a GPU should use ZeroGPU or a paid hardware upgrade.
Step 1: Create the Space
Go to the Spaces main page and click Create new Space. Choose a name, pick the owner account and set the visibility. Spaces support three visibility levels: public, protected and private. Protected visibility is part of PRO or Team and Enterprise plans.
Select Gradio as the SDK. Hugging Face creates a new repository for the Space. The Space gets an address in the form huggingface.co/spaces/owner/name, and a direct app address in the form owner-name.hf.space.
Step 2: Write the Gradio App
Clone the new repository to your machine. Then create an app.py file. The example below builds a text classifier demo with a pre-trained transformer model from the Hugging Face Hub.
import gradio as gr
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
def classify(text):
result = classifier(text)[0]
return f"{result['label']}: {result['score']:.2f}"
demo = gr.Interface(
fn=classify,
inputs=gr.Textbox(label="Enter text"),
outputs=gr.Textbox(label="Result"),
)
demo.launch()
Gradio builds a web interface from the Python function. The Textbox becomes the input field and the function result becomes the output. Keep the app small. A short function and one model load faster and fail less often.
Step 3: List the Dependencies
Create a requirements.txt file in the same folder. List every library the app imports.
gradio
transformers
torch
Pin versions only if you have tested them together. Unpinned installs pull the latest releases, which can break a demo that worked yesterday. Test the app locally with the same requirements file before you push.
Step 4: Add the README Configuration
The README.md file carries the Space configuration in a YAML header at the top. It sets the title, the SDK and the app file.
---
title: Sentiment Classifier Demo
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
pinned: false
license: mit
---
A demo of a sentiment classifier.
Check the SDK version against the version you tested locally. A mismatch is a common cause of a Space that builds but does not start.
Step 5: Push and Deploy
Commit the files and push them to the Space repository.
git add .
git commit -m "Initial demo"
git push
Every push triggers an automatic rebuild and deployment. Hugging Face installs the dependencies, loads the model and serves the interface. The demo is usually live in one to two minutes.
There is a faster route for later updates. From the folder that holds app.py and requirements.txt, run gradio deploy after installing huggingface_hub and signing in. The command asks for a Space name and hardware, uploads the files and returns a URL.
Step 6: Secrets, Hardware and Sharing
Never put API keys in the code. Add secrets such as an API key in the Space settings, not in the repository. Any change to secrets or hardware restarts the app.
Upgrade hardware only when the demo needs it. The default CPU environment suits small models. GPU hardware costs more and bills per hour, so pause it when the demo is not in use. For bursty demos, ZeroGPU runs the model on a serverless GPU and suits demos that are used in bursts.
Share the demo with the public URL. A Space can also be embedded in another website. Duplicating a Space copies the code and configuration, which is useful for forks and experiments.
Start From a Template Instead of a Blank Page
Hugging Face offers official Space templates, including a JupyterLab environment, a Gradio chatbot and a Streamlit app. Starting from a template gives you a working app skeleton with the configuration already set, so you only change the model and the interface.
Templates are listed through the huggingface_hub library with list_space_templates, and a template can be passed as the space_template argument when creating a repository. For a first demo, the Gradio chatbot template is a good choice, because it already handles the chat interface and the message history.
Duplicating an existing Space is another fast start. It copies the code and the configuration into your own account, where you can change the model or the prompt without touching the original.
Common Problems and Fixes
If the build fails, read the build log first. The usual causes are a missing dependency in requirements.txt, a wrong app file name in the README header, or a model that is too large for the default hardware.
If the app starts but the model does not load, check the model name and the pipeline task. A model built for one task will not load under another task name.
If the demo sleeps, that is normal. Free Spaces sleep when idle and wake on the next visit. For a demo that must stay awake, a paid hardware plan is the answer.
Bottom Line
A Hugging Face Space turns a Gradio script into a public demo with a git push. Create the Space, write app.py and requirements.txt, set the README header, push, and share the link. Keep secrets in settings, keep the model small enough for the default hardware, and remember that Spaces are a demo platform, not production hosting. For production traffic, use a dedicated inference endpoint instead.