doc-redaction 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. doc_redaction-2.2.0/MANIFEST.in +3 -0
  2. doc_redaction-2.2.0/PKG-INFO +394 -0
  3. doc_redaction-2.2.0/README.md +331 -0
  4. doc_redaction-2.2.0/README_PYPI.md +320 -0
  5. doc_redaction-2.2.0/agent_routes.py +1020 -0
  6. doc_redaction-2.2.0/app.py +10418 -0
  7. doc_redaction-2.2.0/cli_redact.py +2658 -0
  8. doc_redaction-2.2.0/doc_redaction/__init__.py +27 -0
  9. doc_redaction-2.2.0/doc_redaction/api.py +41 -0
  10. doc_redaction-2.2.0/doc_redaction/cli_api.py +359 -0
  11. doc_redaction-2.2.0/doc_redaction/cli_redact.py +26 -0
  12. doc_redaction-2.2.0/doc_redaction/data_anonymise.py +9 -0
  13. doc_redaction-2.2.0/doc_redaction/file_conversion.py +14 -0
  14. doc_redaction-2.2.0/doc_redaction/file_redaction.py +16 -0
  15. doc_redaction-2.2.0/doc_redaction/find_duplicate_pages.py +12 -0
  16. doc_redaction-2.2.0/doc_redaction/find_duplicate_tabular.py +9 -0
  17. doc_redaction-2.2.0/doc_redaction/gradio_app.py +23 -0
  18. doc_redaction-2.2.0/doc_redaction/helper_functions.py +9 -0
  19. doc_redaction-2.2.0/doc_redaction/install_deps.py +389 -0
  20. doc_redaction-2.2.0/doc_redaction/lambda_entrypoint.py +17 -0
  21. doc_redaction-2.2.0/doc_redaction/redaction_review.py +21 -0
  22. doc_redaction-2.2.0/doc_redaction/summaries.py +9 -0
  23. doc_redaction-2.2.0/doc_redaction.egg-info/PKG-INFO +394 -0
  24. doc_redaction-2.2.0/doc_redaction.egg-info/SOURCES.txt +85 -0
  25. doc_redaction-2.2.0/doc_redaction.egg-info/dependency_links.txt +1 -0
  26. doc_redaction-2.2.0/doc_redaction.egg-info/entry_points.txt +4 -0
  27. doc_redaction-2.2.0/doc_redaction.egg-info/requires.txt +56 -0
  28. doc_redaction-2.2.0/doc_redaction.egg-info/top_level.txt +9 -0
  29. doc_redaction-2.2.0/favicon.png +0 -0
  30. doc_redaction-2.2.0/intros/long_intro.txt +9 -0
  31. doc_redaction-2.2.0/intros/short_intro.txt +7 -0
  32. doc_redaction-2.2.0/intros/short_intro_responsible.txt +7 -0
  33. doc_redaction-2.2.0/lambda_entrypoint.py +803 -0
  34. doc_redaction-2.2.0/load_dynamo_logs.py +278 -0
  35. doc_redaction-2.2.0/load_s3_logs.py +187 -0
  36. doc_redaction-2.2.0/mcp_doc_redaction/__init__.py +1 -0
  37. doc_redaction-2.2.0/mcp_doc_redaction/artifact_bundle.py +88 -0
  38. doc_redaction-2.2.0/mcp_doc_redaction/gradio_transport.py +294 -0
  39. doc_redaction-2.2.0/mcp_doc_redaction/schemas.py +72 -0
  40. doc_redaction-2.2.0/mcp_doc_redaction/server.py +299 -0
  41. doc_redaction-2.2.0/pyproject.toml +187 -0
  42. doc_redaction-2.2.0/setup.cfg +4 -0
  43. doc_redaction-2.2.0/test/test_agent_apply_review_redactions.py +99 -0
  44. doc_redaction-2.2.0/test/test_annotation_color_parsing.py +49 -0
  45. doc_redaction-2.2.0/test/test_cli_smoke.py +79 -0
  46. doc_redaction-2.2.0/test/test_gradio_doc_redact_simple.py +54 -0
  47. doc_redaction-2.2.0/test/test_gradio_summarise_simple.py +28 -0
  48. doc_redaction-2.2.0/test/test_gradio_transport_sse.py +63 -0
  49. doc_redaction-2.2.0/test/test_gradio_upload_staging.py +44 -0
  50. doc_redaction-2.2.0/test/test_gui_only.py +223 -0
  51. doc_redaction-2.2.0/test/test_mcp_doc_redaction_bundle.py +19 -0
  52. doc_redaction-2.2.0/test/test_mcp_doc_redaction_extract_paths.py +23 -0
  53. doc_redaction-2.2.0/test/test_package_api_smoke.py +168 -0
  54. doc_redaction-2.2.0/test/test_placeholder_bbox_scaling.py +118 -0
  55. doc_redaction-2.2.0/test/test_redaction_overlay_export.py +169 -0
  56. doc_redaction-2.2.0/test/test_redaction_types.py +83 -0
  57. doc_redaction-2.2.0/test/test_review_ocr_visualisation_export.py +114 -0
  58. doc_redaction-2.2.0/tools/__init__.py +11 -0
  59. doc_redaction-2.2.0/tools/apply_hf_zero_gpu_readme_frontmatter.py +48 -0
  60. doc_redaction-2.2.0/tools/auth.py +88 -0
  61. doc_redaction-2.2.0/tools/aws_functions.py +461 -0
  62. doc_redaction-2.2.0/tools/aws_textract.py +1271 -0
  63. doc_redaction-2.2.0/tools/cli_usage_logger.py +337 -0
  64. doc_redaction-2.2.0/tools/config.py +2662 -0
  65. doc_redaction-2.2.0/tools/custom_csvlogger.py +335 -0
  66. doc_redaction-2.2.0/tools/custom_image_analyser_engine.py +12882 -0
  67. doc_redaction-2.2.0/tools/data_anonymise.py +1938 -0
  68. doc_redaction-2.2.0/tools/file_conversion.py +3919 -0
  69. doc_redaction-2.2.0/tools/file_redaction.py +13087 -0
  70. doc_redaction-2.2.0/tools/find_duplicate_pages.py +2190 -0
  71. doc_redaction-2.2.0/tools/find_duplicate_tabular.py +742 -0
  72. doc_redaction-2.2.0/tools/helper_functions.py +2125 -0
  73. doc_redaction-2.2.0/tools/llm_entity_detection.py +1167 -0
  74. doc_redaction-2.2.0/tools/llm_entity_detection_prompts.py +102 -0
  75. doc_redaction-2.2.0/tools/llm_funcs.py +2119 -0
  76. doc_redaction-2.2.0/tools/load_spacy_model_custom_recognisers.py +974 -0
  77. doc_redaction-2.2.0/tools/presidio_analyzer_custom.py +142 -0
  78. doc_redaction-2.2.0/tools/quickstart.py +934 -0
  79. doc_redaction-2.2.0/tools/redaction_review.py +5274 -0
  80. doc_redaction-2.2.0/tools/redaction_types.py +137 -0
  81. doc_redaction-2.2.0/tools/run_vlm.py +1363 -0
  82. doc_redaction-2.2.0/tools/secure_path_utils.py +426 -0
  83. doc_redaction-2.2.0/tools/secure_regex_utils.py +297 -0
  84. doc_redaction-2.2.0/tools/simplified_api.py +1120 -0
  85. doc_redaction-2.2.0/tools/summaries.py +2434 -0
  86. doc_redaction-2.2.0/tools/textract_batch_call.py +954 -0
  87. doc_redaction-2.2.0/tools/word_segmenter.py +2011 -0
@@ -0,0 +1,3 @@
1
+ include favicon.png
2
+ recursive-include intros *.txt
3
+
@@ -0,0 +1,394 @@
1
+ Metadata-Version: 2.4
2
+ Name: doc_redaction
3
+ Version: 2.2.0
4
+ Summary: Redact PDF/image-based documents, Word, or CSV/XLSX files using a Gradio-based GUI interface
5
+ Author-email: Sean Pedrick-Case <spedrickcase@lambeth.gov.uk>
6
+ Maintainer-email: Sean Pedrick-Case <spedrickcase@lambeth.gov.uk>
7
+ License-Expression: AGPL-3.0-only
8
+ Project-URL: Homepage, https://seanpedrick-case.github.io/doc_redaction/
9
+ Project-URL: Repository, https://github.com/seanpedrick-case/doc_redaction
10
+ Keywords: redaction,pdf,nlp,documents,document-processing,gradio,pii,pii-detection
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Legal Industry
14
+ Classifier: Topic :: Text Processing :: General
15
+ Classifier: Topic :: Security :: Cryptography
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: pdfminer.six<=20260107
24
+ Requires-Dist: pdf2image<=1.17.0
25
+ Requires-Dist: pymupdf<=1.27.1
26
+ Requires-Dist: bleach<=6.3.0
27
+ Requires-Dist: opencv-python<=4.13.0.92
28
+ Requires-Dist: presidio_analyzer<=2.2.362
29
+ Requires-Dist: presidio_anonymizer<=2.2.362
30
+ Requires-Dist: presidio-image-redactor<=0.0.58
31
+ Requires-Dist: pikepdf<=10.3.0
32
+ Requires-Dist: pandas<=2.3.3
33
+ Requires-Dist: scikit-learn<=1.8.0
34
+ Requires-Dist: spacy<=3.8.14
35
+ Requires-Dist: gradio<=6.10.0
36
+ Requires-Dist: boto3<=1.42.91
37
+ Requires-Dist: pyarrow<=23.0.1
38
+ Requires-Dist: openpyxl<=3.1.5
39
+ Requires-Dist: Faker<=40.8.0
40
+ Requires-Dist: python-levenshtein<=0.27.3
41
+ Requires-Dist: spaczz<=0.6.1
42
+ Requires-Dist: gradio_image_annotation_redaction==0.5.5
43
+ Requires-Dist: rapidfuzz<=3.14.5
44
+ Requires-Dist: python-dotenv<=1.2.2
45
+ Requires-Dist: awslambdaric<=3.1.1
46
+ Requires-Dist: python-docx<=1.2.0
47
+ Requires-Dist: polars<=1.38.1
48
+ Requires-Dist: defusedxml<=0.7.1
49
+ Requires-Dist: numpy<=2.4.4
50
+ Requires-Dist: spaces<=0.48.3
51
+ Requires-Dist: google-genai<=1.73.0
52
+ Requires-Dist: openai<=2.31.0
53
+ Requires-Dist: markdown<=3.10.2
54
+ Requires-Dist: tabulate<=0.10.0
55
+ Provides-Extra: dev
56
+ Requires-Dist: pytest; extra == "dev"
57
+ Provides-Extra: test
58
+ Requires-Dist: pytest; extra == "test"
59
+ Requires-Dist: pytest-cov; extra == "test"
60
+ Provides-Extra: paddle
61
+ Requires-Dist: protobuf<=7.34.0; extra == "paddle"
62
+ Requires-Dist: paddlepaddle<=3.2.1,>=3.0.0; extra == "paddle"
63
+ Requires-Dist: paddleocr<=3.3.0; extra == "paddle"
64
+ Requires-Dist: pycocotools<=2.0.10; extra == "paddle"
65
+ Provides-Extra: vlm
66
+ Requires-Dist: torch<=2.9.1; extra == "vlm"
67
+ Requires-Dist: torchvision<=0.24.1; extra == "vlm"
68
+ Requires-Dist: transformers<=5.5.4; extra == "vlm"
69
+ Requires-Dist: accelerate<=1.13.0; extra == "vlm"
70
+ Requires-Dist: bitsandbytes<=0.49.2; extra == "vlm"
71
+ Requires-Dist: sentencepiece<=0.2.1; extra == "vlm"
72
+ Provides-Extra: mcp
73
+ Requires-Dist: gradio[mcp]<=6.10.0; extra == "mcp"
74
+
75
+ # Document redaction (doc_redaction)
76
+
77
+ <a href="https://pypi.org/project/doc-redaction/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/doc-redaction"></a>
78
+
79
+ Redact personally identifiable information (PII) from documents (PDF, PNG, JPG), Word files (DOCX), or tabular data (XLSX/CSV/Parquet). Please see the [User Guide](https://seanpedrick-case.github.io/doc_redaction/src/user_guide.html) for a full walkthrough of all the features in the app.
80
+
81
+ ---
82
+
83
+ ## 🚀 Quick Start - Installation and first run
84
+
85
+ Follow these instructions to get the document redaction application running on your local machine.
86
+
87
+ ### 1. Prerequisites: System Dependencies
88
+
89
+ This application relies on two external tools for OCR (Tesseract) and PDF processing (Poppler). Please install them on your system before proceeding.
90
+
91
+ ---
92
+
93
+ #### Automated dependency setup (recommended)
94
+
95
+ If you **don’t have admin rights** (or you just want the simplest setup), you can have the project download and configure **Tesseract** and **Poppler** into a local `third_party/` folder inside your checkout.
96
+
97
+ You need the installer script available first, which means either:
98
+
99
+ - **Repository checkout**: `git clone ...` and run the command from the repo root (recommended for the web UI), or
100
+ - **PyPI install**: `pip install doc_redaction` and run from a writable folder where you want `third_party/` and `config/app_config.env` to be created/updated.
101
+
102
+ From the repository root (or your chosen working folder) after creating/activating your venv and installing Python requirements:
103
+
104
+ ```bash
105
+ python -m doc_redaction.install_deps
106
+ ```
107
+
108
+ This writes `TESSERACT_FOLDER` / `POPPLER_FOLDER` into `config/app_config.env` so the app can find the binaries without you editing your system PATH.
109
+
110
+ To just check whether your machine can already see the tools:
111
+
112
+ ```bash
113
+ python -m doc_redaction.install_deps --verify-only
114
+ ```
115
+
116
+
117
+ #### **On Windows**
118
+
119
+ If you don’t use the automated setup above, you can install the dependencies manually by downloading installers and adding the programs to your system's PATH.
120
+
121
+ 1. **Install Tesseract OCR:**
122
+ * Download the installer from the official Tesseract at [UB Mannheim page](https://github.com/UB-Mannheim/tesseract/wiki) (e.g., `tesseract-ocr-w64-setup-v5.X.X...exe`).
123
+ * Run the installer.
124
+ * **IMPORTANT:** During installation, ensure you select the option to "Add Tesseract to system PATH for all users" or a similar option. This is crucial for the application to find the Tesseract executable.
125
+
126
+
127
+ 2. **Install Poppler:**
128
+ * Download the latest Poppler binary for Windows. A common source is the [Poppler for Windows](https://github.com/oschwartz10612/poppler-windows) GitHub releases page. Download the `.zip` file (e.g., `poppler-25.07.0-win.zip`).
129
+ * Extract the contents of the zip file to a permanent location on your computer, for example, `C:\Program Files\poppler\`.
130
+ * You must add the `bin` folder from your Poppler installation to your system's PATH environment variable.
131
+ * Search for "Edit the system environment variables" in the Windows Start Menu and open it.
132
+ * Click the "Environment Variables..." button.
133
+ * In the "System variables" section, find and select the `Path` variable, then click "Edit...".
134
+ * Click "New" and add the full path to the `bin` directory inside your Poppler folder (e.g., `C:\Program Files\poppler\poppler-24.02.0\bin`).
135
+ * Click OK on all windows to save the changes.
136
+
137
+ To verify, open a new Command Prompt and run `tesseract --version` and `pdftoppm -v`. If they both return version information, you have successfully installed the prerequisites.
138
+
139
+ ---
140
+
141
+ #### **On Linux (Debian/Ubuntu)**
142
+
143
+ Open your terminal and run the following command to install Tesseract and Poppler:
144
+
145
+ ```bash
146
+ sudo apt-get update && sudo apt-get install -y tesseract-ocr poppler-utils
147
+ ```
148
+
149
+ #### **On Linux (Fedora/CentOS/RHEL)**
150
+
151
+ Open your terminal and use the `dnf` or `yum` package manager:
152
+
153
+ ```bash
154
+ sudo dnf install -y tesseract poppler-utils
155
+ ```
156
+ ---
157
+
158
+
159
+ ### 2. Installation: Python packages
160
+
161
+ Once the system prerequisites are installed, create a virtual environment (recommended) and install **doc_redaction**.
162
+
163
+ ```bash
164
+ python -m venv venv
165
+ # Windows:
166
+ .\venv\Scripts\activate
167
+ # macOS/Linux:
168
+ source venv/bin/activate
169
+ ```
170
+
171
+ #### Install from PyPI (recommended for users and library use)
172
+
173
+ The package is published on PyPI as **`doc-redaction`** (import name **`doc_redaction`**):
174
+
175
+ ```bash
176
+ pip install doc_redaction
177
+ ```
178
+
179
+ Optional extras (same as in `pyproject.toml`):
180
+
181
+ ```bash
182
+ pip install "doc_redaction[paddle,vlm]"
183
+ ```
184
+
185
+ For programmatic use (CLI-first API matching Gradio `api_name` routes), see **[Package API usage (Python)](https://seanpedrick-case.github.io/doc_redaction/src/package_api_usage.html)**. The console script **`cli_redact`** is available after install.
186
+
187
+ **Web UI from a PyPI install:** You *can* start the Gradio UI after `pip install doc_redaction` by running:
188
+
189
+ ```bash
190
+ python -m app
191
+ ```
192
+
193
+ In practice, the **smoothest UI experience** (examples, bundled assets, docs links, etc.) is still usually via a **repository checkout** or **Docker**, but PyPI install is sufficient to launch the UI as long as you run it from a suitable working folder and have the system dependencies available (or run `python -m doc_redaction.install_deps` first).
194
+
195
+ #### Install from source (repository checkout / development)
196
+
197
+ Clone the repository and install in editable mode:
198
+
199
+ ```bash
200
+ git clone https://github.com/seanpedrick-case/doc_redaction.git
201
+ cd doc_redaction
202
+ pip install -e .
203
+ ```
204
+
205
+ From the same checkout you can use `requirements_lightweight.txt` instead of editable install if you prefer:
206
+
207
+ ```bash
208
+ pip install -r requirements_lightweight.txt
209
+ ```
210
+
211
+ ##### Full install from source (Paddle and VLM)
212
+
213
+ ```bash
214
+ pip install -e ".[paddle,vlm]"
215
+ ```
216
+
217
+ Alternatively, use the full `requirements.txt` (includes PaddleOCR and Torch/transformers references for CUDA 12.9):
218
+
219
+ ```bash
220
+ pip install -r requirements.txt
221
+ ```
222
+
223
+ Note that the versions of both PaddleOCR and Torch installed by default are the CPU-only versions. If you want to install the equivalent GPU versions, you will need to run the following commands:
224
+ ```bash
225
+ pip install paddlepaddle-gpu==3.2.1 --index-url https://www.paddlepaddle.org.cn/packages/stable/cu129/
226
+ ```
227
+
228
+ **Note:** It is difficult to get paddlepaddle gpu working in an environment alongside torch. You may well need to reinstall the cpu version to ensure compatibility, and run paddlepaddle-gpu in a separate environment without torch installed. If you get errors related to .dll files following paddle gpu install, you may need to install the latest c++ redistributables. For Windows, you can find them [here](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170)
229
+
230
+ ```bash
231
+ pip install torch==2.8.0 --index-url https://download.pytorch.org/whl/cu129
232
+ pip install torchvision --index-url https://download.pytorch.org/whl/cu129
233
+ ```
234
+
235
+ #### Docker installation
236
+
237
+ The doc_redaction Redaction app can be installed by using the [Dockerfile](https://github.com/seanpedrick-case/doc_redaction/blob/main/Dockerfile) or Docker compose files ([llama.cpp](https://github.com/ggml-org/llama.cpp), [vLLM](https://docs.vllm.ai/en/stable/)) provided in the repo.
238
+
239
+ ##### Without Llama.cpp / vLLM inference server
240
+
241
+ If you want a working Docker installation without GPU support, you can install from the [Dockerfile](https://github.com/seanpedrick-case/doc_redaction/blob/main/Dockerfile) in the repo. A working example of this, with the CPU version of PaddleOCR, can be found on [Hugging Face](https://huggingface.co/spaces/seanpedrickcase/document_redaction). You can adjust the INSTALL_PADDLEOCR, PADDLE_GPU_ENABLED, INSTALL_VLM, and TORCH_GPU_ENABLED config variables to adjust for PaddleOCR and Transformers packages for local VLM support. Note that GPU-enabled PaddleOCR, and GPU-enabled Transformers/Torch often don't work well together, which is one reason why a Llama.cpp/vLLM inference server Docker installation option is provided below.
242
+
243
+ ##### With Llama.cpp / vLLM inference server
244
+
245
+ The project now has Docker and Docker compose files available to pair running the Redaction app with local inference servers powered by [llama.cpp](https://github.com/ggml-org/llama.cpp), or [vLLM](https://docs.vllm.ai/en/stable/). Llama.cpp is more flexible than vLLM for low VRAM systems, as Llama.cpp will offload to cpu/system RAM automatically rather than failing as vLLM tends to do.
246
+
247
+ For Llama.cpp, you can use the [docker-compose_llama.yml](https://github.com/seanpedrick-case/doc_redaction/blob/main/docker-compose_llama.yml) file, and for vLLM, you can use the [docker-compose_vllm.yml](https://github.com/seanpedrick-case/doc_redaction/blob/main/docker-compose_vllm.yml) file. To run, Docker / Docker Desktop should be installed, and then you can run the commands suggested in the top of the files to run the servers.
248
+
249
+ You will need ~40-50GB of disk space to run everything depending on the model chosen from the compose file. For the vLLM server, you will need 24 GB VRAM. For the Llama.cpp server, 24 GB VRAM is needed to run at full speed, but the n-gpu-layers and n-cpu-moe parameters in the Docker compose file can be adjusted to fit into your system. I would suggest that 8 GB VRAM is needed as a bare minimum for decent inference speed. See the [Unsloth guide](https://unsloth.ai/docs/models/qwen3.5) for more details on working with GGUF files for Qwen 3.5.
250
+
251
+ ### 3. Run the Application
252
+
253
+ With all dependencies installed, you can now start the Gradio application.
254
+
255
+ ```bash
256
+ python app.py
257
+ ```
258
+
259
+ After running the command, the application will start, and you will see a local URL in your terminal (usually `http://127.0.0.1:7860`).
260
+
261
+ Open this URL in your web browser to use the document redaction tool
262
+
263
+ #### Command line interface
264
+
265
+ If you installed from **PyPI**, use the installed console script:
266
+
267
+ ```bash
268
+ cli_redact --help
269
+ ```
270
+
271
+ From a **repository checkout**, you can also run:
272
+
273
+ ```bash
274
+ python cli_redact.py --help
275
+ ```
276
+
277
+ For Python examples that mirror each Gradio `api_name`, see [Package API usage (Python)](https://seanpedrick-case.github.io/doc_redaction/src/package_api_usage.html) (source: [src/package_api_usage.qmd](src/package_api_usage.qmd)).
278
+
279
+ ---
280
+
281
+
282
+ ### 4. ⚙️ Configuration (Optional)
283
+
284
+ You can customise the application's behavior by creating a configuration file. This allows you to change settings without modifying the source code, such as enabling AWS features, changing logging behavior, or pointing to local Tesseract/Poppler installations. A full overview of all the potential settings you can modify in the app_config.env file can be seen in tools/config.py, with explanation on the documentation website for [the github repo](https://seanpedrick-case.github.io/doc_redaction/)
285
+
286
+ To get started:
287
+ 1. Locate the `example_config.env` file in the root of the project.
288
+ 2. Create a new file named `app_config.env` inside the `config/` directory (i.e., `config/app_config.env`).
289
+ 3. Copy the contents from `example_config.env` into your new `config/app_config.env` file.
290
+ 4. Modify the values in `config/app_config.env` to suit your needs. The application will automatically load these settings on startup.
291
+
292
+ If you do not create this file, the application will run with default settings.
293
+
294
+ #### Configuration Breakdown
295
+
296
+ Here is an overview of the most important settings, separated by whether they are for local use or require AWS.
297
+
298
+ ---
299
+
300
+ #### **Local & General Settings (No AWS Required)**
301
+
302
+ These settings are useful for all users, regardless of whether you are using AWS.
303
+
304
+ * `TESSERACT_FOLDER` / `POPPLER_FOLDER`
305
+ * Use these if you installed Tesseract or Poppler to a custom location on **Windows** and did not add them to the system PATH.
306
+ * Provide the path to the respective installation folders (for Poppler, point to the `bin` sub-directory).
307
+ * **Examples:** `POPPLER_FOLDER=C:/Program Files/poppler-24.02.0/bin/` `TESSERACT_FOLDER=tesseract/`
308
+
309
+ * `SHOW_LANGUAGE_SELECTION=True`
310
+ * Set to `True` to display a language selection dropdown in the UI for OCR processing.
311
+
312
+ * `DEFAULT_LOCAL_OCR_MODEL=tesseract`"
313
+ * Choose the backend for local OCR. Options are `tesseract`, `paddle`, or `hybrid`. "Tesseract" is the default, and is recommended. "hybrid-paddle" is a combination of the two - first pass through the redactions will be done with Tesseract, and then a second pass will be done with PaddleOCR on words with low confidence. "paddle" will only return whole line text extraction, and so will only work for OCR, not redaction.
314
+
315
+ * `SESSION_OUTPUT_FOLDER=False`
316
+ * If `True`, redacted files will be saved in unique subfolders within the `output/` directory for each session.
317
+
318
+ * `DISPLAY_FILE_NAMES_IN_LOGS=False`
319
+ * For privacy, file names are not recorded in usage logs by default. Set to `True` to include them.
320
+
321
+ ---
322
+
323
+ #### **AWS-Specific Settings**
324
+
325
+ These settings are only relevant if you intend to use AWS services like Textract for OCR and Comprehend for PII detection.
326
+
327
+ * `RUN_AWS_FUNCTIONS=True`
328
+ * **This is the master switch.** You must set this to `True` to enable any AWS functionality. If it is `False`, all other AWS settings will be ignored.
329
+
330
+ * **UI Options:**
331
+ * `SHOW_AWS_TEXT_EXTRACTION_OPTIONS=True`: Adds "AWS Textract" as an option in the text extraction dropdown.
332
+ * `SHOW_AWS_PII_DETECTION_OPTIONS=True`: Adds "AWS Comprehend" as an option in the PII detection dropdown.
333
+
334
+ * **Core AWS Configuration:**
335
+ * `AWS_REGION=example-region`: Set your AWS region (e.g., `us-east-1`).
336
+ * `DOCUMENT_REDACTION_BUCKET=example-bucket`: The name of the S3 bucket the application will use for temporary file storage and processing.
337
+
338
+ * **AWS Logging:**
339
+ * `SAVE_LOGS_TO_DYNAMODB=True`: If enabled, usage and feedback logs will be saved to DynamoDB tables.
340
+ * `ACCESS_LOG_DYNAMODB_TABLE_NAME`, `USAGE_LOG_DYNAMODB_TABLE_NAME`, etc.: Specify the names of your DynamoDB tables for logging.
341
+
342
+ * **Advanced AWS Textract Features:**
343
+ * `SHOW_WHOLE_DOCUMENT_TEXTRACT_CALL_OPTIONS=True`: Enables UI components for large-scale, asynchronous document processing via Textract.
344
+ * `TEXTRACT_WHOLE_DOCUMENT_ANALYSIS_BUCKET=example-bucket-output`: A separate S3 bucket for the final output of asynchronous Textract jobs.
345
+ * `LOAD_PREVIOUS_TEXTRACT_JOBS_S3=True`: If enabled, the app will try to load the status of previously submitted asynchronous jobs from S3.
346
+
347
+ * **Cost Tracking (for internal accounting):**
348
+ * `SHOW_COSTS=True`: Displays an estimated cost for AWS operations. Can be enabled even if AWS functions are off.
349
+ * `GET_COST_CODES=True`: Enables a dropdown for users to select a cost code before running a job.
350
+ * `COST_CODES_PATH=config/cost_codes.csv`: The local path to a CSV file containing your cost codes.
351
+ * `ENFORCE_COST_CODES=True`: Makes selecting a cost code mandatory before starting a redaction.
352
+
353
+ Now you have the app installed, please refer to the [User Guide](https://seanpedrick-case.github.io/doc_redaction/src/user_guide.html) for more information on how to use it for basic and advanced redaction.
354
+
355
+ ## For agents (API quickstart)
356
+
357
+ If you are an LLM/agent interacting with this app over HTTP (e.g. Hugging Face Spaces), **do not guess inputs** from the UI. Use the Gradio schema as the source of truth:
358
+
359
+ - **Discover schema**: `GET /gradio_api/info`
360
+ - **Upload files**: `POST /gradio_api/upload` (multipart field `files`) → returns server-internal paths like `/tmp/gradio_tmp/...`
361
+ - **Call**: `POST /gradio_api/call/{api_name}` with body `{"data":[...]}` (argument order must match `/gradio_api/info`)
362
+ - **Poll**: `GET /gradio_api/call/{api_name}/{event_id}` until complete
363
+ - **Download outputs**: `GET /gradio_api/file={path}` (note: some deployments return 403 without session cookies)
364
+
365
+ ### Choose the correct route (prefer short `gr.api` endpoints)
366
+
367
+ Fetch `/gradio_api/info` and then prefer the simplest route that exists:
368
+
369
+ - **Apply edited review CSV to a PDF**: `/review_apply`
370
+ - **Redact a PDF/image document**: `/doc_redact`
371
+ - **Summarise a PDF**: `/pdf_summarise`
372
+ - **Redact tabular files (CSV/XLSX/Parquet/DOCX)**: `/tabular_redact`
373
+
374
+ If those endpoints are not present in your deployment, fall back to the long UI-chained routes (`/apply_review_redactions`, `/redact_data`, etc.) and build `data[]` strictly from `/gradio_api/info`.
375
+
376
+ ### Common gotchas
377
+
378
+ - **Arity errors** (`needed: N, got: M`) mean you called a session-heavy UI handler with the wrong `data[]`. Prefer the short endpoints above.
379
+ - **`handle_file()` gotcha** (for `gradio_client` users): do **not** wrap server-internal upload paths (e.g. `/tmp/gradio_tmp/...`) with `handle_file()`. Pass them as plain strings.
380
+ - **Container-only outputs**: outputs may be written to container paths (e.g. `/home/user/app/output/`). Plan to download via `file=...` or use a mounted output directory in Docker.
381
+
382
+ ### Optional: MCP server
383
+
384
+ If you want external agents to call this app reliably without re-implementing Gradio upload/call/poll/download details, consider an **MCP server** that wraps the main tasks (`redact_document`, `apply_review_redactions`, `redact_tabular`, `summarise_document`) behind a small tool interface. See [src/agent_mcp.md](src/agent_mcp.md).
385
+
386
+ **Use as a library:** After installing from [PyPI](https://pypi.org/project/doc-redaction/) (`pip install doc_redaction`), you can call the same workflows as the Gradio `api_name` routes from Python. See the documentation: [Package API usage (Python)](https://seanpedrick-case.github.io/doc_redaction/src/package_api_usage.html) (source: [src/package_api_usage.qmd](src/package_api_usage.qmd)).
387
+
388
+ To extract text from documents, the 'Local' options are PikePDF for PDFs with selectable text, and OCR with Tesseract. Use AWS Textract to extract more complex elements e.g. handwriting, signatures, or unclear text. PaddleOCR and VLM support is also provided (see the installation instructions below).
389
+
390
+ For PII identification, 'Local' (based on spaCy) gives good results if you are looking for common names or terms, or a custom list of terms to redact (see Redaction settings). AWS Comprehend gives better results at a small cost.
391
+
392
+ Additional options on the 'Redaction settings' include, the type of information to redact (e.g. people, places), custom terms to include/ exclude from redaction, fuzzy matching, language settings, and whole page redaction. After redaction is complete, you can view and modify suggested redactions on the 'Review redactions' tab to quickly create a final redacted document.
393
+
394
+ NOTE: The app is not 100% accurate, and it will miss some personal information. It is essential that all outputs are reviewed **by a human** before using the final outputs.