Instructions to use gdelatournelle/laya-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Laya
How to use gdelatournelle/laya-onnx with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download tests/test_verify.py from gdelatournelle/laya-onnx: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/gdelatournelle/laya-onnx/resolve/main/tests/test_verify.py
- Command line
-
hf download hf://gdelatournelle/laya-onnx/tests/test_verify.py
-
curl -L -o test_verify.py https://huggingface.co/gdelatournelle/laya-onnx/resolve/main/tests/test_verify.py
2.07 kB
| import json | |
| from laya_onnx.verify import load_manifest, sha256_file, verify_bundle | |
| def _manifest(tmp_path, payload: bytes): | |
| file_path = tmp_path / "laya_config.json" | |
| file_path.write_bytes(payload) | |
| manifest = { | |
| "algorithm": "sha256", | |
| "files": {"laya_config.json": {"size": len(payload), "sha256": sha256_file(file_path)}}, | |
| } | |
| manifest_path = tmp_path / "manifest.json" | |
| manifest_path.write_text(json.dumps(manifest), encoding="utf-8") | |
| return file_path, manifest_path | |
| def test_verify_bundle_ok(tmp_path): | |
| _, manifest_path = _manifest(tmp_path, b'{"max_len": 64}\n') | |
| ok, rows = verify_bundle(tmp_path, manifest_path) | |
| assert ok is True | |
| assert rows == [{"file": "laya_config.json", "status": "ok", "sha256": rows[0]["sha256"]}] | |
| def test_verify_bundle_detects_tampering(tmp_path): | |
| file_path, manifest_path = _manifest(tmp_path, b'{"max_len": 64}\n') | |
| file_path.write_bytes(b'{"max_len": 128}\n') # same directory, changed bytes | |
| ok, rows = verify_bundle(tmp_path, manifest_path) | |
| assert ok is False | |
| assert rows[0]["status"] == "size-mismatch" | |
| def test_verify_bundle_hash_mismatch(tmp_path): | |
| file_path, manifest_path = _manifest(tmp_path, b"abc") | |
| file_path.write_bytes(b"abd") # same size, different bytes | |
| ok, rows = verify_bundle(tmp_path, manifest_path) | |
| assert ok is False | |
| assert rows[0]["status"] == "sha256-mismatch" | |
| def test_verify_bundle_missing_file(tmp_path): | |
| _, manifest_path = _manifest(tmp_path, b"x") | |
| (tmp_path / "laya_config.json").unlink() | |
| ok, rows = verify_bundle(tmp_path, manifest_path) | |
| assert ok is False | |
| assert rows[0]["status"] == "missing" | |
| def test_bundled_manifest_is_wellformed(): | |
| manifest = load_manifest() | |
| assert manifest["repo"] == "receptron/laya-onnx" | |
| assert manifest["algorithm"] == "sha256" | |
| assert "laya.onnx" in manifest["files"] | |
| for name, entry in manifest["files"].items(): | |
| assert len(entry["sha256"]) == 64 and entry["size"] > 0 | |