Overview
Hugging Face Spaces offers:- Free hosting: Permanent URLs for your demos
- No cold starts: Apps stay warm and responsive
- GPU support: Access to various GPU options
- Easy deployment: CLI or web-based upload
- Automatic updates: Sync with GitHub for CI/CD
- Secrets management: Secure environment variables
- Community: Discover and share demos
Quick start
Deploy your Gradio app in under 2 minutes:1
Create a Hugging Face account
Sign up for free at huggingface.co
2
Deploy from terminal
Run this command in your app directory:The CLI will:
- Ask for your Space name
- Upload all files (respecting
.gitignore) - Launch your app on Spaces
3
Access your app
Your app will be live at:
Deployment methods
Method 1: CLI deployment (recommended)
The fastest way to deploy:- Space name
- Whether to set up GitHub Actions (for auto-updates)
- Hardware tier (CPU or GPU)
Update an existing Space
Simply rungradio deploy again in the same directory:
Enable GitHub Actions
Automate deployments on everygit push:
Method 2: Web interface
Deploy via drag-and-drop:1
Create a new Space
Go to huggingface.co/new-space
2
Choose settings
- Pick a name
- Select “Gradio” as the SDK
- Choose hardware (CPU or GPU)
3
Upload files
Drag and drop your app folder, or clone via Git
Method 3: Git workflow
For version control and collaboration:App structure
A typical Gradio Space contains:Example app.py
Example requirements.txt
README.md metadata
Configure your Space with YAML frontmatter:Hardware options
CPU (free)
Default tier, suitable for:- Text processing
- Simple data analysis
- Lightweight models
- Educational demos
GPU (paid)
For compute-intensive tasks:Change hardware via UI
- Go to your Space settings
- Click “Hardware”
- Select new tier
- Click “Update hardware”
Change hardware via CLI
Sleep timeout
GPU Spaces automatically sleep after inactivity:Environment variables and secrets
Add secrets via UI
- Go to Space settings
- Click “Variables and secrets”
- Add name and value
- Click “Save”
Add secrets via CLI
Use secrets in code
Duplicate Spaces programmatically
Create private copies of Spaces for unlimited API usage:- No rate limits
- Guaranteed availability
- Custom hardware
- Private usage
Custom domains
Pro users can add custom domains:- Go to Space settings
- Click “Domains”
- Add your domain (e.g.,
demo.mycompany.com) - Update DNS records as shown
- Wait for verification
Persistent storage
Spaces are stateless by default. For persistent data:Use Hugging Face Datasets
Use Spaces persistent storage (Pro)
For Pro subscribers:Monitoring and logs
View logs
In your Space page:- Click “Logs” tab
- See real-time output
- Filter by level (info, error, etc.)
Access logs programmatically
Add custom logging
Private Spaces
Restrict access to your Space:Make Space private
- Go to Space settings
- Click “Visibility”
- Select “Private”
- Save
Access private Spaces
Best practices
1
Use .gitignore
Don’t upload unnecessary files:
2
Pin dependencies
Specify exact versions in
requirements.txt:3
Add examples
Help users get started:
4
Set up error handling
Gracefully handle failures:
5
Optimize for cold starts
Load models outside the function:
Troubleshooting
Space won’t start
- Check logs for errors
- Verify
requirements.txtdependencies - Ensure
app.pyruns locally - Check Python version compatibility
Out of memory
- Upgrade to higher RAM tier
- Reduce model size
- Use model quantization
- Clear unused variables
Slow performance
- Upgrade to GPU hardware
- Cache model outputs
- Optimize data preprocessing
- Use batch processing
Next steps
Docker deployment
Deploy Gradio apps with Docker
Sharing apps
Learn about authentication and embedding