furyhawk 168dd1d562 Add script to download PDFs of papers from AI-Papers-of-the-Week
This script fetches Markdown tables from the specified GitHub repository, extracts paper links, resolves them to PDF URLs, and downloads the PDFs. It supports various link formats, handles errors gracefully, and allows for parallel downloads. A JSON manifest of downloaded papers is generated for reference.
2026-10-06 20:04:01 +08:00
2026-08-25 21:46:06 +08:00
2026-08-25 21:46:06 +08:00

Marker PDF Converter - Reflex Framework

A modern web application built with Reflex that converts PDFs, images, and documents to Markdown, HTML, JSON, or chunks using the Marker library.

Features

  • 📄 Multi-format Support: Convert PDFs, images, and documents (PNG, JPG, GIF, PPTX, DOCX, XLSX, HTML, EPUB)
  • 🎨 Live Preview: View document pages in real-time as you navigate
  • 📝 Multiple Output Formats: Export as Markdown, JSON, HTML, or chunks
  • ⚡ Flexible Processing: Choose between fast, balanced, or auto processing modes
  • 🔍 Advanced OCR Options: Control OCR behavior with granular settings
  • 🤖 LLM Support: Optional LLM integration for higher quality processing
  • 🐛 Debug Mode: Analyze document layout with debug visualizations
  • 🎯 Page Range Selection: Process specific pages or page ranges

Installation

Prerequisites

  • Python 3.11 or higher
  • UV package manager (recommended) or pip

Setup

  1. Clone the repository:
git clone <repository-url>
cd reflex-framework-rebuild
  1. Install dependencies using UV:
uv sync

Or with pip:

pip install -e .
  1. Install Reflex CLI (if not included):
pip install reflex

Running the Application

Using Reflex Development Server

reflex run

The application will start on http://localhost:3000

Production Build

reflex build
reflex export

Then deploy the generated files or run:

reflex run --env prod

Usage Guide

Basic Workflow

  1. Upload a Document

    • Click the "Choose File" button in the left sidebar
    • Select your PDF, image, or supported document format
  2. Navigate (PDF only)

    • Use the page number input or the arrow buttons to view different pages (page navigation is 1-based; page ranges remain zero-based)
    • Preview updates in the left panel
  3. Configure Conversion Options

    • Output Format: Choose output type (markdown, JSON, HTML, chunks)
    • Processing Mode:
      • auto: Automatically selects based on device (GPU = balanced, CPU/MPS = fast)
      • balanced: Uses VLM layout model + full-page OCR (best on GPU)
      • fast: Lightweight CPU detectors, only OCRs garbled/empty content
    • Page Range: Specify which pages to process with zero-based ranges (e.g., "0,5-10,20")
  4. Configure Advanced Options

    • Use LLM: Enable for higher quality processing
    • Force OCR: Force OCR on all pages
    • Disable OCR: Skip OCR (text-layer extraction only)
    • Strip Existing OCR: Re-OCR the document
    • Show Page Headers/Footers: Include headers and footers in output
    • Debug Mode: Generate debug visualizations
  5. Run Conversion

    • Click the "Run Conversion" button
    • Monitor progress via status messages
    • View results in the right panel (automatically formatted)

Output Formats

Markdown

  • Clean, readable markdown representation
  • Images embedded as base64-encoded HTML
  • Tables, equations, and formatting preserved

JSON

  • Structured data format
  • Useful for programmatic processing
  • Full metadata included

HTML

  • Web-ready HTML output
  • Fully styled and formatted
  • Direct preview in browser

Chunks

  • Segmented content
  • Useful for RAG (Retrieval-Augmented Generation)
  • JSON format with chunk metadata

Parts lists: Markdown tables → Excel

The marker output for parts / servicing manuals keeps the tables as Markdown. scripts/md_tables_to_excel.py turns those tables into a ready-to-order Excel spare-parts list:

  • it extracts every table and remembers the heading above it as its component (that header is written on the first row of each worksheet);
  • it understands two kinds of component tables and filters them accordingly:
    • Part tables – a dedicated Part Number column exists; only the rows that carry a part number are kept (blank / duplicate rows are dropped, while wrapped text and quantities that belong to a part are merged back);
    • Locator tables – no part number, but a Landmark / Rep. column is used to locate parts or components on an illustration (common in GUINAULT manuals); only the rows that carry a landmark are kept, and side-by-side legends like Landmark | Description | Landmark | Description are flattened into one sorted Landmark | Description list.
  • it also captures inline figure legends: parts/components printed under a subtitle as a plain numbered paragraph (not a table), e.g. the DEUTZ engine callouts 1\_Air pressure/temperature transmitter 2\_Oil filter cap 3\_Exhaust manifold … (the subtitle becomes the component, and a trailing (left view)-style line is kept in the component name);
  • it writes one worksheet per component (sheet name = component heading) plus an Index overview sheet (with a Kind column).
# CIMC TAM 7002 servicing manual: 53 part tables -> one sheet each
python scripts/md_tables_to_excel.py "conversion_results/1. Servicing Manual TAM 7002.pdf 01072026/1. Servicing Manual TAM 7002.pdf 01072026.md"

# GUINAULT GPU GA180 manual: Landmark legends + DEUTZ engine callouts
# (10 component sheets: figures + engine left/right view part lists)
python scripts/md_tables_to_excel.py "conversion_results/GUINAULT - GPU GA180 - Operation and maintenance manual (1)/GUINAULT - GPU GA180 - Operation and maintenance manual (1).md"# keep the non-component tables too (e.g. maintenance schedules)
python scripts/md_tables_to_excel.py manual.md --include-other-tables -o parts.xlsx

# scan a whole folder of markdown files
python scripts/md_tables_to_excel.py conversion_results -o all_manuals.xlsx

The parser deliberately targets the output that marker produces: headers can span several rows, some converters merge the header with the first data row, and cell text can wrap over several visual rows. Tables where several parts were collapsed into a single header line (e.g. Item # 2 3 4 …) are expanded on a best-effort basis and reported in the console so they can be double-checked.

Art books: PDF → images

scripts/pdf_images.py pulls the pictures out of an art book, portfolio or scanned magazine. It copies the embedded streams verbatim (JPEG / JPEG 2000 are written byte-for-byte, no decode and no re-encode), so a 26-page art book finishes in ~0.05 s and the output is bit-identical to the source artwork.

  • walks page content recursively, so images nested in form XObjects are found too;
  • de-duplicates identical images (a background reused on several pages is kept once);
  • names files <pdf>-p0001-01.jpg (page + index), so they sort back into reading order;
  • --format png|jpg|webp|tif re-encodes from the decoded pixel data when you need a different container, --flatten bakes in alpha masks (transparency);
  • --render-missing rasterizes the pages that hold no extractable image at all (vector or tiled art) at a chosen --dpi;
  • CMYK artwork is converted to sRGB by default. Print-sourced art books store their JPEGs as CMYK with the samples inverted (Adobe marker) and usually no colour profile, so anything that reads those samples literally — PIL, browsers, VS Code — shows the page as a negative. PDFium does the conversion (it honours the Adobe marker / embedded ICC), and the result is written as RGB JPEG (--quality, default 95) so it looks right everywhere. --cmyk keep copies the original CMYK streams byte-for-byte instead, if you need them for print;
  • --manifest out/manifest.json records page, size, filters and duplicates per image;
  • input can be a single PDF, a whole folder (scanned recursively) or a glob pattern — a folder of art books converts in one command, and -o then gives each PDF its own sub-folder.
# whole art book -> "God of War ..._images/" next to the PDF
python scripts/pdf_images.py "ingress/God of War Ragnarök - Digital Artbook.pdf"

# a folder, scanned recursively (hidden files/folders are skipped)
python scripts/pdf_images.py artbooks/

# a glob pattern -- quote it so the shell does not expand it first
python scripts/pdf_images.py "artbooks/**/*.pdf" -o out

# pages 1-12 and 40+, ignoring thumbnails and decoration
python scripts/pdf_images.py artbook.pdf -o out --pages 1-12,40- --min-px 256

# vector/tiled PDF: rasterize whatever had no embedded image
python scripts/pdf_images.py artbook.pdf --render-missing --dpi 300

# normalize to PNG with transparency flattened, plus a JSON manifest
python scripts/pdf_images.py artbook.pdf --format png --flatten --manifest out/manifest.json

# keep the original CMYK streams instead of converting them to sRGB
python scripts/pdf_images.py artbook.pdf --cmyk keep

Architecture

Components

  • State Management (MarkerState):

    • Centralized state for file handling, options, and results
    • Async conversion handling
  • UI Components:

    • render_sidebar(): Controls and options
    • render_preview(): Document preview with debug images
    • render_results(): Formatted output display
  • Backend Integration:

    • Marker library integration for PDF/document conversion
    • PyPDF integration for page extraction
    • PIL for image handling

File Structure

ingressor/
├── src/ingressor/         # Main application package
│   ├── app.py             # Reflex app bootstrap
│   ├── components.py      # UI composition
│   ├── marker.py          # Marker conversion helpers
│   └── state.py           # Reflex state and actions
├── reflex_app.py          # Legacy compatibility entrypoint
├── marker_converter/      # Reflex entrypoint module
├── rxconfig.py            # Reflex configuration
├── pyproject.toml         # Project dependencies
└── app/                   # Legacy Streamlit helpers

Technology Stack

  • Frontend Framework: Reflex (Python-based React)
  • Backend: FastAPI (integrated with Reflex)
  • Document Processing: Marker PDF
  • PDF Handling: PyPDF, pypdfium2
  • Image Processing: Pillow

Configuration

Environment Variables

# PyTorch/ML
PYTORCH_ENABLE_MPS_FALLBACK=1    # Enable MPS fallback on Apple Silicon

# Logging
GRPC_VERBOSITY=ERROR              # Suppress gRPC logging
GLOG_minloglevel=2                # Suppress TensorFlow logging

Troubleshooting

Models not loading

  • First run downloads large ML models (~2GB)
  • Initial conversion may take 1-2 minutes
  • Check internet connection

Memory issues

  • Use "fast" mode for resource-constrained systems
  • Process one page at a time
  • Disable LLM and OCR if not needed

OCR not working

  • Ensure scanned pages are high quality
  • Enable "Force OCR" option
  • Check debug images to verify detection

Layout detection issues

  • Use "balanced" mode on GPU systems
  • Check debug images in debug mode
  • Try adjusting page range

Performance Tips

  1. GPU Systems: Use "balanced" mode for best quality
  2. CPU Systems: Use "fast" mode for reasonable speed
  3. Large Documents: Process page ranges instead of full documents
  4. Memory: Disable LLM if running low on memory

Development

Adding New Features

  1. Extend MarkerState for new state variables
  2. Add handler methods for new operations
  3. Create UI components with rx.Component return type
  4. Integrate into main layout

Running Tests

# Run linting
reflex lint

# Format code
reflex format

Known Limitations

  • Reflex rendering may be resource-intensive for very large PDFs
  • Some advanced Marker features may require CLI usage
  • Real-time live updates require WebSocket connection

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

Same license as the parent project

References

Support

For issues or questions:

  1. Check the Marker Issues
  2. Check the Reflex Docs
  3. Open an issue in this repository
S
Description
A modern web application built with Reflex that converts PDFs, images, and documents to Markdown, HTML, JSON, or chunks using the Marker library.
Readme
684 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 95.3%
Shell 3.3%
Makefile 0.9%
Dockerfile 0.5%