Sync from davanstrien/uv-scripts via hub-sync
Browse files- xiaomi-ocr-0-saturate.py +5 -23
xiaomi-ocr-0-saturate.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# /// script
|
| 2 |
# requires-python = ">=3.11"
|
| 3 |
# dependencies = [
|
| 4 |
-
# "saturate[hf]==0.3.
|
| 5 |
# "pillow>=10",
|
| 6 |
# ]
|
| 7 |
#
|
|
@@ -79,8 +79,6 @@ import base64
|
|
| 79 |
import io
|
| 80 |
import os
|
| 81 |
import re
|
| 82 |
-
import shutil
|
| 83 |
-
import subprocess
|
| 84 |
import sys
|
| 85 |
from dataclasses import dataclass
|
| 86 |
|
|
@@ -495,25 +493,6 @@ def finalize_document(text: str) -> str:
|
|
| 495 |
return postprocess_otsl_tables(postprocess_math_delimiters(_clean_truncated_repeats(text)))
|
| 496 |
|
| 497 |
|
| 498 |
-
def sglang_command() -> list[str]:
|
| 499 |
-
"""Return the SGLang server command, using the image's Python rather than this script's venv."""
|
| 500 |
-
# The SGLang image keeps sglang in its own venv, first on PATH; `uv run` puts
|
| 501 |
-
# this script's venv in front, so look past it.
|
| 502 |
-
own_bin = os.path.realpath(os.path.join(sys.prefix, "bin"))
|
| 503 |
-
path = os.pathsep.join(
|
| 504 |
-
p for p in os.environ.get("PATH", "").split(os.pathsep) if os.path.realpath(p) != own_bin
|
| 505 |
-
)
|
| 506 |
-
python = shutil.which("python3", path=path)
|
| 507 |
-
found = python and subprocess.run([python, "-c", "import sglang"], check=False, capture_output=True).returncode == 0
|
| 508 |
-
if not found:
|
| 509 |
-
sys.exit(f"--engine sglang needs sglang: add --image {SERVING['images']['sglang']} to hf jobs uv run.")
|
| 510 |
-
return [
|
| 511 |
-
python, "-m", "sglang.launch_server", "--model-path", SERVING["model"],
|
| 512 |
-
"--context-length", str(SERVING["context"]), "--enable-metrics",
|
| 513 |
-
"--host", "127.0.0.1", "--port", "8000",
|
| 514 |
-
] # fmt: skip
|
| 515 |
-
|
| 516 |
-
|
| 517 |
def main():
|
| 518 |
ap = argparse.ArgumentParser(description="Xiaomi-OCR-0 batch OCR via saturate")
|
| 519 |
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
|
|
@@ -593,7 +572,10 @@ def main():
|
|
| 593 |
}
|
| 594 |
|
| 595 |
if args.engine == "sglang":
|
| 596 |
-
|
|
|
|
|
|
|
|
|
|
| 597 |
else:
|
| 598 |
extra = ["--max-model-len", str(SERVING["context"]), *SERVING["vllm_args"]]
|
| 599 |
engine = Engine(SERVING["model"], engine="vllm", extra_args=extra)
|
|
|
|
| 1 |
# /// script
|
| 2 |
# requires-python = ">=3.11"
|
| 3 |
# dependencies = [
|
| 4 |
+
# "saturate[hf]==0.3.1",
|
| 5 |
# "pillow>=10",
|
| 6 |
# ]
|
| 7 |
#
|
|
|
|
| 79 |
import io
|
| 80 |
import os
|
| 81 |
import re
|
|
|
|
|
|
|
| 82 |
import sys
|
| 83 |
from dataclasses import dataclass
|
| 84 |
|
|
|
|
| 493 |
return postprocess_otsl_tables(postprocess_math_delimiters(_clean_truncated_repeats(text)))
|
| 494 |
|
| 495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
def main():
|
| 497 |
ap = argparse.ArgumentParser(description="Xiaomi-OCR-0 batch OCR via saturate")
|
| 498 |
ap.add_argument("input_dataset", help="Input dataset repo id (rows with an image column)")
|
|
|
|
| 572 |
}
|
| 573 |
|
| 574 |
if args.engine == "sglang":
|
| 575 |
+
# saturate starts SGLang with the image's Python (the one that has sglang), not this
|
| 576 |
+
# script's venv; without the SGLang --image the server fails with "No module named sglang".
|
| 577 |
+
extra = ["--context-length", str(SERVING["context"]), "--host", "127.0.0.1"]
|
| 578 |
+
engine = Engine(SERVING["model"], engine="sglang", extra_args=extra)
|
| 579 |
else:
|
| 580 |
extra = ["--max-model-len", str(SERVING["context"]), *SERVING["vllm_args"]]
|
| 581 |
engine = Engine(SERVING["model"], engine="vllm", extra_args=extra)
|