Instructions to use SamJoshua/injection-guard-fix-recipe with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SamJoshua/injection-guard-fix-recipe with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="SamJoshua/injection-guard-fix-recipe")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("SamJoshua/injection-guard-fix-recipe", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download scripts/privacy_check.py from SamJoshua/injection-guard-fix-recipe: direct link, hf CLI and curl.
- Browser
- Download file 3.38 kB
-
https://huggingface.co/SamJoshua/injection-guard-fix-recipe/resolve/main/scripts/privacy_check.py
- Command line
-
hf download hf://SamJoshua/injection-guard-fix-recipe/scripts/privacy_check.py
-
curl -L -o privacy_check.py https://huggingface.co/SamJoshua/injection-guard-fix-recipe/resolve/main/scripts/privacy_check.py
3.38 kB
| """Fail if any committed (or about-to-be-committed) file contains identifying information. | |
| The identifiers to block are never written into the repo: they are derived at runtime from the same | |
| environment variables the pipeline reads (dataset / model ids and the pinned revision), plus optional | |
| extra terms in PRIVACY_EXTRA_TERMS (comma-separated). Independently of the environment, it also blocks | |
| literal email addresses and links to model/code hosting profiles. | |
| python scripts/privacy_check.py # tracked + untracked-not-ignored files | |
| python scripts/privacy_check.py --staged # exactly what `git commit` would record (pre-commit hook) | |
| """ | |
| import os | |
| import re | |
| import subprocess | |
| import sys | |
| ID_VARS = ["DATASET_MINIMAL_PAIRS", "DATASET_TERSE", "DATASET_INDIRECT", "BASE_MODEL", "BASE_MODEL_REVISION"] | |
| EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}") | |
| HOSTING = re.compile(r"(?<![A-Za-z0-9.-])(?:huggingface\.co|hf\.co|github\.com|gitlab\.com|twitter\.com|x\.com|linkedin\.com)/[A-Za-z0-9_.-]+", re.I) | |
| MIN_PART = 5 | |
| def split_parts(s): | |
| parts = re.split(r"[-_./\s]+|(?<=[a-z])(?=[A-Z])", s) | |
| return [p for p in parts if len(p) >= MIN_PART] | |
| def forbidden_terms(): | |
| terms = set() | |
| for var in ID_VARS: | |
| v = os.environ.get(var, "").strip() | |
| if not v: | |
| continue | |
| terms.add(v) | |
| if "/" in v: | |
| owner, name = v.split("/", 1) | |
| terms.update([owner, name]) | |
| terms.update(split_parts(owner)) | |
| for t in os.environ.get("PRIVACY_EXTRA_TERMS", "").split(","): | |
| if t.strip(): | |
| terms.add(t.strip()) | |
| return sorted(terms, key=len, reverse=True) | |
| def git(*args): | |
| return subprocess.run(["git", *args], capture_output=True, text=True, check=True).stdout | |
| def files_to_scan(staged): | |
| if staged: | |
| names = git("diff", "--cached", "--name-only", "--diff-filter=ACMR").split("\n") | |
| return [(n, lambda n=n: git("show", f":{n}")) for n in names if n] | |
| names = set(git("ls-files").split("\n")) | set(git("ls-files", "--others", "--exclude-standard").split("\n")) | |
| out = [] | |
| for n in sorted(x for x in names if x and os.path.isfile(x)): | |
| out.append((n, lambda n=n: open(n, encoding="utf-8", errors="replace").read())) | |
| return out | |
| def main(): | |
| staged = "--staged" in sys.argv | |
| terms = forbidden_terms() | |
| missing = [v for v in ID_VARS if not os.environ.get(v)] | |
| if missing: | |
| print(f"privacy_check: WARNING env vars not set, their identifiers are not checked: {missing}", file=sys.stderr) | |
| pats = [(re.compile(re.escape(t), re.I), "identifier") for t in terms] + [(EMAIL, "email"), (HOSTING, "profile link")] | |
| hits = 0 | |
| for name, read in files_to_scan(staged): | |
| try: | |
| text = read() | |
| except (subprocess.CalledProcessError, UnicodeDecodeError): | |
| continue | |
| for ln, line in enumerate(text.split("\n"), 1): | |
| for pat, kind in pats: | |
| if pat.search(line): | |
| hits += 1 | |
| print(f"privacy_check: {kind} in {name}:{ln}", file=sys.stderr) | |
| if hits: | |
| print(f"privacy_check: FAILED ({hits} hits)", file=sys.stderr) | |
| sys.exit(1) | |
| print(f"privacy_check: ok ({len(terms)} runtime identifiers + email/profile-link patterns)") | |
| if __name__ == "__main__": | |
| main() | |