Download src/protocol_pilot/bom.py from idiakhoas/protocolcolpilot: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/datasets/idiakhoas/protocolcolpilot/resolve/main/src/protocol_pilot/bom.py
- Command line
-
hf download hf://datasets/idiakhoas/protocolcolpilot/src/protocol_pilot/bom.py
-
curl -L -o bom.py https://huggingface.co/datasets/idiakhoas/protocolcolpilot/resolve/main/src/protocol_pilot/bom.py
1.01 kB
| from __future__ import annotations | |
| import json | |
| import click | |
| from pathlib import Path | |
| from slugify import slugify | |
| from .extract import parse_markdown | |
| DEFAULT_ALTS = [ | |
| {"vendor": "Vendor A", "catalog_number": "TBD"}, | |
| {"vendor": "Vendor B", "catalog_number": "TBD"}, | |
| ] | |
| def main(protocol_md, out_path): | |
| proto = parse_markdown(Path(protocol_md).read_text(encoding="utf-8")) | |
| items = [] | |
| for r in proto.reagents: | |
| items.append({ | |
| "name": r.name, | |
| "amount": r.amount, | |
| "unit": r.unit, | |
| "alternatives": DEFAULT_ALTS, | |
| }) | |
| payload = {"protocol": slugify(proto.title), "items": items} | |
| if out_path: | |
| Path(out_path).write_text(json.dumps(payload, indent=2), encoding="utf-8") | |
| else: | |
| print(json.dumps(payload, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |