These scripts perform text and image redaction on PDFs using AI-powered text detection and PyMuPDF. It consists of two python scripts:
redact_text.py: Redacts sensitive text based on predefined specifications.redact_images.py: Redacts sensitive entities found in images within the PDF.
- Text Redaction: Detects and redacts text based on a customizable list of terms or phrases.
- Image Redaction: Extracts images, uses AI (GPT-4 Vision) to identify sensitive entities, and redacts the images.
Ensure you have the following installed:
- Python 3.8 or higher
- pip (Python package manager)
- Tesseract OCR: Required for redacting text from images and flat PDFs.
To insall the required packages, run:
./install.sh
If necessary, make the script executable before running:
chmod +x install.sh
Shroud requires Tesseract’s trained models (tessdata).
By default, the script is configured for macOS, using:
os.environ["TESSDATA_PREFIX"] = "/usr/local/share/tessdata"
os.environ["TESSERACT_CMD"] = "/usr/local/bin/tesseract"For Intel Mac users,
OR
os.environ["TESSDATA_PREFIX"] = "/opt/local/share/tessdata"
os.environ["TESSERACT_CMD"] = "/opt/local/bin/tesseract"for Apple Silicon Mac users.
If you are on Linux or Windows, update these values:
- Linux:
/usr/share/tesseract-ocr/5/tessdata - Windows:
C:\Program Files\Tesseract-OCR\tessdata
To manually override, set the environment variables before running the script:
export TESSDATA_PREFIX="/path/to/tessdata"
export TESSERACT_CMD="/path/to/tesseract"The scripts use a config.json file to store your OpenAI API key. To configure your key, create a file named config.json in the root directory with the following format:
{
"openai": {
"api_key": "openai-api-key"
}
}Run the shell script with the appropriate arguments:
For text-only redaction (default):
bash run.sh textFor text and image redaction:
bash run.sh text imageIf necessary, make the script executable before running:
chmod +x run.sh
Folder Structure After Running:
./input_pdfs/ # Original PDFs
./output_pdfs/ # Fully redacted PDFs
./partially_redacted_pdfs/ # Text-redacted PDFs (used for images)