alhajjaj commited on
Commit
2ef40cb
Β·
verified Β·
1 Parent(s): c5a6c31

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +207 -0
README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+
3
+ ---
4
+ license: polyform-noncommercial-1.0.0
5
+ title: Warraqa
6
+ sdk: python
7
+ ---
8
+
9
+ # Warraqa (ΩˆΨ±Ω‘Ψ§Ω‚Ψ©)
10
+
11
+ ### The Document Scribe Agent
12
+
13
+ *Named after the **WarrāqΕ«n** β€” the master scribes and paper-makers of the Islamic Golden Age.*
14
+
15
+ [![License: PolyForm NC 1.0.0](https://img.shields.io/badge/License-PolyForm%20NC%201.0.0-orange.svg)](LICENSE)
16
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
17
+ [![Version](https://img.shields.io/badge/version-1.0.0-magenta.svg)](CHANGELOG.md)
18
+ [![CI](https://github.com/AALAM-Studio/warraqa/actions/workflows/ci.yml/badge.svg)](https://github.com/AALAM-Studio/warraqa/actions/workflows/ci.yml)
19
+ [![Aalam Studio](https://img.shields.io/badge/from-AALAM%20Studio-black.svg)](https://github.com/AALAM-Studio)
20
+
21
+ **Warraqa converts PDF, Word, and PowerPoint documents into clean, accurate Markdown β€” and scores her own work.**
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ ## Why Warraqa?
28
+
29
+ Most document-to-Markdown tools are one-trick ponies: great at clean PDFs, terrible at scans; great at `.docx`, blind to `.doc`; or they silently produce garbage and let you discover it three pipelines later.
30
+
31
+ Warraqa is a **specialist agent**. She picks the right engine for each file, falls back gracefully, scores her output from 0–100 with letter grades, and tells you which conversions to trust. She's built to feed RAG pipelines, knowledge bases, and downstream agents β€” where Markdown quality directly determines retrieval quality.
32
+
33
+ ## Features
34
+
35
+ - **Dual-engine architecture** β€” best specialized tool for each format
36
+ - **Marker** (deep learning) for scanned PDFs: tables, equations, multi-column, OCR
37
+ - **PyMuPDF4LLM** (fast, CPU-only) for native-text PDFs
38
+ - **MarkItDown** (Microsoft) for `.docx` and `.pptx`
39
+ - **MS Office COM** auto-converts legacy `.doc` and `.ppt` to modern formats first
40
+ - Pandoc fallback for `.docx` resilience
41
+ - **Smart triage** β€” every PDF is pre-scanned to detect native vs. scanned content; routing is automatic
42
+ - **Two-phase batch processing** β€” fast files (native PDFs, Word, PowerPoint) run first; slow OCR work is deferred to a single trailing pass so you don't wait on Marker mid-batch
43
+ - **Quality scoring** β€” every conversion gets a 0–100 confidence score with an A–F grade across 5 dimensions (completeness, structure, encoding, density, readability)
44
+ - **Crash-resistant** β€” sanitizes invalid Unicode from upstream engines so a single bad PDF can't kill a 1000-file run
45
+ - **Folder workflow** β€” input β†’ convert β†’ output + move originals to `processed/` or `failed/`
46
+ - **Watch mode** β€” continuous monitoring for new files
47
+ - **Inter-agent API** β€” designed for other agents to call programmatically
48
+
49
+ ## Quick Start
50
+
51
+ ### Option 1 β€” pip (recommended)
52
+
53
+ ```bash
54
+ pip install warraqa
55
+ warraqa --folder "C:\path\to\documents"
56
+ ```
57
+
58
+ You still need **Pandoc** on `PATH` for `.docx` fallback, and **MS Office** (Windows) for legacy `.doc`/`.ppt`. The Marker engine downloads its ML models on first use (~2–3 GB).
59
+
60
+ ### Option 2 β€” Clone + bootstrap script
61
+
62
+ ```bash
63
+ git clone https://github.com/AALAM-Studio/warraqa.git
64
+ cd warraqa
65
+ python bootstrap.py # creates .venv, installs deps, auto-installs Pandoc on Windows
66
+ .venv\Scripts\activate # Linux/macOS: source .venv/bin/activate
67
+ python run.py
68
+ ```
69
+
70
+ ### Option 3 β€” Docker (for cloud / headless use)
71
+
72
+ ```bash
73
+ docker build -t warraqa .
74
+ docker run --rm -v "/path/to/docs:/data" warraqa --folder /data
75
+ ```
76
+
77
+ Note: the Docker image is CPU-only and does **not** include MS Office, so legacy `.doc`/`.ppt` will be skipped with a clean error message.
78
+
79
+ ## Usage
80
+
81
+ ```bash
82
+ warraqa # Manual mode β€” opens a folder picker dialog
83
+ warraqa --folder "C:\path" # Process a specific folder
84
+ warraqa --file path/to/document.pdf # Convert a single file
85
+ warraqa --watch --folder "C:\path" # Watch mode β€” continuously monitor
86
+ warraqa --folder "C:\path" --no-save --no-move # Dry run
87
+ warraqa --help # All options
88
+ ```
89
+
90
+ ## Output Structure
91
+
92
+ ```
93
+ output/
94
+ β”œβ”€β”€ md_files/ # Converted Markdown files
95
+ β”œβ”€β”€ processed/ # Successfully converted originals
96
+ β”œβ”€β”€ failed/ # Failed conversion originals
97
+ β”œβ”€β”€ reports/ # JSON reports with scores and metadata
98
+ β”œβ”€β”€ scanned_pdfs/ # Staging area for OCR-bound PDFs (auto-cleaned per run)
99
+ └── warraqa.log
100
+ ```
101
+
102
+ ## Quality Scoring
103
+
104
+ Every conversion is scored across 5 weighted dimensions:
105
+
106
+ | Dimension | Weight | What It Measures |
107
+ |:--|:--|:--|
108
+ | Text Completeness | 30% | Word count vs. expected density for file size |
109
+ | Structure Integrity | 25% | Headings, lists, tables, formatting |
110
+ | Encoding Quality | 20% | Garbled text, mojibake, Unicode issues |
111
+ | Content Density | 15% | Meaningful text vs. noise |
112
+ | Readability | 10% | Line length, paragraph structure |
113
+
114
+ Grades: **A** (90–100) β†’ **B** (75–89) β†’ **C** (60–74) β†’ **D** (40–59) β†’ **F** (0–39).
115
+ Files scoring below 40 are moved to `output/failed/` automatically.
116
+
117
+ ## Inter-Agent API
118
+
119
+ ```python
120
+ from warraqa import Warraqa
121
+
122
+ agent = Warraqa()
123
+
124
+ # Convert a single file
125
+ result = agent.convert_file("document.pdf")
126
+ print(result.confidence_score) # 87
127
+ print(result.grade) # "B"
128
+ print(result.markdown_content) # "# Title\n\n..."
129
+ print(result.output_path) # Path to saved .md file
130
+
131
+ # Process a folder
132
+ results = agent.process_folder("C:/Users/you/Academia")
133
+ for r in results:
134
+ print(f"{r.source_file.filename}: {r.grade} ({r.confidence_score}/100)")
135
+ ```
136
+
137
+ ## Configuration
138
+
139
+ Edit [`config.yaml`](config.yaml) to customize:
140
+
141
+ - Default mode (manual / watch)
142
+ - Output directories
143
+ - Engine preferences (primary / fallback per format)
144
+ - Scoring thresholds
145
+ - Logging level
146
+
147
+ ## Supported Formats
148
+
149
+ | Extension | Engine | Notes |
150
+ |:--|:--|:--|
151
+ | `.pdf` (native text) | PyMuPDF4LLM | Fast, CPU-only |
152
+ | `.pdf` (scanned) | Marker | Deferred to Phase 2 OCR pass |
153
+ | `.docx` | MarkItDown β†’ Pandoc | β€” |
154
+ | `.doc` | MS Office COM β†’ MarkItDown | Windows + Office required |
155
+ | `.pptx` | MarkItDown | β€” |
156
+ | `.ppt` | MS Office COM β†’ MarkItDown | Windows + Office required |
157
+
158
+ ## License
159
+
160
+ **Warraqa is published under the [PolyForm Noncommercial License 1.0.0](LICENSE)** β€” a source-available license that allows free use for:
161
+
162
+ - Personal projects, research, study, and experimentation
163
+ - Academic and educational institutions
164
+ - Charitable, public-safety, health, and government organizations
165
+ - Internal evaluation by any organization
166
+
167
+ **Commercial use** β€” including using Warraqa as part of a product or service offered to paying customers, internal business operations at a for-profit company, or any revenue-generating workflow β€” **requires a separate commercial license**. Contact **`contact@aalam.consulting`** to discuss licensing.
168
+
169
+ Note on terminology: PolyForm Noncommercial is *source-available*, not *open source* in the OSI sense (which by definition allows commercial use). The full text is in [`LICENSE`](LICENSE).
170
+
171
+ ## Versioning Policy
172
+
173
+ This repository contains **Warraqa v1.0.0** β€” the inaugural public, source-available release. Future versions of Warraqa are developed privately and available under commercial license terms. Critical bug fixes may be backported to v1.x at AALAM Studio's discretion.
174
+
175
+ See [`CHANGELOG.md`](CHANGELOG.md) for the release history.
176
+
177
+ ## Citation
178
+
179
+ If Warraqa contributes to academic research, please cite it. A machine-readable [`CITATION.cff`](CITATION.cff) is provided, or use the GitHub "Cite this repository" button.
180
+
181
+ ## Acknowledgements
182
+
183
+ Warraqa stands on the shoulders of excellent open-source projects:
184
+
185
+ - [Marker](https://github.com/VikParuchuri/marker) β€” Vik Paruchuri's deep-learning PDF parser
186
+ - [PyMuPDF4LLM](https://github.com/pymupdf/PyMuPDF) β€” Artifex's LLM-optimized PDF extraction
187
+ - [MarkItDown](https://github.com/microsoft/markitdown) β€” Microsoft's universal-to-markdown converter
188
+ - [Pandoc](https://pandoc.org/) β€” John MacFarlane's document conversion swiss-army knife
189
+ - [Rich](https://github.com/Textualize/rich) β€” Will McGugan's terminal beautifier
190
+
191
+ ## Part of Aalam Studio
192
+
193
+ Warraqa is the first publicly released agent in the **AALAM Studio** ecosystem. Other agents access her output at a predictable path:
194
+
195
+ ```python
196
+ WARRAQA_OUTPUT = "c:/projects/aalam-studio/warraqa/output/"
197
+ ```
198
+
199
+ ---
200
+
201
+ <div align="center">
202
+
203
+ *She reads. She transcribes. She scores her own work.*
204
+
205
+ **Built with care by [AALAM Studio](https://github.com/AALAM-Studio).**
206
+
207
+ </div>