remove.bg / DEPLOY.md
srayuth
CUDA base image, pre-cache models, fix double loading
7bebf4c
|
raw
history blame
2.7 kB

Deploy to HuggingFace Spaces

Quick Push

cd /Users/srayuth/git/bluweo/service/remove-background-hf

# Make changes, then:
git add .
git commit -m "Your message"
git push

Setup from Scratch

1. Clone HF Space

git clone https://huggingface.co/spaces/Pheerakarn/remove.bg
cd remove.bg

2. With Access Token (if needed)

# Get token from: https://huggingface.co/settings/tokens
git remote set-url origin https://Pheerakarn:YOUR_TOKEN@huggingface.co/spaces/Pheerakarn/remove.bg

3. Copy Files from Main Project

# From main project
cp Dockerfile.hf ../remove-background-hf/Dockerfile
cp requirements-hf.txt ../remove-background-hf/requirements.txt
cp .env.hf ../remove-background-hf/.env
cp -r config transparent scalar ../remove-background-hf/
cp manage.py gunicorn.conf.py yolov8n.pt ../remove-background-hf/

4. Push

git add .
git commit -m "Update"
git push

Hardware Options

Hardware Specs VRAM Speed Cost
CPU basic 2 vCPU Β· 16 GB RAM - ~30-60s Free
CPU upgrade 8 vCPU Β· 32 GB RAM - ~15-30s $0.03/hr
T4 small 4 vCPU Β· 15 GB RAM 16GB ~2-5s $0.40/hr
T4 medium 8 vCPU Β· 30 GB RAM 16GB ~2-5s $0.60/hr
L4 8 vCPU Β· 30 GB RAM 24GB ~1-3s $0.80/hr
A10G small 4 vCPU Β· 15 GB RAM 24GB ~1-3s $1.00/hr
A10G large 12 vCPU Β· 46 GB RAM 24GB ~1-3s $1.50/hr
L40S 8 vCPU Β· 62 GB RAM 48GB ~0.5-2s $1.80/hr
A100 large 12 vCPU Β· 142 GB RAM 80GB ~0.5-1s $2.50/hr

Enable GPU: Settings β†’ Hardware β†’ Select GPU β†’ Save

Files Structure

remove-background-hf/
β”œβ”€β”€ Dockerfile          # HF Docker config
β”œβ”€β”€ requirements.txt    # Python deps (GPU)
β”œβ”€β”€ .env               # Environment vars
β”œβ”€β”€ README.md          # HF metadata
β”œβ”€β”€ manage.py          # Django entry
β”œβ”€β”€ gunicorn.conf.py   # Server config
β”œβ”€β”€ yolov8n.pt         # YOLO model
β”œβ”€β”€ config/            # Django settings
β”œβ”€β”€ transparent/       # API app
└── scalar/            # API docs

Troubleshooting

OMP_NUM_THREADS Error

Fixed in transparent/apps.py - converts HF's "3500m" to "4"

GPU Not Detected

  • Check hardware is enabled in Settings
  • Wait for Space to fully restart after hardware change

Build Failed

  • Check logs in HF Space
  • Verify Dockerfile syntax
  • Check requirements.txt versions

API Endpoints

  • Docs: https://pheerakarn-remove-bg.hf.space/api/docs/
  • Health: https://pheerakarn-remove-bg.hf.space/api/transparent/health/
  • Generate: POST /api/transparent/generate-styles/