Download example.py from Ismantic/Handwritten: direct link, hf CLI and curl.
- Browser
- Download file 604 Bytes
-
https://huggingface.co/Ismantic/Handwritten/resolve/main/example.py
- Command line
-
hf download hf://Ismantic/Handwritten/example.py
-
curl -L -o example.py https://huggingface.co/Ismantic/Handwritten/resolve/main/example.py
604 Bytes
| """用发布包识别一张白底黑字图片。""" | |
| import argparse | |
| from pathlib import Path | |
| from inference import HCCRRecognizer | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("image", type=Path) | |
| parser.add_argument("--model-dir", type=Path, default=Path(".")) | |
| parser.add_argument("-k", type=int, default=10) | |
| args = parser.parse_args() | |
| model = HCCRRecognizer.from_pretrained(args.model_dir) | |
| for char, probability in model.predict_file(args.image, k=args.k): | |
| print(f"{char}\t{probability:.2%}") | |
| if __name__ == "__main__": | |
| main() | |