Download predict.py from Kamlesh21/cti-verify-file-svm: direct link, hf CLI and curl.
- Browser
- Download file 597 Bytes
-
https://huggingface.co/Kamlesh21/cti-verify-file-svm/resolve/main/predict.py
- Command line
-
hf download hf://Kamlesh21/cti-verify-file-svm/predict.py
-
curl -L -o predict.py https://huggingface.co/Kamlesh21/cti-verify-file-svm/resolve/main/predict.py
597 Bytes
| """Score a file with the CTI Verify file classifiers. | |
| pip install -r requirements.txt | |
| python predict.py suspicious.exe # a Windows program, a Linux program or a PDF | |
| """ | |
| import json | |
| import sys | |
| from api import file_svm | |
| MAGIC = {b"MZ": "exe", b"\x7fELF": "elf", b"%PDF": "pdf"} | |
| data = open(sys.argv[1], "rb").read() | |
| kind = next((k for m, k in MAGIC.items() if data.startswith(m)), None) | |
| if not kind: | |
| sys.exit("not a Windows program, a Linux program or a PDF: these models score only those") | |
| print(json.dumps(file_svm.score(kind, data), indent=2, default=str)) | |