CoolFace
Apppublic

LukeFP/Physh_Classification

sourceHugging Faceapache-2.0updated 2d agoView on Hugging Face
0likes
DEPLOY.md67 linesDownload Raw Back to root
1# Deploying to LukeFP/Physh_Classification2 3The Space repo lives at `~/code/2026.7/Physh_Classification`.4 5## 1. Add the token secret6 7`google/embeddinggemma-300m` is gated. Accept the Gemma license while signed in,8create a **read** token, then on the Space page: Settings → *Variables and9secrets* → **New secret**, name `HF_TOKEN`, value the token. Without it the Space10boots fine but the first classification fails with a 401.11 12## 2. Hardware13 14On the free tier, Gradio Spaces run on **ZeroGPU**, which stops the container at15startup unless it finds at least one `@spaces.GPU` function — the16`No @spaces.GPU function detected during startup` error. `infer()` in `app.py`17carries that decorator, so ZeroGPU is satisfied.18 19Constraints ZeroGPU imposes, and how `app.py` meets them:20 21| Constraint | Handling |22|---|---|23| `import spaces` must precede `import torch` | It is the first import in `app.py` |24| Nothing may touch CUDA outside a `@GPU` function | Models load with `device="cpu"`; `.to(device)` happens inside `infer()` |25| Return values cross a process boundary | `infer()` returns plain `list[float]`, never CUDA tensors |26| One GPU allocation per call, with a duration budget | `@GPU(duration=60)`; the model is already resident, so only the encode runs |27 28CPU basic (a PRO perk) also works with this code unchanged — `spaces` is an29optional import and the device is chosen from `torch.cuda.is_available()`.30 31## 3. Push32 33```bash34cd ~/code/2026.7/Physh_Classification35git push origin main36```37 38The build takes a few minutes, most of it `pip install torch`.39 40## 4. First checks41 42- **Predictions look like noise, or nothing clears the threshold.** Almost43  certainly the embedding prompt. Open *Advanced* and try the other two formats;44  the one matching your training pipeline gives confident, coherent labels.45  Once you know which, set `DEFAULT_PROMPT` at the top of `app.py`.46  (`~/code/2026/embedding_title_abstract` likely has the answer.)47- **Error mentioning a gated repo, or a 401.** `HF_TOKEN` is missing, wrong, or48  the account behind it hasn't accepted the Gemma license.49- **First request is slow, later ones fast.** Expected — EmbeddingGemma loads50  lazily on first use so the Space boots quickly. Cached after that.51 52## Updating later53 54Retraining only needs a push to55[`LukeFP/physh_topic_supervised_classifier`](https://huggingface.co/LukeFP/physh_topic_supervised_classifier);56the Space picks up new weights on its next restart. Only change this repo if the57*filenames* change — they're the constants at the top of `app.py`.58 59## Local smoke test60 61Runs the real checkpoints through the full chain with a stubbed embedder, so it62needs no token and no model download:63 64```bash65PHYSH_WEIGHTS_DIR=~/code/2026.7/physh_topic_supervised_classifier python test_local.py66```67