| from transformers import AutoModel, AutoTokenizer |
| import torch |
|
|
|
|
| def extract_text(image_path): |
| if torch.cuda.is_available(): |
| device = torch.device('cuda') |
| else: |
| device = torch.device('cpu') |
|
|
| tokenizer = AutoTokenizer.from_pretrained('custom_got', |
| trust_remote_code=True |
| ) |
| model = AutoModel.from_pretrained('custom_got', |
| trust_remote_code=True, |
| low_cpu_mem_usage=True, |
| device_map=device.type, |
| use_safetensors=True, |
| |
| pad_token_id=tokenizer.eos_token_id, |
| ) |
| model.to(device) |
| image_file = image_path |
| |
| res = model.chat(tokenizer, image_file, ocr_type='ocr') |
| return res |
|
|