CoolFace
Apppublic

davanstrien/deepseek-ocr

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
App README

DeepSeek-OCR with vLLM

High-performance document OCR using DeepSeek-OCR with vLLM for efficient batch processing.

๐Ÿš€ Quick Start with HuggingFace Jobs

Process any image dataset without needing your own GPU:

bash
# Basic usage (Gundam mode - adaptive resolution)
hf jobs run --flavor l4x1 \
    --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    input-dataset \
    output-dataset

# Quick test with 10 samples
hf jobs run --flavor l4x1 \
    --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    your-input-dataset \
    your-output-dataset \
    --max-samples 10

That's it! The script will:

  • โ€”โœ… Process images from your dataset
  • โ€”โœ… Add OCR results as a new markdown column
  • โ€”โœ… Push results to a new dataset with automatic documentation
  • โ€”๐Ÿ“Š View results at: https://huggingface.co/datasets/[your-output-dataset]

๐Ÿ“‹ Features

Model Capabilities

  • โ€”๐Ÿ“ LaTeX equations - Mathematical formulas preserved in LaTeX format
  • โ€”๐Ÿ“Š Tables - Extracted and formatted as HTML/markdown
  • โ€”๐Ÿ“ Document structure - Headers, lists, and formatting maintained
  • โ€”๐Ÿ–ผ๏ธ Image grounding - Spatial layout and bounding box information
  • โ€”๐Ÿ” Complex layouts - Multi-column and hierarchical structures
  • โ€”๐ŸŒ Multilingual - Supports multiple languages

Performance

  • โ€”โšก vLLM AsyncEngine - Optimized for throughput (~2500 tokens/s on A100)
  • โ€”๐ŸŽฏ Multiple resolution modes - Choose speed vs quality
  • โ€”๐Ÿ”ฅ Large context - Up to 8K tokens
  • โ€”๐Ÿ’ช Batch optimized - Efficient async processing

๐ŸŽ›๏ธ Resolution Modes

ModeResolutionVision TokensBest For
tiny512ร—51264Fast testing, simple documents
small640ร—640100Balanced speed/quality
base1024ร—1024256High quality documents
large1280ร—1280400Maximum quality, detailed docs
gundamDynamicAdaptiveLarge documents, best overall

๐Ÿ’ป Usage Examples

Basic Processing

bash
# Default (Gundam mode)
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    my-images-dataset \
    ocr-results

Fast Processing for Testing

bash
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    large-dataset \
    test-output \
    --max-samples 100

Random Sampling

bash
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    ordered-dataset \
    random-sample \
    --max-samples 50 \
    --shuffle \
    --seed 42

Custom Image Column

bash
hf jobs run --flavor a10g-large --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    davanstrien/ufo-ColPali \
    ufo-ocr \
    --image-column image

Private Output Dataset

bash
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python process_dataset.py \
    private-input \
    private-output \
    --private

๐Ÿ“ Command-Line Options

Required Arguments

ArgumentDescription
input_datasetInput dataset ID from Hugging Face Hub
output_datasetOutput dataset ID for Hugging Face Hub

Optional Arguments

OptionDefaultDescription
--image-columnimageColumn containing images
--modeldeepseek-ai/DeepSeek-OCRModel to use
--resolution-modegundamResolution preset (tiny/small/base/large/gundam)
--max-model-len8192Maximum model context length
--max-tokens8192Maximum tokens to generate
--gpu-memory-utilization0.75GPU memory usage (0.0-1.0)
--prompt`<image>\n<\grounding\>Convert...`Custom prompt
--hf-token-Hugging Face API token (or use env var)
--splittrainDataset split to process
--max-samplesNoneLimit samples (for testing)
--privateFalseMake output dataset private
--shuffleFalseShuffle dataset before processing
--seed42Random seed for shuffling

๐Ÿ“Š Output Format

The script adds two new columns to your dataset:

  1. 1.`markdown` - The OCR text in markdown format
  2. 2.`inference_info` - JSON metadata about the processing

Inference Info Structure

json
[
  {
    "column_name": "markdown",
    "model_id": "deepseek-ai/DeepSeek-OCR",
    "processing_date": "2025-10-21T12:00:00",
    "resolution_mode": "gundam",
    "base_size": 1024,
    "image_size": 640,
    "crop_mode": true,
    "prompt": "<image>\n<|grounding|>Convert the document to markdown.",
    "max_tokens": 8192,
    "gpu_memory_utilization": 0.75,
    "max_model_len": 8192,
    "script": "main.py",
    "script_version": "1.0.0",
    "space_url": "https://huggingface.co/spaces/davanstrien/deepseek-ocr",
    "implementation": "vllm-async (optimized)"
  }
]

๐Ÿ”ง Technical Details

Architecture

  • โ€”Model: DeepSeek-OCR (3B parameters, based on Qwen2.5-VL)
  • โ€”Inference Engine: vLLM 0.8.5 with AsyncEngine
  • โ€”Image Preprocessing: Custom dynamic tiling based on aspect ratio
  • โ€”Vision Encoders: Custom CLIP + SAM encoders
  • โ€”Context Length: Up to 8K tokens
  • โ€”Optimization: Flash Attention 2.7.3, async batch processing

Hardware Requirements

  • โ€”Minimum: L4 GPU (24GB VRAM) - --flavor l4x1
  • โ€”Recommended: L40S/A10G (48GB VRAM) - --flavor l40sx1 or --flavor a10g-large
  • โ€”Maximum Performance: A100 (40GB+ VRAM) - --flavor a100-large

Speed Benchmarks

GPUResolutionSpeedNotes
L4Tiny~5-8 img/sGood for testing
L4Gundam~2-3 img/sBalanced
A100Gundam~8-12 img/sProduction speed
A100Large~5-7 img/sMaximum quality

๐Ÿ“š Example Workflows

1. Process Historical Documents

bash
hf jobs run --flavor l40sx1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python main.py \
    historical-scans \
    historical-text \
    --resolution-mode large \
    --shuffle

2. Extract Tables from Reports

bash
hf jobs run --flavor a10g-large --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python main.py \
    financial-reports \
    extracted-tables \
    --resolution-mode gundam \
    --prompt "<image>\n<|grounding|>Convert the document to markdown."

3. Multi-language Documents

bash
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
    hf.co/spaces/davanstrien/deepseek-ocr \
    python main.py \
    multilingual-docs \
    ocr-output \
    --resolution-mode base

๐Ÿ”— Related Resources

๐Ÿ“„ License

MIT License - See model card for details

๐Ÿ™ Acknowledgments

  • โ€”DeepSeek AI for the OCR model
  • โ€”vLLM team for the inference engine
  • โ€”Hugging Face for Jobs infrastructure

Built with โค๏ธ using vLLM and DeepSeek-OCR