File size: 1,396 Bytes
30bc126
2020627
 
 
 
30bc126
2020627
30bc126
2020627
 
30bc126
 
 
2020627
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: DeepSeek OCR
emoji: πŸš€
colorFrom: red
colorTo: red
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: true
short_description: DeepSeek-OCR demo on PDF and img
license: mit
---

## API Usage

### Using Gradio Client

```python
from gradio_client import Client

client = Client("BinKhoaLe1812/DeepseekOCR")

# Process a PDF or image file
result = client.predict(
    file_path="path/to/document.pdf",  # or image file
    mode="Gundam",  # Options: Gundam, Tiny, Small, Base, Large
    task="πŸ“‹ Markdown",  # Options: πŸ“‹ Markdown, πŸ“ Free OCR, πŸ“ Locate, πŸ” Describe, ✏️ Custom
    custom_prompt="",  # Required for Custom or Locate tasks
    page_num=1,  # Page number (all pages are processed for PDFs)
    api_name="/run"
)

# Result contains: [text_out, markdown_out, raw_out, img_out, gallery]
text, markdown, raw, image, crops = result
print(text)  # Extracted text
print(markdown)  # Markdown formatted output
```

### Using HTTP API

```python
import requests

# Upload file and process
with open("document.pdf", "rb") as f:
    files = {"files": f}
    data = {
        "mode": "Gundam",
        "task": "πŸ“‹ Markdown",
        "custom_prompt": "",
        "page_num": 1
    }
    response = requests.post(
        "https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/api/predict",
        files=files,
        data=data
    )
    result = response.json()
```