Absolutely!
Every model or Space you see on the Hugging Face Hub can be pulled down and run entirely on your own machine or private server—no calls back to Hugging Face once everything is downloaded. Below is a quick-start plus some extra tips for true offline/air-gapped use.
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="google/flan-t5-base", # 👈 any model, dataset, or Space
repo_type="model", # omit for models (default). use "space" for Spaces
local_dir="./hf_models/flan-t5", # where to put the files
local_dir_use_symlinks=False # copy instead of symlink (handy for containers)
)
(For Spaces, replace repo-type model with repo-type space.)
🤝 Licenses & gated models
Some repos ask you to agree to a license or EULA. You’ll need to log in (huggingface-cli login) once to accept before the download.
2. Use the files 100 % locally
bash
pip install -U transformers torch # or your preferred framework
python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_path = "./hf_models/flan-t5" # 👈 local folder, not a Hub name
tok = AutoTokenizer.from_pretrained(model_path, local_files_only=True)
model = AutoModelForSeq2SeqLM.from_pretrained(model_path, local_files_only=True)
text = "Translate: My dog loves pizza."
out = model.generate(**tok(text, return_tensors="pt").to(model.device))
print(tok.decode(out[0], skip_special_tokens=True))
Set these env vars if you want to enforce offline mode:
The libraries will now raise an error if anything tries to reach the internet.
3. Running a Space locally
Clone it:
bash
git lfs install # one-time
git clone https://huggingface.co/spaces/USERNAME/space-name
cd space-name
Install dependencies:
bash
pip install -r requirements.txt # often Gradio or Streamlit
Launch:
bash
python app.py # or `gradio app.py`, `streamlit run app.py`, etc.
The Space UI shows up on http://localhost:7860 (default for Gradio) and never leaves your machine.
4. Tips for smooth offline workflows
Need
Trick
Keep a clean cache
Set export HF_HOME=/path/to/hf_cache. Copy that folder onto any machine to “pre-seed” it.
Docker / Singularity
COPY the hf_cache into your image and set HF_HOME in the Dockerfile.
Large multi-GB checkpoints
Use --max-workers on snapshot_download to parallelize; or sync via rsync once downloaded.
Air-gapped cluster
Pre-download on a laptop with internet, move via external drive, drop under /opt/hf_models, and point code there.
Mirroring many models
Write a tiny loop around snapshot_download or use huggingface-cli list + download.
🎉 That’s it! After the initial download, neither your data nor your usage stats ever touch Hugging Face’s servers. Enjoy fully local, private inference (and fine-tuning if you like).