Nos7 commited on
Commit
3867e7f
1 Parent(s): e466c19

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +37 -0
main.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch==2.0.1
2
+ torchvision==0.15.2
3
+ transformers==4.37.2
4
+ tiktoken==0.6.0
5
+ verovio==4.3.1
6
+ accelerate==0.28.0
7
+
8
+ from transformers import AutoModel, AutoTokenizer
9
+
10
+ tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
11
+ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
12
+ model = model.eval().cuda()
13
+
14
+
15
+ # input your test image
16
+ image_file = 'radio.jpeg'
17
+
18
+ # plain texts OCR
19
+ res = model.chat(tokenizer, image_file, ocr_type='ocr')
20
+
21
+ # format texts OCR:
22
+ # res = model.chat(tokenizer, image_file, ocr_type='format')
23
+
24
+ # fine-grained OCR:
25
+ # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')
26
+ # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')
27
+ # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')
28
+ # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')
29
+
30
+ # multi-crop OCR:
31
+ # res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')
32
+ # res = model.chat_crop(tokenizer, image_file, ocr_type='format')
33
+
34
+ # render the formatted OCR results:
35
+ # res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')
36
+
37
+ print(res)