Imagt / smoke_test.py
openmodelai's picture
Upload 10 files
755023e verified
Raw History Blame Contribute Delete
1.08 kB
"""Smoke-тест Image: извлечение весов (если нужно) + OCR примера.
Запуск:
python tests/smoke_test.py
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from image_text import ImageEngine # noqa: E402
SAMPLE = ROOT / "examples" / "sample.png"
def main() -> int:
model_dir = ROOT / "model"
if not (model_dir / "ch_PP-OCRv4_det_infer.onnx").exists():
print("Веса не найдены — извлекаю scripts/build_model.py ...")
subprocess.run([sys.executable, str(ROOT / "scripts" / "build_model.py")], check=True)
engine = ImageEngine()
result = engine.ocr(SAMPLE)
text = result["text"]
print("Извлеченный текст:", repr(text))
for needle in ("Hello", "World", "123"):
assert needle in text, f"В результатах нет «{needle}»"
print("SMOKE TEST OK")
return 0
if __name__ == "__main__":
sys.exit(main())