Spaces:
Running
on
Zero
Running
on
Zero
automation
commited on
Commit
·
a1cd61c
1
Parent(s):
87a21f1
Upd API document
Browse files
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
API.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## DeepSeek-OCR WebUI – HTTP API Usage
|
| 2 |
+
|
| 3 |
+
This Space exposes a programmatic API that mirrors the WebUI flow. You can call it using cURL or Python.
|
| 4 |
+
|
| 5 |
+
Base URL: `https://binkhoale1812-deepseekocr.hf.space`
|
| 6 |
+
|
| 7 |
+
### Python (recommended)
|
| 8 |
+
|
| 9 |
+
```python
|
| 10 |
+
from gradio_client import Client
|
| 11 |
+
|
| 12 |
+
client = Client("BinKhoaLe1812/DeepSeekOCR", hf_token="<HF_TOKEN>")
|
| 13 |
+
|
| 14 |
+
result = client.predict(
|
| 15 |
+
image=None, # or a local image path/URL
|
| 16 |
+
file_path="/absolute/path/to/doc.pdf", # local PDF or image path
|
| 17 |
+
mode_label="Base", # one of: Gundam, Tiny, Small, Base, Large
|
| 18 |
+
task_label="Markdown", # one of: Markdown, Tables, Locate, Describe, Custom
|
| 19 |
+
custom_prompt="", # required for Custom/Locate
|
| 20 |
+
dpi_val=300, # PDF DPI
|
| 21 |
+
page_range_text="", # e.g. "1-3,5"; empty = all pages
|
| 22 |
+
embed=True, # embed detected figures into Markdown
|
| 23 |
+
hiacc=False, # high-accuracy second pass
|
| 24 |
+
sep_pages=True, # insert --- between pages
|
| 25 |
+
api_name="/run",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Save Markdown to a file
|
| 29 |
+
markdown = result[1]
|
| 30 |
+
with open("output.md", "w", encoding="utf-8") as f:
|
| 31 |
+
f.write(markdown or "")
|
| 32 |
+
print("Wrote output.md")
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### Raw HTTP via cURL
|
| 36 |
+
|
| 37 |
+
The Gradio REST API expects a two-step process for files:
|
| 38 |
+
1) Upload the file to `/upload` to get a server-side path
|
| 39 |
+
2) Call the function route with a JSON body including that path
|
| 40 |
+
|
| 41 |
+
Replace `<HF_TOKEN>` with your token if the Space requires auth.
|
| 42 |
+
|
| 43 |
+
Step 1 – Upload the file:
|
| 44 |
+
```bash
|
| 45 |
+
curl -s -X POST \
|
| 46 |
+
-H "Authorization: Bearer <HF_TOKEN>" \
|
| 47 |
+
-F "files[]=@/absolute/path/to/doc.pdf" \
|
| 48 |
+
https://binkhoale1812-deepseekocr.hf.space/upload
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
This returns JSON like:
|
| 52 |
+
```json
|
| 53 |
+
{
|
| 54 |
+
"files": [
|
| 55 |
+
{"name": "/tmp/gradio/1234/filename.pdf"}
|
| 56 |
+
]
|
| 57 |
+
}
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
Capture the `name` field as `SERVER_PATH`.
|
| 61 |
+
|
| 62 |
+
Step 2 – Invoke the API (`api_name` is `/run`, so route is `/run/run`):
|
| 63 |
+
```bash
|
| 64 |
+
curl -s -X POST \
|
| 65 |
+
-H "Authorization: Bearer <HF_TOKEN>" \
|
| 66 |
+
-H "Content-Type: application/json" \
|
| 67 |
+
-d '{
|
| 68 |
+
"data": [
|
| 69 |
+
null,
|
| 70 |
+
{"path": "SERVER_PATH"},
|
| 71 |
+
"Base",
|
| 72 |
+
"Markdown",
|
| 73 |
+
"",
|
| 74 |
+
300,
|
| 75 |
+
"",
|
| 76 |
+
true,
|
| 77 |
+
false,
|
| 78 |
+
true
|
| 79 |
+
]
|
| 80 |
+
}' \
|
| 81 |
+
https://binkhoale1812-deepseekocr.hf.space/run/run \
|
| 82 |
+
| python3 - <<'PY'
|
| 83 |
+
import sys, json
|
| 84 |
+
resp=json.loads(sys.stdin.read())
|
| 85 |
+
md = resp.get("data", [None, None])[1]
|
| 86 |
+
with open("output.md", "w", encoding="utf-8") as f:
|
| 87 |
+
f.write(md or "")
|
| 88 |
+
print("Wrote output.md")
|
| 89 |
+
PY
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
The response is a JSON envelope whose `data` contains 8 outputs. The second element (`data[1]`) is the Markdown string. Both examples above save it to `output.md`. If you enabled `sep_pages`, pages are separated by `---`. The ZIP path for per-page Markdown is in `data[7]`.
|
| 93 |
+
|
| 94 |
+
### Notes
|
| 95 |
+
- The server performs per-page batching with retries under the hood to respect 120s GPU windows.
|
| 96 |
+
- For large PDFs (up to ~200 pages), prefer `mode_label="Base"` or `"Gundam"` with `dpi_val=300`.
|
| 97 |
+
- Use `page_range_text` to subset processing, e.g. `"1-10, 15, 20-25"`.
|
| 98 |
+
|