MCPcopy
hub / github.com/stas00/ml-engineering / unpack

Function unpack

debug/tiny-scripts/general-pmd-ds-unpack.py:57–80  ·  view source on GitHub ↗
(args, idx, row)

Source from the content-addressed store, hash-verified

55 if '-' in i else [int(i)]) for i in s.split(',')), [])
56
57def unpack(args, idx, row):
58 #pprint(row)
59
60 path = f"{args.target_path}/{idx}"
61 Path(path).mkdir(parents=True, exist_ok=True)
62
63 # all items are text, except 'image'
64
65 img = row["image"]
66 basename = f"{path}/image"
67 ext = "null" if img is None else "jpg"
68 file = f"{basename}.{ext}"
69 with open(file, "w") as fh:
70 if img is not None:
71 img.save(fh, 'jpeg')
72
73 for col in ['meta', 'source', 'text']:
74 item = row[col]
75 basename = f"{path}/{col}"
76 ext = "null" if item is None else "txt"
77 file = f"{basename}.{ext}"
78 with open(file, "w") as fh:
79 if item is not None:
80 fh.write(item)
81
82def dump_example_shapes(idx, row):
83 """ dump the row stats """

Callers 1

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected