DEV Community

niuniu
niuniu

Posted on

Quick Tip: Host Your ML Demo for Free on Hugging Face Spaces (No Server Needed)

You built a cool ML demo. Now you need a server, a domain, SSL, and a Dockerfile. Or you could spend 3 minutes on Hugging Face Spaces and get a public URL with free CPU (or GPU if you're lucky).

The 3-Minute Deploy

pip install gradio huggingface_hub
huggingface-cli login  # token from hf.co/settings/tokens
Enter fullscreen mode Exit fullscreen mode
# app.py
import gradio as gr
from transformers import pipeline

classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

def predict(text):
    return classifier(text)[0]

gr.Interface(fn=predict, inputs="text", outputs="label", title="Sentiment Demo").launch()
Enter fullscreen mode Exit fullscreen mode
huggingface-cli repo create my-demo --type space
git clone https://huggingface.co/spaces/YOUR_USERNAME/my-demo
cd my-demo
# copy app.py + requirements.txt
git add . && git commit -m "init" && git push
Enter fullscreen mode Exit fullscreen mode

Your demo is live at https://YOUR_USERNAME-my-demo.hf.space in ~60 seconds.

What You Get for Free

Feature Free Tier
CPU 2 vCPU, 16GB RAM
GPU T4 (community grant, queue-based)
Custom domain Yes (CNAME)
Sleep after 48h inactivity
Persistent storage 50GB (ephemeral)

The Catch

The free T4 GPU is a lottery — you request a community grant and wait. For CPU-only demos (sentiment, classification, small LLMs with llama.cpp) it's perfect. For SDXL or 70B models, bring your own inference API.

I use Spaces for every side project demo now. Zero DevOps, zero cost, and the URL looks legit in a portfolio.

Built the demo UI with MonkeyCode: https://ly.cyberserval.tech/iIETXiF

What's the most creative thing you've seen hosted on Spaces?

ai #python #tips #opensource

Top comments (0)