Commit ·
1035f0d
1
Parent(s): 72de53b
docs(card-ocr): operator runbook for the Hugging Face Space deploy
Browse filesThe Dockerfile + Spaces frontmatter + hf git remote landed in eac3468,
but the actual deploy procedure (HF account, repo secret, hf-remote
auth, subtree push, smoke tests) was carried in head only. Write it
down so it survives.
Also retarget the .env.example OCR block at the HF Space URL and bump
the example timeout to 30s -- the free CPU tier sleeps after idle and
first-call cold-load is 30-60s.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
111 unmodified lines112113114111 unmodified lines# Real PaddleOCR integration (downloads models, takes ~30s):CARD_OCR_INTEGRATION=1 pytest -v```111 unmodified lines112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202111 unmodified lines# Real PaddleOCR integration (downloads models, takes ~30s):CARD_OCR_INTEGRATION=1 pytest -v```## Operator runbookEnd-to-end deploy of this sidecar to the FoodNode Hugging Face Space(`https://huggingface.co/spaces/foodnode/card-ocr`). The Dockerfile,README frontmatter, and `hf` git remote are already in place -- theseare the manual steps that the repo can't automate for you.### One-time setup1. **Create the Space** at <https://huggingface.co/new-space> withowner `foodnode`, name `card-ocr`, **SDK: Docker**, hardware**CPU basic (free)**. (If the Space already exists, skip.)2. **Set the shared secret** in the Space's*Settings → Repository secrets*:```OCR_INTERNAL_API_KEY = <openssl rand -hex 32>```The same value goes into Django's env (`OCR_INTERNAL_API_KEY` Flysecret). Without it the sidecar refuses every request with`503 ocr-key-not-configured`.3. **Authenticate the local `hf` git remote.** Anonymous fetchesagainst an HF Space repo error with`fatal: expected 'acknowledgments'` -- that is HF rejecting theunauthenticated git protocol. Two options:```bash# Option A: huggingface_hub CLI (preferred -- one login lasts# across every HF command)pip install huggingface_hubhuggingface-cli login # paste a write-scoped token from# https://huggingface.co/settings/tokens# Option B: bake the token into the remote URLgit remote set-url hf https://USER:HF_TOKEN@huggingface.co/spaces/foodnode/card-ocr```### Every deploy```bash# Push only this subdirectory as the root of the HF Space repogit subtree push --prefix=backend/services/card_ocr hf main```The first push triggers a ~5–10 min HF build (downloads PaddleOCRweights into the image). Subsequent pushes are layered, so only thefiles that actually changed re-upload.### Smoke tests```bash# Liveness (always cheap, no auth)curl https://foodnode-card-ocr.hf.space/health# → {"ok": true}# Auth check (no body needed)curl -i -H "X-Internal-API-Key: $OCR_INTERNAL_API_KEY" \https://foodnode-card-ocr.hf.space/health# End-to-end extract -- replace the JPGs with real card photoscurl -H "X-Internal-API-Key: $OCR_INTERNAL_API_KEY" \-F front_image=@samples/card_front.jpg \-F back_image=@samples/card_back.jpg \https://foodnode-card-ocr.hf.space/extract```The first call after the Space has been idle for a while will take30–60 s to return -- that's PaddleOCR loading its model into a coldcontainer. Bump Django's `OCR_REQUEST_TIMEOUT_SECONDS` to ≥ 30 on thefree tier so the `/api/onboarding/sessions/<id>/extract-card/`endpoint doesn't time out before the sidecar wakes.### Wire Django to the SpaceSet on the Django host (Fly secrets, etc.):```OCR_SERVICE_URL=https://foodnode-card-ocr.hf.spaceOCR_INTERNAL_API_KEY=<same value as the HF Space secret>OCR_REQUEST_TIMEOUT_SECONDS=30CARD_OCR_ENABLED=true```No code change is needed -- `backend/onboarding/providers/real_card_ocr.py`already POSTs to `${OCR_SERVICE_URL}/extract` with the`X-Internal-API-Key` header.
README.md+88