Download run.py from failed09/bashkir-trocr-base: direct link, hf CLI and curl.
- Browser
- Download file 842 Bytes
-
https://huggingface.co/failed09/bashkir-trocr-base/resolve/main/run.py
- Command line
-
hf download hf://failed09/bashkir-trocr-base/run.py
-
curl -L -o run.py https://huggingface.co/failed09/bashkir-trocr-base/resolve/main/run.py
842 Bytes
| """Recognize one image locally and write UTF-8 text and JSON.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| from PIL import Image | |
| from runtime.engine import OCR | |
| def main(): | |
| p=argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('image',type=Path) | |
| p.add_argument('--backend',choices=['cpu','gpu','auto'],default='cpu') | |
| p.add_argument('--output',type=Path,default=Path('result.txt')) | |
| args=p.parse_args() | |
| with Image.open(args.image) as image:r=OCR(backend=args.backend).recognize(image,include_images=False) | |
| args.output.write_text(r['full_text']+'\n',encoding='utf-8') | |
| args.output.with_suffix('.json').write_text(json.dumps(r,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') | |
| print(f'Saved {args.output}; backend={r["backend"]}; lines={len(r["lines"])}') | |
| if __name__=='__main__':main() | |