Spaces:
Running on Zero
Running on Zero
Maxim Kruglikov Claude Opus 4.7 (1M context) commited on
Commit ·
836e4c0
1
Parent(s): 711c874
Document deploy and log-observation workflow
Browse filesCaptures the hf-upload / git-push publish paths, the
HfApi.request_space_hardware call for switching flavors (frontmatter is
not a valid path), and the SSE build/run log endpoints with the
~/.cache/huggingface/token auth pattern.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CLAUDE.md
CHANGED
|
@@ -107,6 +107,78 @@ or needs unit tests without Gradio. Not needed today.
|
|
| 107 |
- **Verdict styling uses emoji prefix, not inline HTML `<span>`.** `gr.Markdown`'s HTML handling
|
| 108 |
varies across Gradio versions; emoji is reliably rendered.
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
## Working with the Hugging Face Hub
|
| 111 |
|
| 112 |
- Model weights (`megastyle_encoder.pth`) should be pulled at runtime via `huggingface_hub.hf_hub_download`,
|
|
|
|
| 107 |
- **Verdict styling uses emoji prefix, not inline HTML `<span>`.** `gr.Markdown`'s HTML handling
|
| 108 |
varies across Gradio versions; emoji is reliably rendered.
|
| 109 |
|
| 110 |
+
## Deploying and observing the Space
|
| 111 |
+
|
| 112 |
+
The live Space is at **`olfronar/megastyle-comparison`**
|
| 113 |
+
(https://huggingface.co/spaces/olfronar/megastyle-comparison). Local working copy is git-backed
|
| 114 |
+
with `origin` pointing at the Space's git URL — normal `git push origin main` triggers a rebuild.
|
| 115 |
+
|
| 116 |
+
### Publish a change
|
| 117 |
+
|
| 118 |
+
```bash
|
| 119 |
+
git add <files> && git commit -m "..." && git push origin main
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
For one-off blob pushes without a git clone:
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
hf upload olfronar/megastyle-comparison . --repo-type space --commit-message "..."
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
### Set hardware (ZeroGPU, etc.)
|
| 129 |
+
|
| 130 |
+
Hardware is *not* set via README frontmatter. Use `HfApi.request_space_hardware`:
|
| 131 |
+
|
| 132 |
+
```python
|
| 133 |
+
from huggingface_hub import HfApi
|
| 134 |
+
HfApi().request_space_hardware("olfronar/megastyle-comparison", hardware="zero-a10g")
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
Valid flavors include `cpu-basic`, `cpu-upgrade`, `t4-small`, `a10g-small`, `a10g-large`,
|
| 138 |
+
`a100-large`, and `zero-a10g` (the legacy name still used for the ZeroGPU pool, which is
|
| 139 |
+
currently backed by H200 hardware). You can also toggle via the Space's *Settings → Hardware*
|
| 140 |
+
page; both paths write to the same field.
|
| 141 |
+
|
| 142 |
+
### Observe build and run logs
|
| 143 |
+
|
| 144 |
+
HF exposes Server-Sent-Events streams for both phases. They require the user's HF token (read
|
| 145 |
+
it from `~/.cache/huggingface/token` after `hf auth login`). Capped-timeout curl works for
|
| 146 |
+
point-in-time snapshots:
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
# Build phase (docker layers, pip install)
|
| 150 |
+
curl -s --max-time 20 \
|
| 151 |
+
-H "Authorization: Bearer $(cat ~/.cache/huggingface/token)" \
|
| 152 |
+
"https://huggingface.co/api/spaces/olfronar/megastyle-comparison/logs/build" | tail -80
|
| 153 |
+
|
| 154 |
+
# Run phase (Python stdout/stderr, Gradio startup)
|
| 155 |
+
curl -s --max-time 20 \
|
| 156 |
+
-H "Authorization: Bearer $(cat ~/.cache/huggingface/token)" \
|
| 157 |
+
"https://huggingface.co/api/spaces/olfronar/megastyle-comparison/logs/run" | tail -80
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
Each event line is JSON with `data` and `timestamp` fields. Because it's SSE, the stream is
|
| 161 |
+
long-lived — always use `--max-time` to bound it.
|
| 162 |
+
|
| 163 |
+
### Check high-level state
|
| 164 |
+
|
| 165 |
+
```bash
|
| 166 |
+
curl -s "https://huggingface.co/api/spaces/olfronar/megastyle-comparison" | \
|
| 167 |
+
python3 -c "import sys, json; d=json.load(sys.stdin); r=d.get('runtime',{}); \
|
| 168 |
+
print('stage:', r.get('stage'), 'hardware:', r.get('hardware'), 'sha:', d.get('sha','?')[:7])"
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
`stage` values: `BUILDING` → `RUNNING` (healthy) or `RUNTIME_ERROR` / `BUILD_FAILED` (check logs).
|
| 172 |
+
|
| 173 |
+
### Common fix cycles
|
| 174 |
+
|
| 175 |
+
- **Runtime import / missing dep**: edit `requirements.txt` or the affected import, commit, push,
|
| 176 |
+
stream the run logs until `RUNNING`. Most fixes don't need a full rebuild — layer caching makes
|
| 177 |
+
re-pushes with unchanged deps very fast.
|
| 178 |
+
- **Hardware change**: one `HfApi().request_space_hardware(...)` call — no push, no rebuild.
|
| 179 |
+
- **Stuck build**: use the *Settings → Factory Reboot* UI as a last resort; our Dockerfile is the
|
| 180 |
+
HF default so factory-reboot is safe.
|
| 181 |
+
|
| 182 |
## Working with the Hugging Face Hub
|
| 183 |
|
| 184 |
- Model weights (`megastyle_encoder.pth`) should be pulled at runtime via `huggingface_hub.hf_hub_download`,
|