Chaeyoon Claude Opus 4.8 commited on
Commit
fe2d018
·
1 Parent(s): b7c4eb2

Add Hugging Face Spaces (Docker SDK) deploy config for the live demo

Browse files

- Dockerfile runs the Streamlit app on port 8501 (HF create API only accepts
gradio|docker|static, so Streamlit is served via Docker)
- README.md front-matter: sdk: docker, app_port: 8501
- en_core_web_lg model wheel in requirements.txt (installs during image build)
- DEPLOY_HF_SPACES.md with corrected hf-CLI + Docker steps

Deploy branch only — push to the Space's main, don't merge into main.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (4) hide show
  1. DEPLOY_HF_SPACES.md +44 -0
  2. Dockerfile +24 -0
  3. README.md +12 -0
  4. requirements.txt +4 -0
DEPLOY_HF_SPACES.md ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deploy the live demo on Hugging Face Spaces
2
+
3
+ This branch (`feat/hf-spaces-demo`) is the deploy branch. HF's create API only accepts
4
+ `gradio | docker | static` as the SDK, so the Streamlit app runs as a **Docker Space**. It adds:
5
+
6
+ 1. **`Dockerfile`** — runs `streamlit run app/streamlit_app.py` on port 8501.
7
+ 2. **`README.md` front-matter** — `sdk: docker`, `app_port: 8501`.
8
+ 3. **The spaCy model in `requirements.txt`** — `en_core_web_lg` installs during the image build.
9
+
10
+ Everything else (the `noteguard/` package, `app/streamlit_app.py`) already works as-is. The Space
11
+ downloads the NHS dataset from Hugging Face at first run; if that fails it falls back to paste-only mode.
12
+
13
+ ## One-time deploy
14
+
15
+ ```bash
16
+ # 1) Log in (needs a HF token with WRITE scope: https://huggingface.co/settings/tokens)
17
+ hf auth login
18
+
19
+ # 2) Create the Space (Docker SDK, free cpu-basic). Or make it at https://huggingface.co/new-space
20
+ hf repos create <HF_USERNAME>/noteguard --repo-type space --space-sdk docker
21
+
22
+ # 3) Push THIS branch to the Space's main branch
23
+ git remote add space https://huggingface.co/spaces/<HF_USERNAME>/noteguard
24
+ git push space feat/hf-spaces-demo:main
25
+ ```
26
+
27
+ > Uses the `hf` CLI from `huggingface_hub` >= 1.0 (the old `huggingface-cli` still works as a
28
+ > deprecated alias). `hf auth login` will prompt for your write token.
29
+
30
+ The Space builds (installs Presidio + spaCy + `en_core_web_lg`, ~3–5 min the first time), then serves
31
+ the app. Your **Live Demo Link** is:
32
+
33
+ ```
34
+ https://huggingface.co/spaces/<HF_USERNAME>/noteguard
35
+ ```
36
+
37
+ Paste that into the submission form's *Live Demo Link* field.
38
+
39
+ ## Notes
40
+ - **Resource-constrained?** If the build is slow or the Space OOMs, swap the model line in
41
+ `requirements.txt` to `en_core_web_sm-3.8.0` (faster, lighter; slightly lower name recall).
42
+ - **Updating the demo:** push again with `git push space feat/hf-spaces-demo:main` (the Space rebuilds).
43
+ - **Keep this branch deploy-only** — don't merge the README front-matter into `main` (it's only for the
44
+ Space card).
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Spaces (Docker SDK) — serves the NoteGuard Streamlit app.
2
+ # HF's create API only accepts gradio|docker|static, so Streamlit runs via Docker.
3
+ FROM python:3.11-slim
4
+
5
+ # Non-root user (HF Spaces convention) → gives a writable HOME for model/dataset caches.
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV HOME=/home/user \
9
+ PATH=/home/user/.local/bin:$PATH \
10
+ PYTHONUNBUFFERED=1
11
+
12
+ WORKDIR $HOME/app
13
+
14
+ # Install deps first for layer caching. requirements.txt pins the spaCy model wheel.
15
+ COPY --chown=user requirements.txt .
16
+ RUN pip install --no-cache-dir --upgrade pip && \
17
+ pip install --no-cache-dir -r requirements.txt
18
+
19
+ # App code (data/ and .venv are gitignored, so the app downloads the dataset at runtime).
20
+ COPY --chown=user . .
21
+
22
+ EXPOSE 8501
23
+ CMD ["streamlit", "run", "app/streamlit_app.py", \
24
+ "--server.port=8501", "--server.address=0.0.0.0", "--server.headless=true"]
README.md CHANGED
@@ -1,3 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  # 🛡️ NoteGuard
2
 
3
  **Automatic PII sanitisation for NHS clinical notes — clean data in, no identifiers out.**
 
1
+ ---
2
+ title: NoteGuard — NHS De-Identification Gate
3
+ emoji: 🛡️
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ app_port: 8501
8
+ pinned: false
9
+ license: mit
10
+ short_description: Sanitise-at-source PII removal for NHS notes
11
+ ---
12
+
13
  # 🛡️ NoteGuard
14
 
15
  **Automatic PII sanitisation for NHS clinical notes — clean data in, no identifiers out.**
requirements.txt CHANGED
@@ -7,3 +7,7 @@ huggingface_hub
7
  pandas
8
  streamlit
9
  pytest
 
 
 
 
 
7
  pandas
8
  streamlit
9
  pytest
10
+
11
+ # spaCy model (installed at build time on Hugging Face Spaces; matches detect.py default).
12
+ # Swap to en_core_web_sm-3.8.0 for a faster/lighter build if the Space is resource-constrained.
13
+ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.8.0/en_core_web_lg-3.8.0-py3-none-any.whl