--- title: Sentedel EDI-PHI API emoji: 🔒 colorFrom: blue colorTo: gray sdk: docker app_port: 7860 pinned: false models: - rrsanjabi/sentedel-edi-phi-v1 short_description: Demo API for PHI detection on healthcare EDI. tags: - token-classification - phi - edi - fastapi --- # Sentedel EDI-PHI API (demo) Public **FastAPI** inference server for [rrsanjabi/sentedel-edi-phi-v1](https://huggingface.co/rrsanjabi/sentedel-edi-phi-v1)—token-classification PHI detection and simple `[REDACTED]` masking on X12/EDI-style text. **Live app:** [https://rrsanjabi-sentedel-edi-phi-api.hf.space](https://rrsanjabi-sentedel-edi-phi-api.hf.space) **Website demo:** [https://sentedel.com/demo-server.html](https://sentedel.com/demo-server.html) This Space is a **research/demo endpoint**, not a production HIPAA-compliant service. Do not submit real patient or member data. --- ## What it does 1. Downloads model weights from `rrsanjabi/sentedel-edi-phi-v1` on startup (if not already cached). 2. Loads a Hugging Face `token-classification` pipeline on **CPU** (unless GPU is available and configured). 3. Exposes a small JSON API for health checks and redaction. --- ## API ### `GET /api/health` **Example** ```bash curl -s "https://rrsanjabi-sentedel-edi-phi-api.hf.space/api/health" ``` **Response** ```json { "ok": true, "model_dir": "/app/models/sentedel-edi-phi-v1", "device": "cpu", "error": null } ``` - `ok: false` — model weights missing or failed to load; see `error`. --- ### `POST /api/redact` Detect PHI spans and return redacted text. **Request** ```http POST /api/redact Content-Type: application/json { "text": "" } ``` **Response** ```json { "redacted": "...", "entities": [ { "label": "private_person", "start": 120, "end": 135, "score": 0.98 } ], "latency_ms": 842 } ``` **Errors** | Status | Meaning | | ------ | ------------------------------ | | `503` | Model not loaded | | `422` | Invalid body (e.g. empty text) | **Example** ```bash curl -s -X POST "https://rrsanjabi-sentedel-edi-phi-api.hf.space/api/redact" \ -H "Content-Type: application/json" \ -d '{"text":"NM1*IL*1*JOHNSON*MICHAEL*T***MI*XKW123456789~"}' ``` --- ## CORS Cross-origin requests are allowed (`*`) so the static site at sentedel.com can call this API from the browser. Treat that as a **demo convenience**, not a security model for sensitive data. --- ## Configuration | Variable | Default | Description | | ----------------- | ------------------------------- | ----------------------------------- | | `MODEL_ID` | `rrsanjabi/sentedel-edi-phi-v1` | Hugging Face model repo to download | | `SENTEDEL_DEVICE` | `auto` | `cpu`, `cuda`, or `auto` | To ship **v2**, upload a new model repo and set `MODEL_ID` (or update `start.sh`) then rebuild the Space. --- ## Performance notes - **CPU Basic** hardware—first request after sleep can be slow (cold start + model load). - Large inputs increase latency; keep demo payloads reasonable. - For production, run your own deployment with GPU, autoscaling, auth, and logging. --- ## Stack - [FastAPI](https://fastapi.tiangolo.com/) + [Uvicorn](https://www.uvicorn.org/) - [PyTorch](https://pytorch.org/) + [Transformers](https://github.com/huggingface/transformers) (`openai_privacy_filter`) - [huggingface_hub](https://huggingface.co/docs/huggingface_hub) for `snapshot_download` Source layout mirrors the [Sentedel website](https://github.com/) repo: `server/app.py`, `start.sh`, `Dockerfile`. --- ## Disclaimer - Demo only—**no real PHI**. - Outputs may include false positives/negatives; evaluate on your data before any operational use. - Not affiliated with or endorsed by OpenAI; fine-tuned from `openai/privacy-filter` under Apache 2.0. ## Links - Model card: [https://huggingface.co/rrsanjabi/sentedel-edi-phi-v1](https://huggingface.co/rrsanjabi/sentedel-edi-phi-v1) - Blog / benchmark: [https://sentedel.com/sentedel_blog_post.html](https://sentedel.com/sentedel_blog_post.html)