feat: publish downloadable wakeword trainer source
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""Write manifest-safe image/package/front-end evidence into the mounted run."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import platform
|
||||
import subprocess
|
||||
from importlib.metadata import distributions
|
||||
from pathlib import Path
|
||||
|
||||
from wakeword_training_image import collect_image_provenance
|
||||
|
||||
|
||||
def main() -> int:
|
||||
run_dir = Path("/run")
|
||||
request = json.loads((run_dir / "request.json").read_text(encoding="utf-8"))
|
||||
payload = request["request"]
|
||||
package_versions = {
|
||||
distribution.metadata["Name"].lower(): distribution.version
|
||||
for distribution in distributions()
|
||||
if distribution.metadata.get("Name")
|
||||
}
|
||||
frontend_assets = [
|
||||
path
|
||||
for path in Path("/usr/local/lib").glob("python*/site-packages/livekit/wakeword/**/*.onnx")
|
||||
if path.is_file()
|
||||
]
|
||||
cuda_version = "unknown"
|
||||
try:
|
||||
cuda_version = subprocess.check_output(["nvcc", "--version"], text=True).strip()
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
pass
|
||||
os_packages: list[str] = []
|
||||
try:
|
||||
os_packages = subprocess.check_output(
|
||||
["dpkg-query", "--show", "--showformat", "${Package}=${Version}\\n"], text=True
|
||||
).splitlines()
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
pass
|
||||
provenance = collect_image_provenance(
|
||||
dependency_lock_path=Path("/opt/jr-wakeword/requirements.wheelhouse.lock"),
|
||||
frontend_asset_paths=frontend_assets,
|
||||
installed_distributions=package_versions,
|
||||
image_digest=str(payload["runner_image_digest"]),
|
||||
python_version=platform.python_version(),
|
||||
cuda_version=cuda_version,
|
||||
os_packages=os_packages,
|
||||
)
|
||||
(run_dir / "image-provenance.json").write_text(
|
||||
json.dumps(provenance, sort_keys=True) + "\n", encoding="utf-8"
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user