Batch-Scan PDFs and Word Files for AI-Generated Text with Python
说明与用途
Python脚本批量扫描PDF、DOCX和TXT文件,提取文本,调用AI检测API,使用指数退避处理速率限制,按段落拆分长文档,生成包含分数和关键片段的CSV报告。
问题
Teachers, HR, and editors need to check many documents for AI-generated content, but copying each into a web tool does not scale.
结果
The script processes a folder of 200+ documents in minutes, producing a CSV with AI‑generation probability scores and key passages, enabling reviewers to focus on suspicious sections.
工作流
- Walk the target folder and identify files with .pdf, .docx, .txt, or .md extensions.
- Extract text from each file using pypdf for PDFs, python-docx for DOCX, and read_text for plain text.
- Handle edge cases: flag scanned PDFs for manual review or OCR, and trim headers/footers after "References" or "Bibliography".
- Send the extracted text to the AI detection API, retrying on 429 (rate limit) with exponential backoff and on 5xx errors with a short pause.
- Chunk long documents into 400‑word pieces, skipping fragments shorter than 50 words, to obtain per‑section scores.
- Collect the API responses and write a CSV report containing file name, overall score, and highlighted passages.
证据
Teachers get a folder of 60 essays. HR gets a shared drive of cover letters. Editors get a pile of freelancer drafts. Checking each one by copy-pasting into a web tool doesn't scale.
Exponential backoff on 429 is the difference between a script that finishes and one that dies halfway through a folder of 200 files.
A 3,000-word report is better scored in chunks than as one blob: you get a per-section picture, and one AI-written section doesn't get averaged away.
- 记录日期: 2026-10-21T14:56:03.010Z