File size: 8,536 Bytes
2ef40cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<div align="center">

---
license: polyform-noncommercial-1.0.0
title: Warraqa
sdk: python
---

# Warraqa (ΩˆΨ±Ω‘Ψ§Ω‚Ψ©)

### The Document Scribe Agent

*Named after the **WarrāqΕ«n** β€” the master scribes and paper-makers of the Islamic Golden Age.*

[![License: PolyForm NC 1.0.0](https://img.shields.io/badge/License-PolyForm%20NC%201.0.0-orange.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![Version](https://img.shields.io/badge/version-1.0.0-magenta.svg)](CHANGELOG.md)
[![CI](https://github.com/AALAM-Studio/warraqa/actions/workflows/ci.yml/badge.svg)](https://github.com/AALAM-Studio/warraqa/actions/workflows/ci.yml)
[![Aalam Studio](https://img.shields.io/badge/from-AALAM%20Studio-black.svg)](https://github.com/AALAM-Studio)

**Warraqa converts PDF, Word, and PowerPoint documents into clean, accurate Markdown β€” and scores her own work.**

</div>

---

## Why Warraqa?

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.

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.

## Features

- **Dual-engine architecture** β€” best specialized tool for each format
  - **Marker** (deep learning) for scanned PDFs: tables, equations, multi-column, OCR
  - **PyMuPDF4LLM** (fast, CPU-only) for native-text PDFs
  - **MarkItDown** (Microsoft) for `.docx` and `.pptx`
  - **MS Office COM** auto-converts legacy `.doc` and `.ppt` to modern formats first
  - Pandoc fallback for `.docx` resilience
- **Smart triage** β€” every PDF is pre-scanned to detect native vs. scanned content; routing is automatic
- **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
- **Quality scoring** β€” every conversion gets a 0–100 confidence score with an A–F grade across 5 dimensions (completeness, structure, encoding, density, readability)
- **Crash-resistant** β€” sanitizes invalid Unicode from upstream engines so a single bad PDF can't kill a 1000-file run
- **Folder workflow** β€” input β†’ convert β†’ output + move originals to `processed/` or `failed/`
- **Watch mode** β€” continuous monitoring for new files
- **Inter-agent API** β€” designed for other agents to call programmatically

## Quick Start

### Option 1 β€” pip (recommended)

```bash
pip install warraqa
warraqa --folder "C:\path\to\documents"
```

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).

### Option 2 β€” Clone + bootstrap script

```bash
git clone https://github.com/AALAM-Studio/warraqa.git
cd warraqa
python bootstrap.py        # creates .venv, installs deps, auto-installs Pandoc on Windows
.venv\Scripts\activate     # Linux/macOS: source .venv/bin/activate
python run.py
```

### Option 3 β€” Docker (for cloud / headless use)

```bash
docker build -t warraqa .
docker run --rm -v "/path/to/docs:/data" warraqa --folder /data
```

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.

## Usage

```bash
warraqa                              # Manual mode β€” opens a folder picker dialog
warraqa --folder "C:\path"           # Process a specific folder
warraqa --file path/to/document.pdf  # Convert a single file
warraqa --watch --folder "C:\path"   # Watch mode β€” continuously monitor
warraqa --folder "C:\path" --no-save --no-move    # Dry run
warraqa --help                       # All options
```

## Output Structure

```
output/
β”œβ”€β”€ md_files/        # Converted Markdown files
β”œβ”€β”€ processed/       # Successfully converted originals
β”œβ”€β”€ failed/          # Failed conversion originals
β”œβ”€β”€ reports/         # JSON reports with scores and metadata
β”œβ”€β”€ scanned_pdfs/    # Staging area for OCR-bound PDFs (auto-cleaned per run)
└── warraqa.log
```

## Quality Scoring

Every conversion is scored across 5 weighted dimensions:

| Dimension | Weight | What It Measures |
|:--|:--|:--|
| Text Completeness | 30% | Word count vs. expected density for file size |
| Structure Integrity | 25% | Headings, lists, tables, formatting |
| Encoding Quality | 20% | Garbled text, mojibake, Unicode issues |
| Content Density | 15% | Meaningful text vs. noise |
| Readability | 10% | Line length, paragraph structure |

Grades: **A** (90–100) β†’ **B** (75–89) β†’ **C** (60–74) β†’ **D** (40–59) β†’ **F** (0–39).
Files scoring below 40 are moved to `output/failed/` automatically.

## Inter-Agent API

```python
from warraqa import Warraqa

agent = Warraqa()

# Convert a single file
result = agent.convert_file("document.pdf")
print(result.confidence_score)    # 87
print(result.grade)               # "B"
print(result.markdown_content)    # "# Title\n\n..."
print(result.output_path)         # Path to saved .md file

# Process a folder
results = agent.process_folder("C:/Users/you/Academia")
for r in results:
    print(f"{r.source_file.filename}: {r.grade} ({r.confidence_score}/100)")
```

## Configuration

Edit [`config.yaml`](config.yaml) to customize:

- Default mode (manual / watch)
- Output directories
- Engine preferences (primary / fallback per format)
- Scoring thresholds
- Logging level

## Supported Formats

| Extension | Engine | Notes |
|:--|:--|:--|
| `.pdf` (native text) | PyMuPDF4LLM | Fast, CPU-only |
| `.pdf` (scanned) | Marker | Deferred to Phase 2 OCR pass |
| `.docx` | MarkItDown β†’ Pandoc | β€” |
| `.doc` | MS Office COM β†’ MarkItDown | Windows + Office required |
| `.pptx` | MarkItDown | β€” |
| `.ppt` | MS Office COM β†’ MarkItDown | Windows + Office required |

## License

**Warraqa is published under the [PolyForm Noncommercial License 1.0.0](LICENSE)** β€” a source-available license that allows free use for:

- Personal projects, research, study, and experimentation
- Academic and educational institutions
- Charitable, public-safety, health, and government organizations
- Internal evaluation by any organization

**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.

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).

## Versioning Policy

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.

See [`CHANGELOG.md`](CHANGELOG.md) for the release history.

## Citation

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.

## Acknowledgements

Warraqa stands on the shoulders of excellent open-source projects:

- [Marker](https://github.com/VikParuchuri/marker) β€” Vik Paruchuri's deep-learning PDF parser
- [PyMuPDF4LLM](https://github.com/pymupdf/PyMuPDF) β€” Artifex's LLM-optimized PDF extraction
- [MarkItDown](https://github.com/microsoft/markitdown) β€” Microsoft's universal-to-markdown converter
- [Pandoc](https://pandoc.org/) β€” John MacFarlane's document conversion swiss-army knife
- [Rich](https://github.com/Textualize/rich) β€” Will McGugan's terminal beautifier

## Part of Aalam Studio

Warraqa is the first publicly released agent in the **AALAM Studio** ecosystem. Other agents access her output at a predictable path:

```python
WARRAQA_OUTPUT = "c:/projects/aalam-studio/warraqa/output/"
```

---

<div align="center">

*She reads. She transcribes. She scores her own work.*

**Built with care by [AALAM Studio](https://github.com/AALAM-Studio).**

</div>