Download bhed/cli.py from MindMapDigital/Bhed-v0.1: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/MindMapDigital/Bhed-v0.1/resolve/main/bhed/cli.py
- Command line
-
hf download hf://MindMapDigital/Bhed-v0.1/bhed/cli.py
-
curl -L -o cli.py https://huggingface.co/MindMapDigital/Bhed-v0.1/resolve/main/bhed/cli.py
1.44 kB
| """Redact one text query from the command line.""" | |
| import argparse | |
| import json | |
| import sys | |
| from bhed.model import Bhed | |
| def main(argv=None): | |
| parser = argparse.ArgumentParser(prog="bhed", description="Bhed multilingual PII redaction") | |
| parser.add_argument("text", nargs="*", help="Text to redact (or pass on stdin)") | |
| parser.add_argument("--source", default=None, help="Local model dir or Hub id") | |
| parser.add_argument("--max-new-tokens", type=int, default=256) | |
| parser.add_argument("--json", action="store_true", help="Print full analyze() JSON") | |
| parser.add_argument("--device", default=None) | |
| args = parser.parse_args(argv) | |
| text = " ".join(args.text).strip() or sys.stdin.read().strip() | |
| if not text: | |
| parser.error("pass text as arguments or on stdin") | |
| model = Bhed(source=args.source, device=args.device) | |
| if args.json: | |
| result = model.analyze(text, max_new_tokens=args.max_new_tokens) | |
| print(json.dumps({ | |
| "blocked": result["blocked"], | |
| "sanitized": result["sanitized"], | |
| "mapping": result["mapping"], | |
| "model_output": result["model_output"], | |
| "flags": {k: v for k, v in result["flags"].items() if v and k != "parsed"}, | |
| }, ensure_ascii=False, indent=2)) | |
| sys.exit(2 if result["blocked"] else 0) | |
| print(model.redact(text, max_new_tokens=args.max_new_tokens)) | |
| if __name__ == "__main__": | |
| main() | |