Why Spaces, Not Colab
Colab's free GPU is a one-shot session; Hugging Face Spaces is a persistent service with sleep-to-save behavior. You can deploy any open model (Llama, Qwen, Mistral, Stable Diffusion, etc.) as a public Space. It sleeps when idle and wakes on request. The key: hardware quota is account-level, but the endpoint is public. That means you can treat a Space as an on-demand free inference endpoint without maintaining your own server.
In 2026, free HF accounts still get CPU Basic (2 vCPU / 16GB RAM), and community GPUs (ZeroGPU, T4 small) offer queue-based quota for public Spaces. Exact numbers change often, so this article gives methods, not fixed figures.
Steps
1. Create a callable Space
- Log in to huggingface.co, click New Space.
- Pick Gradio or Docker SDK, start with CPU Basic (free).
- Expose a function in
app.pyviagr.Interfaceorgr.ChatInterface, e.g.:
```python
import gradio as gr
from transformers import pipeline
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct")
def generate(prompt):
return pipe(prompt, max_new_tokens=256)[0]["generated_text"]
gr.Interface(fn=generate, inputs="text", outputs="text").launch()
```
- Wait for the build. Your public Space gets a
https://<user>-<space>.hf.spacedomain.
2. Call it via API, not the web UI
Gradio Spaces expose /call and /api/predict endpoints (depending on Gradio version). A safer route is gradio_client:
```python
from gradio_client import Client
client = Client("your-username/your-space")
result = client.predict("hello", api_name="/predict")
print(result)
```
Now your script gets a free inference call, while the Space burns HF-allocated free hardware.
3. Request community GPU (ZeroGPU / T4)
- In Space settings, switch hardware to ZeroGPU if eligible.
- ZeroGPU uses per-second queueing. Free accounts get a daily duration; the settings page shows something like “~X minutes/day”.
- If the ZeroGPU queue is long, fall back to T4 small, which also has free hours but usually fewer.
4. Chain multiple Spaces into a token pool
One Space's quota is limited, but you can:
- Create separate Spaces for different models (chat, embedding, image).
- Write a router script that dispatches by task type.
- Use
requestsorgradio_clientto poll available Spaces and fail over.
```python
SPACES = ["user/chat-space", "user/embed-space", "user/img-space"]
for s in SPACES:
try:
c = Client(s)
out = c.predict("test", api_name="/predict")
print(s, "OK", out[:50])
break
except Exception as e:
print(s, "failed", e)
```
5. Monitor quota and sleep state
- The Space page shows current hardware and remaining time (if any).
- Query Space status via HF API:
https://huggingface.co/api/spaces/<user>/<space>. - If
runtime.stageisSLEEPING, the next call triggers a cold start, usually 10–60 seconds.
Caveats
- Cold start latency: A sleeping Space may time out on first call. Set
timeout=120and add retries. - Public visibility: Inputs and outputs on a public Space are visible to everyone. Don't send sensitive data.
- Quota is not guaranteed: ZeroGPU / T4 free hours are adjusted dynamically by HF and may shrink or queue longer.
- No abuse: Scripted high-frequency calls may trigger rate limits or bans. Keep it reasonable (a few calls per minute).
- Model licenses: Some models (e.g., Llama) require accepting a license on HF first, or the Space build fails.
Use cases
- Individual developers prototyping without paying for occasional inference.
- Small teams needing a stable internal endpoint with low volume.
- Teaching / demo scenarios needing a public inference endpoint.
Limits
- Not for high-concurrency production.
- Not for tasks with private data.
- Free GPU hours are finite; heavy use still needs paid or self-hosted options.