Hugging Face Spaces is a free platform to deploy and share machine learning apps using Python tools like Gradio, Streamlit, or FastAPI. In this guide, weโll walk you through the two main methods for uploading your app:
๐ HTTPS (using access token) โ easy and recommended for most users
๐ SSH (for advanced users) โ useful for devs who prefer key-based workflows
๐งฑ Prerequisites
- A free Hugging Face account
- Git installed
- Your app folder with a
README.md
,requirements.txt
, and an entry-point Python file likeapp.py
โ Method 1: Upload via HTTPS (Access Token) โ Recommended
Step 1: Create a New Space
- Go to Hugging Face Spaces
- Click โCreate new Spaceโ
- Choose:
- Space Name
- SDK: Gradio, Streamlit, etc.
-
Visibility: Public or private
- Click Create Space. This gives you a Git URL like:
https://huggingface.co/spaces/your-username/your-space-name
- Click Create Space. This gives you a Git URL like:
Step 2: Generate Access Token
- Go to Settings โ Access Tokens
- Click โNew tokenโ
- Choose:
-
Name: e.g.,
space-push
-
Role:
Write
- Copy the token (youโll need it in Step 3)
Step 3: Push Your Project Using the Token
In your terminal:
cd your-project-folder
git init
git remote add origin https://<your-username>:<your-token>@huggingface.co/spaces/<your-username>/<your-space-name>
git add .
git commit -m "Initial commit"
git push -u origin main
Replace:
<your-username>
: Hugging Face username<your-token>
: The access token you just copied<your-space-name>
: The name of the Space you created
โ๏ธ Thatโs it! Your app will deploy automatically.
๐ Method 2: Upload via SSH (Advanced)
SSH lets you push without typing a token each time, but setup is longer.
Step 1: Generate SSH Key (if you don't have one)
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
- Save it as
huggingFace_key
or just press Enter for default path - Youโll get two files:
huggingFace_key
andhuggingFace_key.pub
Step 2: Add the Public Key to Hugging Face
- Go to Settings โ SSH Keys
- Click โNew SSH Keyโ
- Paste the content of
huggingFace_key.pub
clip < huggingFace_key.pub # On Windows
cat huggingFace_key.pub # On Mac/Linux
- Give it a name like
laptop-ssh
Step 3: Configure SSH Remote
- Set your remote URL:
git remote set-url origin git@huggingface.co:spaces/your-username/your-space-name.git
- Push your code:
git add .
git commit -m "Initial SSH push"
git push
๐ง SSH Troubleshooting
-
If you see
ssh: connect to host huggingface.co port 22: Connection timed out
, your network may block port 22.- ๐ Try switching to HTTPS method above
- ๐ Try another network (e.g., mobile hotspot)
๐งช Sample Project Structure
Hereโs a simple app that converts temperature using Gradio:
mcp-temperature-converter/
โโโ app.py
โโโ requirements.txt
โโโ README.md
app.py
import gradio as gr
def convert(temp_f):
return (float(temp_f) - 32) * 5/9
gr.Interface(fn=convert, inputs="text", outputs="text", title="F to C Converter").launch()
requirements.txt
gradio
๐ Updating Your App
After making changes locally, just run:
git add .
git commit -m "Update app"
git push
Your Hugging Face Space will automatically redeploy with the latest code.
๐ You're Live!
You now have a public (or private) URL to share your deployed AI tool with others.
Top comments (0)