Views
No views yet
Original Document → LLM Re-enrichment → Re-enriched Copy → Your ParserTITLE, SECTION_HEADING, or BODY using Llama3 via Ollama1git clone https://huggingface.co/dwijverma2/doc-enricher
2cd doc-enricher
3pip install python-docx requests1ollama pull llama3
2ollama serve # if not already running1from doc_enricher import DocumentEnricher, DocxHandler
2
3enricher = DocumentEnricher(
4 handler=DocxHandler(),
5 model="llama3",
6)
7
8# Single file
9enricher.enrich("report.docx", "report_enriched.docx")
10
11# Batch — all .docx files in a directory
12enricher.enrich_batch("./originals/", "./enriched/")1# Single file
2python -m doc_enricher.cli report.docx -o report_enriched.docx
3
4# Batch mode
5python -m doc_enricher.cli --batch ./originals/ -o ./enriched/
6
7# Custom model + verbose
8python -m doc_enricher.cli report.docx -o out.docx --model llama3:8b -v| Flag | Default | Description |
|---|---|---|
-o, --output | {name}_enriched.docx | Output path |
--batch | off | Process entire directory |
--model | llama3 | Ollama model name |
--ollama-url | http://localhost:11434 | Ollama API URL |
--max-tokens | 3000 | Token budget per LLM chunk |
--overlap | 3 | Paragraph overlap between chunks |
--no-formatting-hints | off | Don't send existing formatting to LLM |
-v, --verbose | off | Debug logging |
/api/chat endpoint with "format": "json" (constrained decoding) for reliable structured output. The prompt includes existing formatting metadata (style name, bold, font size) as hints.Title, Heading 1, Normal) and run-level formatting (bold + font size) are applied — works whether your parser checks para.style.name or inspects run formatting directly.doc_enricher/
├── __init__.py # Package entry point
├── base_handler.py # Abstract handler interface (extend for PDF/HTML)
├── handlers/
│ ├── __init__.py
│ └── docx_handler.py # DOCX: extract paragraphs + apply formatting
├── llm_client.py # Ollama /api/chat with JSON-constrained output
├── chunker.py # Adaptive sliding window with overlap
├── enricher.py # Main orchestrator
└── cli.py # Command-line interface
test_module.py # Test suite (no Ollama required)BaseHandler:1from doc_enricher.base_handler import BaseHandler, ParagraphInfo
2
3class PdfHandler(BaseHandler):
4 def extract_paragraphs(self, filepath: str) -> list[ParagraphInfo]:
5 ...
6 def apply_classifications(self, src_path, dst_path, classifications):
7 ...python test_module.py