Spaces:
Paused
Paused
π Deployment Guide for Hugging Face Spaces
This guide will walk you through deploying the Turnstile Solver API to Hugging Face Spaces.
Prerequisites
- A Hugging Face account (free): https://huggingface.co/join
- Git installed on your computer (optional, can use web interface)
Method 1: Web Interface (Easiest)
Step 1: Create a New Space
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Fill in the details:
- Space name:
turnstile-solver(or any name you prefer) - License: MIT
- Select the Space SDK: Choose Docker
- Space hardware: CPU basic (free tier)
- Visibility: Public or Private (your choice)
- Space name:
- Click "Create Space"
Step 2: Upload Files
- Once your Space is created, you'll see an empty repository
- Click "Files" tab
- Click "Add file" β "Upload files"
- Upload these files from the
turnstile-solver-hffolder:app.pyrequirements.txtDockerfileREADME.md.dockerignore
- Click "Commit changes to main"
Step 3: Wait for Build
- The Space will automatically start building the Docker container
- This takes about 5-10 minutes
- You can watch the build logs in the "Logs" tab
- Once complete, your API will be live!
Step 4: Test Your API
Your API will be available at:
https://huggingface.co/spaces/YOUR-USERNAME/turnstile-solver
Test it:
curl "https://YOUR-USERNAME-turnstile-solver.hf.space/turnstile?url=https://example.com&sitekey=0x4AAAAAAB6qwG1HcvybuFht"
Method 2: Git CLI (Advanced)
Step 1: Create Space on HF
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Choose Docker SDK
- Note your Space URL
Step 2: Clone and Push
# Clone your empty Space
git clone https://huggingface.co/spaces/YOUR-USERNAME/turnstile-solver
cd turnstile-solver
# Copy files from turnstile-solver-hf folder
cp ../turnstile-solver-hf/* .
# Add and commit
git add .
git commit -m "Initial deployment"
# Push to HF
git push
Step 3: Monitor Build
Watch the build process at:
https://huggingface.co/spaces/YOUR-USERNAME/turnstile-solver
Configuration Options
Change Port (Optional)
The default port is 7860. To change it, modify Dockerfile:
ENV PORT=8080
EXPOSE 8080
Enable GPU (Optional)
For faster processing, upgrade to GPU hardware:
- Go to Space Settings
- Change "Space hardware" to "GPU basic"
- Note: This requires a paid plan
Add Authentication (Optional)
To protect your API, add basic auth in app.py:
from quart import request
from functools import wraps
def require_auth(f):
@wraps(f)
async def decorated(*args, **kwargs):
auth = request.headers.get('Authorization')
if auth != 'Bearer YOUR_SECRET_TOKEN':
return jsonify({"error": "Unauthorized"}), 401
return await f(*args, **kwargs)
return decorated
@app.route('/turnstile')
@require_auth
async def process_turnstile():
# ... existing code
Troubleshooting
Build Fails
Error: "No space left on device"
- Solution: Reduce Docker image size by removing unnecessary dependencies
Error: "Chromium installation failed"
- Solution: Check Dockerfile has all required system dependencies
API Not Responding
Check Logs:
- Go to your Space
- Click "Logs" tab
- Look for errors
Common Issues:
- Port mismatch: Ensure PORT env variable matches EXPOSE in Dockerfile
- Memory limit: Free tier has 16GB RAM limit
- Timeout: Increase timeout in Space settings
Slow Performance
Solutions:
- Upgrade to GPU hardware
- Reduce concurrent tasks
- Optimize browser launch parameters
Monitoring
View Logs
# Real-time logs
https://huggingface.co/spaces/YOUR-USERNAME/turnstile-solver/logs
Health Check
curl https://YOUR-USERNAME-turnstile-solver.hf.space/health
Updating Your Space
Via Web Interface
- Go to your Space
- Click "Files"
- Click on file to edit
- Make changes
- Commit
Via Git
cd turnstile-solver
# Make changes to files
git add .
git commit -m "Update description"
git push
Cost Considerations
Free Tier
- CPU basic: Free
- 16GB RAM
- 50GB storage
- No GPU
Paid Tiers
- GPU basic: ~$0.60/hour
- GPU T4: ~$0.90/hour
- More RAM/storage available
Security Best Practices
- Don't commit secrets: Use HF Secrets for API keys
- Rate limiting: Implement rate limiting in production
- Authentication: Add auth for production use
- Monitoring: Set up alerts for unusual activity
- Updates: Keep dependencies updated
Support
- HF Spaces Docs: https://huggingface.co/docs/hub/spaces
- Community Forum: https://discuss.huggingface.co/
- Discord: https://discord.gg/hugging-face
Next Steps
- β Deploy your Space
- β Test the API
- β Share your Space URL
- β Monitor usage
- β Iterate and improve
Happy deploying! π