Deployment Guide: Hugging Face Spaces
This guide will help you deploy your Prism application to Hugging Face Spaces using Docker.
Prerequisites
- A Hugging Face account.
- Git installed on your computer.
Step 1: Create a New Space
- Go to huggingface.co/new-space.
- Space Name: Enter a name (e.g.,
prism-classifier). - License: Choose a license (e.g., MIT) or leave blank.
- SDK: Select Docker.
- Space Hardware: Select CPU Basic (Free) (or upgrade if you need more power for AI models).
- Visibility: Public or Private.
- Click Create Space.
Step 2: Setup Git for Deployment
You need to link your local project to the Hugging Face Space.
- Open your terminal in the project root (
d:\My Stuff\Coding Projects\Prism). - Initialize Git (if not already done):
git init - Add the Hugging Face remote (replace
YOUR_USERNAMEandSPACE_NAME):git remote add space https://huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME
Step 3: Prepare Files (Already Done!)
I have already configured the necessary files for you:
Dockerfile: Builds the React frontend and sets up the Python backend.app.py: Configured to run on port 7860 (required by HF Spaces).requirements.txt: Lists all Python dependencies.
Step 4: Deploy
To deploy, simply commit your changes and push to the space remote.
Add files:
git add .Commit:
git commit -m "Initial deploy to Hugging Face"Push:
git push space master:main(Note: HF Spaces usually use
mainbranch. If your local branch ismaster, usemaster:main. If local ismain, justgit push space main).IMPORTANT: Authentication When asked for your Username, enter your Hugging Face username. When asked for your Password, you MUST enter an Access Token, not your account password.
How to get a Token:
- Go to huggingface.co/settings/tokens.
- Click Create new token.
- Type: Write. Name: "Deploy".
- Copy the token (starts with
hf_...). - Paste this token when the terminal asks for your password.
Troubleshooting: "Updates were rejected" If you see an error saying "Updates were rejected", it means your Space already has a
README.mdthat you don't have locally. For the first push only, you can force overwrite it:git push --force space master:mainTroubleshooting: "File larger than 10MB" If you see an error about
static/background.mp3being too large, you need Git LFS:git lfs install git lfs track "static/background.mp3" git add .gitattributes git commit --amend --no-edit git push --force space master:main
Step 5: Future Updates
To reflect future changes on the live site:
- Make your changes in the code.
- Run:
git add . git commit -m "Update description" git push space master:main
The Space will automatically rebuild and update!
Troubleshooting
- Build Failures: Check the "Logs" tab in your Hugging Face Space to see why the build failed.
- Large Files: If you have large model files (>10MB), you might need to use
git lfs. However, your models seem to be downloaded at runtime, so this shouldn't be an issue.