k4d3 commited on
Commit
8db8d20
1 Parent(s): 988d14b

start ocr, gallery-dl override

Browse files

Signed-off-by: Balazs Horvath <acsipont@gmail.com>

Files changed (3) hide show
  1. .zshrc +1 -0
  2. ocr +33 -0
  3. zsh/gallery-dl.zsh +10 -0
.zshrc CHANGED
@@ -913,6 +913,7 @@ filePath = '$filePath'
913
  print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
914
  }
915
 
 
916
  source ~/toolkit/zsh/png2mp4.zsh
917
 
918
  # Function: c
 
913
  print(json.loads(safetensors.safe_open(filePath, 'np').metadata().get('ss_seed', 'Not found')))"
914
  }
915
 
916
+ source ~/toolkit/zsh/gallery-dl.zsh
917
  source ~/toolkit/zsh/png2mp4.zsh
918
 
919
  # Function: c
ocr ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ from transformers import AutoModel, AutoTokenizer
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
6
+ 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)
7
+ model = model.eval().cuda()
8
+
9
+
10
+ # input your test image
11
+ image_file = 'xxx.jpg'
12
+
13
+ # plain texts OCR
14
+ res = model.chat(tokenizer, image_file, ocr_type='ocr')
15
+
16
+ # format texts OCR:
17
+ # res = model.chat(tokenizer, image_file, ocr_type='format')
18
+
19
+ # fine-grained OCR:
20
+ # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')
21
+ # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')
22
+ # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')
23
+ # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')
24
+
25
+ # multi-crop OCR:
26
+ # res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')
27
+ # res = model.chat_crop(tokenizer, image_file, ocr_type='format')
28
+
29
+ # render the formatted OCR results:
30
+ # res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')
31
+
32
+ print(res)
33
+
zsh/gallery-dl.zsh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Override the gallery-dl command to change the directory to ~/datasets
2
+ # before executing the original command
3
+ function gallery-dl() {
4
+ # Change to the ~/datasets directory
5
+ cd ~/datasets
6
+
7
+ # Execute the original gallery-dl command with all passed arguments
8
+ command gallery-dl "$@"
9
+ }
10
+