File size: 3,974 Bytes
0fd1762 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | # Deploying the PhysioLead Space to Hugging Face (git / Option B)
Step-by-step for pushing this demo to a Hugging Face Space using git.
---
## 0. Prerequisites
**Files you need in this folder before pushing (6 total):**
| File | Where it comes from |
|------|---------------------|
| `app.py` | this repo |
| `requirements.txt` | this repo |
| `README.md` | this repo (has the HF Space frontmatter β keep it) |
| `export_for_space.py` | this repo (optional; documentation only) |
| `physiolead_model.pt` | **run `export_for_space.py` in Kaggle**, download from Output tab |
| `physiolead_examples.npz` | same Kaggle run, same Output tab |
If you don't have the last two, run the export cell in your Kaggle notebook first
(after `model`, `ROOT`, `meta` exist). They save to `/kaggle/working/` β download
them from Kaggle's right-hand **Output** panel.
**An HF write token:**
1. huggingface.co β your avatar β **Settings** β **Access Tokens**
2. **New token** β Type: **Write** β copy it (used as your git password below).
---
## 1. Create the Space (once)
Either on the website β **New Space** β name `physiolead-ecg`, SDK **Gradio**,
license MIT β or from the CLI:
```bash
pip install huggingface_hub
huggingface-cli login # paste your write token
huggingface-cli repo create physiolead-ecg --type space --space_sdk gradio
```
Replace `YOUR_USERNAME` below with your HF username throughout.
---
## 2. Clone, add files, push
```bash
# clone the (empty) Space repo
git clone https://huggingface.co/spaces/YOUR_USERNAME/physiolead-ecg
cd physiolead-ecg
# copy your 6 files into this folder (adjust paths to where you downloaded them)
cp /path/to/app.py .
cp /path/to/requirements.txt .
cp /path/to/README.md .
cp /path/to/export_for_space.py .
cp /path/to/physiolead_model.pt .
cp /path/to/physiolead_examples.npz .
# stage and commit
git add app.py requirements.txt README.md export_for_space.py \
physiolead_model.pt physiolead_examples.npz
git commit -m "PhysioLead reduced-lead ECG reconstruction demo"
# push (username = your HF username, password = your WRITE token)
git push
```
The Space rebuilds automatically. Watch the **build logs** on the Space page.
---
## 3. Large-file note (only if the push is rejected)
`physiolead_model.pt` is small (a few MB) and pushes fine over plain git. But HF
Spaces track `*.pt` with **git-lfs** by default. If the push complains about file
size or LFS:
```bash
git lfs install
git lfs track "*.pt" "*.npz"
git add .gitattributes
git add physiolead_model.pt physiolead_examples.npz
git commit -m "track model + examples with LFS"
git push
```
---
## 4. Verify
Open `https://huggingface.co/spaces/YOUR_USERNAME/physiolead-ecg`.
- **Build succeeds, app loads** β pick the Normal example β you should see the
12-lead plot and mean precordial QRS-r β 0.97.
- **`load_state_dict` error in the logs** β the model classes in `app.py` don't
match your trained model's dimensions. Fix the class definitions in `app.py` to
match, commit, push again.
- **"examples all look the same"** β your `physiolead_examples.npz` has duplicate
beats; re-run the (fixed) `export_for_space.py` in Kaggle and re-push just that
file.
---
## 5. Updating later
To push a change (e.g. an edited `app.py`):
```bash
# in the physiolead-ecg folder
git add app.py
git commit -m "update app"
git push
```
The Space rebuilds on every push.
---
## Common issues
- **`Authentication failed`** β use your **write token** as the password, not your
account password. Username is your HF username.
- **`remote: Password authentication ... deprecated`** β same fix: token, not
password.
- **Build stuck / red status** β open the logs; a missing package goes in
`requirements.txt`, a code error shows a traceback there.
- **Wrong SDK** β the `README.md` frontmatter must say `sdk: gradio`; if you
created the Space as Static or Streamlit, delete and recreate as Gradio. |