OpenAI Privacy Filter: Building Scalable PII Detection Web Apps
OpenAI Privacy Filter: Building Scalable PII Detection Web Apps
OpenAI has released Privacy Filter, an open-source personally-identifiable information (PII) detector designed to identify and label sensitive text across eight distinct categories. The model is significant for its ability to process a 128k token context in a single forward pass, eliminating the need for text chunking and ensuring precise span offsets.
Privacy Filter Model Specifications
Privacy Filter is a 1.5B-parameter model with 50M active parameters, released under the Apache 2.0 license. It achieves state-of-the-art performance on the PII-Masking-300k benchmark.
Technical Capabilities
- Context Window: 128,000 tokens.
- PII Categories: The model detects eight categories:
private_person,private_address,private_email,private_phone,private_url,private_date,account_number, andsecret. - Efficiency: The model performs labeling in a single forward pass, which maintains the integrity of span boundaries and offsets over long documents.
Practical Implementations via gradio.Server
Hugging Face has demonstrated the model's utility by building three scalable web applications using gradio.Server. This framework allows developers to combine custom HTML/JS frontends with Gradio's backend capabilities, such as ZeroGPU allocation and request queueing.
1. Document Privacy Explorer
This application allows users to upload PDF or DOCX files to have PII spans highlighted in place.
- Technical Approach: The entire document is processed in one 128k-context pass. BIOES decoding is used to ensure clean span boundaries during long, ambiguous text runs.
- Infrastructure:
gr.Serverserves the reader view as a single HTML file and exposes the model via a queued@server.apiendpoint, allowing for concurrent uploads to be serialized and handled via ZeroGPU.
2. Image Anonymizer
This tool redacts PII from images and screenshots (e.g., Slack threads or receipts) by placing black bars over sensitive data.
- Technical Approach: The system uses Tesseract for OCR to generate per-word bounding boxes. The backend maps character offsets to these boxes and runs Privacy Filter over the reconstructed text. Detected spans are then converted into pixel rectangles for redaction.
- Infrastructure: A custom
<canvas>frontend handles the interactive elements—such as toggling, dragging, or manually drawing redaction bars—while the@server.apiendpoint provides the pixel coordinates.
3. SmartRedact Paste
This is a redaction-focused pastebin that generates two separate URLs: a public redacted version and a private reveal version.
- Technical Approach: Detected PII spans are replaced with
<CATEGORY>placeholders (e.g.,<PRIVATE_EMAIL>). The model's multilingual capabilities allow it to handle text in Spanish, French, Chinese, and Hindi without modification. - Infrastructure: Because
gr.Serveris built on FastAPI, the app utilizes both@server.apifor the model-heavy redaction process and plain@server.getroutes for the token-gated viewing pages.
Architectural Pattern for Scalable AI Apps
The integration of Privacy Filter across these apps follows a consistent architectural split between queued compute and static routing:
| Application | Queued Compute (@server.api) |
Plain FastAPI Routes |
|---|---|---|
| Document Privacy Explorer | Text extraction, PII detection, and statistics | Serving the custom reader HTML view |
| Image Anonymizer | OCR, PII detection, and pixel box mapping | Serving the canvas UI and examples |
| SmartRedact Paste | PII detection and redaction | Public and token-gated view pages |
By using @server.api, developers gain access to Gradio's queue and the @spaces.GPU composition on ZeroGPU, while plain FastAPI routes handle lightweight tasks like HTML delivery and dictionary lookups.