A FastAPI-based service for detecting and masking Personally Identifiable Information (PII) in text using the PII-Ranha model.
- PII Detection: Check if text contains any PII
- PII Masking: Mask detected PII with either aggregated or detailed redaction
- Health Check: Verify service status
- Token Chunking: Handles long texts by splitting into 256-token chunks
% curl -s -X POST "http://localhost:8001/check-pii" \
-H "Content-Type: application/json" \
-d '{"text":"Your text here, my name is Jean-Claude Dusse"}'
{
"detail": "PII detected in input"
}
(piiserver)
% curl -s -X POST "http://localhost:8001/check-pii" \
-H "Content-Type: application/json" \
-d '{"text":"Your text here, Lorem ipsum dolor sit amet, consectetur adipiscing elit"}'
{
"status": "OK",
"message": "No PII detected"
}
POST /check-pii
- Request body:
{"text": "your text here"}
- Returns: 200 if no PII detected, 400 if PII detected
POST /mask-pii
- Request body:
{"text": "your text here"}
- Optional query param:
aggregate_redaction=true|false
(default: true) - Returns: Original and masked text
GET /health
- Returns: Service status
- Install dependencies:
pip install fastapi uvicorn transformers torch
- Run the server:
python app.py
- The service will be available at
http://localhost:8000
Check for PII:
curl -X POST "http://localhost:8000/check-pii" -H "Content-Type: application/json" -d '{"text":"Your text here"}'
Mask PII:
curl -X POST "http://localhost:8000/mask-pii" -H "Content-Type: application/json" -d '{"text":"Your text here"}'
The service uses the PII-Ranha model from Hugging Face.
Author: Sébastien Campion
Sébastien Campion - sebastien.campion@foss4.eu
Note: This project is under active development. Please report any issues or feature requests through the issue tracker.
This project is licensed under the GNU Affero General Public License v3.0 - see the LICENSE file for details.