Spaces:
Configuration error
Configuration error
Download scripts/test_trocr_load.py from Sivaneshakumar/sanjeevani-api: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/scripts/test_trocr_load.py
- Command line
-
hf download hf://spaces/Sivaneshakumar/sanjeevani-api/scripts/test_trocr_load.py
-
curl -L -o test_trocr_load.py https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/scripts/test_trocr_load.py
1.73 kB
| from pathlib import Path | |
| import torch | |
| from transformers import ( | |
| TrOCRProcessor, | |
| VisionEncoderDecoderModel, | |
| ) | |
| BASE_DIR = Path(__file__).resolve().parents[1] | |
| MODEL_PATH = ( | |
| BASE_DIR | |
| / "models" | |
| / "pretrained" | |
| / "trocr" | |
| ) | |
| print("=" * 70) | |
| print("SANJEEVANI - TrOCR LOAD TEST") | |
| print("=" * 70) | |
| print("Model:", MODEL_PATH) | |
| print( | |
| "CUDA:", | |
| torch.cuda.is_available() | |
| ) | |
| if torch.cuda.is_available(): | |
| print( | |
| "GPU:", | |
| torch.cuda.get_device_name(0) | |
| ) | |
| # ------------------------------------------------------------ | |
| # PROCESSOR | |
| # ------------------------------------------------------------ | |
| print("\nLoading processor...") | |
| processor = TrOCRProcessor.from_pretrained( | |
| str(MODEL_PATH) | |
| ) | |
| print("Processor loaded successfully.") | |
| # ------------------------------------------------------------ | |
| # MODEL | |
| # ------------------------------------------------------------ | |
| print("\nLoading model...") | |
| model = VisionEncoderDecoderModel.from_pretrained( | |
| str(MODEL_PATH) | |
| ) | |
| print("Model loaded successfully.") | |
| # ------------------------------------------------------------ | |
| # GPU | |
| # ------------------------------------------------------------ | |
| if torch.cuda.is_available(): | |
| model = model.to("cuda") | |
| print( | |
| "\nModel moved to GPU successfully." | |
| ) | |
| # ------------------------------------------------------------ | |
| # SUMMARY | |
| # ------------------------------------------------------------ | |
| print("\n" + "=" * 70) | |
| print("SUCCESS") | |
| print("=" * 70) | |
| print("TrOCR processor: OK") | |
| print("TrOCR model: OK") | |
| if torch.cuda.is_available(): | |
| print("CUDA: OK") | |
| print( | |
| "GPU: " | |
| +torch.cuda.get_device_name(0) | |
| ) | |
| print("=" * 70) | |