Redact Skill
Privacy redaction toolkit using PPStructureV3 OCR for text detection and replacement.
Scripts
| Script | Format | Command |
|---|
| INLINECODE0 | Images / PDF / Word / PowerPoint | INLINECODE1 |
| INLINECODE2 |
Images (png, jpg, etc.) |
redact-image.py <input> <rules.csv> <output> |
|
redact-pdf.py | PDF |
redact-pdf.py <input> <rules.csv> <output> |
|
redact-document.py | Word (docx, doc) |
redact-document.py <input> <rules.csv> <output> |
|
redact-presentation.py | PowerPoint (pptx, ppt) |
redact-presentation.py <input> <rules.csv> <output> |
CSV Rules Format
CODEBLOCK0
| Rule | Effect |
|---|
| INLINECODE10 | Replace with new text |
| INLINECODE11 |
Empty = mask with █ (documents) or solid color block (images/PDF) |
Masking Behavior
| Format | Empty Replacement |
|---|
| Images, PDF | Solid color block overlay |
| Word, PowerPoint |
█ characters (same length as target) |
Read Features
INLINECODE13 supports:
- - Reading text from images, PDF, Word, and PowerPoint files
- OCR for image files and embedded images
- Page-aware output for PDF / Word / PowerPoint
- INLINECODE14 structured output:
-
<page index="...">
-
<image format='markdown' type='ocr'>...</image> for OCR text extracted from images
JSON Output
Document-like files (pdf, docx, doc, pptx) output:
CODEBLOCK1
Image files output:
CODEBLOCK2
Features
| Feature | Image | PDF | Document | Presentation |
|---|
| Read text | ✅ | ✅ | ✅ | ✅ |
| JSON output |
✅ | ✅ | ✅ | ✅ |
| Text replacement | ✅ | ✅ | ✅ | ✅ |
| Solid color mask | ✅ | ✅ | - | - |
| █ character mask | - | - | ✅ | ✅ |
| OCR detection | ✅ | ✅ | ✅ (images) | ✅ (images) |
| Tables | - | ✅ | ✅ | ✅ |
| Headers/Footers | - | ✅ | ✅ | - |
| Embedded images | - | ✅ | ✅ | ✅ |
Environment Setup
使用 uv 安装依赖:
CODEBLOCK3
Dependencies
- - Python 3.10+
- PaddleOCR / PPStructureV3
- python-docx, python-pptx, PyMuPDF, Pillow
技能名称: redact
详细描述:
红action技能
使用PPStructureV3 OCR进行文本检测和替换的隐私编辑工具包。
脚本
| 脚本 | 格式 | 命令 |
|---|
| read.py | 图片 / PDF / Word / PowerPoint | read.py <输入> [--info] [--mode json] |
| redact-image.py |
图片 (png, jpg等) | redact-image.py <输入> <规则.csv> <输出> |
| redact-pdf.py | PDF | redact-pdf.py <输入> <规则.csv> <输出> |
| redact-document.py | Word (docx, doc) | redact-document.py <输入> <规则.csv> <输出> |
| redact-presentation.py | PowerPoint (pptx, ppt) | redact-presentation.py <输入> <规则.csv> <输出> |
CSV规则格式
csv
目标文本,替换文本
张三,李四
手机号,
身份证号,
空值 = 用█遮盖(文档)或纯色块遮盖(图片/PDF) |
遮盖行为
| 格式 | 空替换 |
|---|
| 图片, PDF | 纯色块覆盖 |
| Word, PowerPoint |
█ 字符(与目标文本等长) |
读取功能
read.py 支持:
- - 从图片、PDF、Word和PowerPoint文件中读取文本
- 对图片文件和嵌入图片进行OCR识别
- 针对PDF/Word/PowerPoint的分页输出
- --info 结构化输出:
-
- ... 用于从图片中提取的OCR文本
JSON输出
文档类文件(pdf、docx、doc、pptx)输出:
json
{
type: pptx,
pages: [
{
page_index: 1,
content: [
{ type: text, text: ... },
{ type: image, text: ocr text... }
]
}
]
}
图片文件输出:
json
{
type: image,
content: ...
}
功能特性
| 功能 | 图片 | PDF | 文档 | 演示文稿 |
|---|
| 读取文本 | ✅ | ✅ | ✅ | ✅ |
| JSON输出 |
✅ | ✅ | ✅ | ✅ |
| 文本替换 | ✅ | ✅ | ✅ | ✅ |
| 纯色遮盖 | ✅ | ✅ | - | - |
| █ 字符遮盖 | - | - | ✅ | ✅ |
| OCR检测 | ✅ | ✅ | ✅ (图片) | ✅ (图片) |
| 表格 | - | ✅ | ✅ | ✅ |
| 页眉/页脚 | - | ✅ | ✅ | - |
| 嵌入图片 | - | ✅ | ✅ | ✅ |
环境设置
使用 uv 安装依赖:
bash
进入 skill 目录
cd skills/redact
同步依赖(自动创建虚拟环境并安装)
uv sync
依赖项
- - Python 3.10+
- PaddleOCR / PPStructureV3
- python-docx, python-pptx, PyMuPDF, Pillow