CoolFace
Apppublic

alfonsovelp/deepseek-ocr

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

DeepSeek-OCR Image Extraction API

This Space provides a FastAPI endpoint for extracting text and bounding boxes from images using DeepSeek-OCR with grounding support.

Features

  • โ€”๐Ÿ“ Extract text from images with precise bounding box coordinates
  • โ€”๐ŸŽฏ Grounding support for spatial text localization
  • โ€”๐Ÿš€ GPU-accelerated inference
  • โ€”๐Ÿ“ฆ RESTful API interface

Requirements

  • โ€”GPU: Nvidia T4 (30GB recommended) or higher
  • โ€”CUDA: 11.8+
  • โ€”Python: 3.12+

API Endpoints

POST /extract

Extract text and bounding boxes from a base64-encoded image.

Request Body:

json
{
  "image": "base64_encoded_image_string",
  "prompt": "<image>\n<|grounding|>Convert the document to markdown. ",
  "base_size": 1024,
  "image_size": 640,
  "crop_mode": true
}

Response:

json
{
  "document_type": "image",
  "image_dimensions": {
    "width": 1920,
    "height": 1080
  },
  "extractions": [
    {
      "text": "extracted text",
      "bbox": {
        "x": 100,
        "y": 200,
        "width": 150,
        "height": 30
      }
    }
  ]
}

POST /extract_simple

Returns raw DeepSeek-OCR output for debugging and format inspection.

Model Sizes

  • โ€”Tiny: base_size=512, image_size=512, crop_mode=False
  • โ€”Small: base_size=640, image_size=640, crop_mode=False
  • โ€”Base: base_size=1024, image_size=1024, crop_mode=False
  • โ€”Large: base_size=1280, image_size=1280, crop_mode=False
  • โ€”Gundam: base_size=1024, image_size=640, crop_mode=True (default)

Usage Example

python
import requests
import base64

# Read and encode image
with open("image.png", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

# Make API request
response = requests.post(
    "https://your-space-url/extract",
    json={
        "image": image_b64,
        "prompt": "<image>\n<|grounding|>Convert the document to markdown. "
    }
)

result = response.json()
print(result["extractions"])

Prompts

  • โ€”Free OCR (no bounding boxes): "<image>\nFree OCR. "
  • โ€”Grounded OCR (with bounding boxes): "<image>\n<|grounding|>Convert the document to markdown. "

Credits

Based on DeepSeek-OCR by DeepSeek AI.

Citation

bibtex
@article{wei2024deepseek-ocr,
  title={DeepSeek-OCR: Contexts Optical Compression},
  author={Wei, Haoran and Sun, Yaofeng and Li, Yukun},
  journal={arXiv preprint arXiv:2510.18234},
  year={2025}
}