alfonsovelp/deepseek-ocr
0
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:
{
"image": "base64_encoded_image_string",
"prompt": "<image>\n<|grounding|>Convert the document to markdown. ",
"base_size": 1024,
"image_size": 640,
"crop_mode": true
}Response:
{
"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
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
@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}
}