Deploy a FastHTML application to HuggingFace Spaces for free with one command!
- Create a free account on HuggingFace
- Go to your account settings and create an access token with write access. Keep this token safe and don't share it.
- Set the
HF_TOKEN
environment variable to that token - Install fasthtml-hf:
pip install fasthtml-hf
- HuggingFace needs
fasthtml-hf
to run your space, so add it to your requirements.txt file. - At the top of your
main.py
addfrom fasthtml_hf import setup_hf_backup
, and just before you run uvicorn addsetup_hf_backup(app)
- Run
fh_hf_deploy <space_name>
, replacing<space_name>
with the name you want to give your space.
By default this will upload a public space. You can make it private with --private true
.
The space will upload a backup of your database to a HuggingFace Dataset. By default it will be private and its name will be <your-huggingface-id>/space-backup
. You can change this behavior in the config.ini
file. In not provided, a default file will be created with the contents (note that the [DEFAULT]
line is required at the top):
[DEFAULT]
dataset_id = space-backup
db_dir = data
private_backup = True
interval = 15 # number of minutes between periodic backups
If you so choose, you can disable the automatic backups and use persistent storage instead for $5/month (USD).