From 64c3a1b528a88b4ae21bf3cbcff2537200477806 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Sun, 13 Sep 2026 20:03:39 +0200 Subject: Init --- tools/embed.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tools/embed.py (limited to 'tools/embed.py') diff --git a/tools/embed.py b/tools/embed.py new file mode 100644 index 0000000..bc4157e --- /dev/null +++ b/tools/embed.py @@ -0,0 +1,45 @@ +"""Turns the weight blob into a C source file so a binary carries no data file. + +Deliberately depends on nothing but the standard library: this runs inside the +container build, where the checkpoint, PyTorch and pyannote are not present and +should not have to be. Regenerating the blob itself needs all three and is a +separate step. + + python3 tools/embed.py pyseg_weights.bin src/weights_blob.c +""" + +import sys + +HEADER = """/* Generated by tools/embed.py from {name}. Do not edit. + * + * The packed weight blob, so a binary needs no data file at runtime. + * pyseg_create_from_file reads the identical bytes from disk instead. */ + +#include + +__attribute__((aligned(64))) +const unsigned char pyseg_weights_blob[] = {{ +""" + + +def main(argv: list[str]) -> int: + if len(argv) != 3: + print(__doc__.strip(), file=sys.stderr) + return 2 + + with open(argv[1], "rb") as f: + data = f.read() + + step = 24 + with open(argv[2], "w") as out: + out.write(HEADER.format(name=argv[1])) + for i in range(0, len(data), step): + out.write("".join(f"{b:d}," for b in data[i : i + step])) + out.write("\n") + out.write("};\n") + out.write(f"const size_t pyseg_weights_blob_len = {len(data)};\n") + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) -- cgit v1.3.1