Instructions to use datalab-to/surya-parsebench-rl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use datalab-to/surya-parsebench-rl with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="datalab-to/surya-parsebench-rl") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("datalab-to/surya-parsebench-rl") model = AutoModelForMultimodalLM.from_pretrained("datalab-to/surya-parsebench-rl", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use datalab-to/surya-parsebench-rl with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "datalab-to/surya-parsebench-rl" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "datalab-to/surya-parsebench-rl", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/datalab-to/surya-parsebench-rl
- SGLang
How to use datalab-to/surya-parsebench-rl with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "datalab-to/surya-parsebench-rl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "datalab-to/surya-parsebench-rl", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "datalab-to/surya-parsebench-rl" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "datalab-to/surya-parsebench-rl", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use datalab-to/surya-parsebench-rl with Docker Model Runner:
docker model run hf.co/datalab-to/surya-parsebench-rl
Download code/bench.sh from datalab-to/surya-parsebench-rl: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/datalab-to/surya-parsebench-rl/resolve/main/code/bench.sh
- Command line
-
hf download hf://datalab-to/surya-parsebench-rl/code/bench.sh
-
curl -L -o bench.sh https://huggingface.co/datalab-to/surya-parsebench-rl/resolve/main/code/bench.sh
1.97 kB
| # Score the Surya checkpoint currently served on :8000 on the four ParseBench | |
| # dimensions this project targets (charts excluded). Usage: [PORT=8000] [CONC=24] bench.sh <tag> [--test] | |
| # Results land in output/<tag>/ and a scorecard in output/<tag>/SCORECARD.txt. | |
| set -u | |
| cd ~/parsebench_rl | |
| TAG="$1"; shift | |
| EXTRA="${*:-}" | |
| export PYTHONPATH=$PWD SURYA_VLLM_URL=http://127.0.0.1:${PORT:-8000}/v1 SURYA_VLLM_MODEL=surya SURYA_PROMPT=${SURYA_PROMPT:-short} SURYA_FIGTEXT=${SURYA_FIGTEXT:-0} | |
| PB=.venv/bin/parse-bench | |
| OUT=output/$TAG | |
| for g in text_formatting text_content table layout; do | |
| $PB run surya_vllm --group $g --output_dir output_run_$TAG --max_concurrent ${CONC:-24} \ | |
| --open_report False $EXTRA > output_run_$TAG.$g.log 2>&1 | |
| done | |
| mkdir -p $OUT | |
| cp -r output_run_$TAG/surya_vllm/* $OUT/ 2>/dev/null | |
| for g in text_formatting text_content table; do | |
| $PB evaluation run $OUT --group $g --test_cases_dir data > /dev/null 2>&1 | |
| cp $OUT/_evaluation_report.json $OUT/_rep_$g.json | |
| done | |
| $PB evaluation run $OUT --group layout --product_type layout_detection --test_cases_dir data > /dev/null 2>&1 | |
| cp $OUT/_evaluation_report.json $OUT/_rep_layout.json | |
| .venv/bin/python - "$OUT" <<'PY' | tee $OUT/SCORECARD.txt | |
| import json, sys | |
| out = sys.argv[1] | |
| keys = [("table", "avg_grits_trm_composite", "Tables"), | |
| ("text_content", "avg_content_faithfulness", "Content"), | |
| ("text_formatting", "avg_semantic_formatting", "SemFmt"), | |
| ("layout", "avg_layout_element_rule_pass_rate", "VisGnd")] | |
| vals = [] | |
| for g, k, lab in keys: | |
| try: | |
| r = json.load(open(f"{out}/_rep_{g}.json")) | |
| v = r["aggregate_metrics"].get(k, 0) * 100 | |
| n = r.get("successful"); f = r.get("failed") | |
| except Exception as e: | |
| v, n, f = float("nan"), "?", str(e)[:40] | |
| vals.append(v) | |
| print(f"{lab:8s} {v:6.2f} (ok={n} failed={f})") | |
| print(f"{'MEAN4':8s} {sum(vals)/4:6.2f} (LlamaParse Agentic Plus = 89.21, Surya OCR 2 published = 75.55)") | |
| PY | |