Spaces:
Running on Zero

IDP-Machine-learning-demo / test_space.py
mrrobot2610's picture
Upload folder using huggingface_hub
d3788d8 verified
Raw History Blame Contribute Delete
1.28 kB
"""Smoke-test the real deployed Space, including OCR and invalid inputs."""
from pathlib import Path
from gradio_client import Client, handle_file
client = Client("mrrobot2610/IDP-Machine-learning-demo", httpx_kwargs={"timeout": 300})
client.view_api()
text = "INVOICE #INV-12345\nDate: 28/11/2025\nTotal: $1,250.00\nTax: $125.00"
result = client.predict(text, api_name="/process_text")[2]
assert result["document_type"] == "INVOICE", result
assert result["fields"]["invoice_number"]["value"] == "INV-12345", result
assert "rule-based" in result["mode"], result
image = Path(__file__).parent / "examples" / "invoice.png"
result = client.predict(handle_file(image), api_name="/process_image")[2]
assert result["document_type"] == "INVOICE", result
assert "12345" in result["fields"]["invoice_number"]["value"], result
assert "1250" in result["raw_ocr_text"].replace(",", ""), result
for endpoint, value, message in [("/process_text", "", "No text found"), ("/process_image", None, "Upload")]:
try:
client.predict(value, api_name=endpoint)
except Exception as exc:
assert message in str(exc), str(exc)
else:
raise AssertionError(f"{endpoint} accepted empty input")
print("PASS: live text extraction, image OCR, and empty-input validation")