Mageia commited on
Commit
546c454
Β·
unverified Β·
1 Parent(s): d1d6f35

fix: cuda device

Browse files
Files changed (3) hide show
  1. app-ocr.py +0 -3
  2. app.py +2 -1
  3. got_ocr.py +10 -4
app-ocr.py CHANGED
@@ -6,9 +6,6 @@ import time
6
  import uuid
7
  from pathlib import Path
8
 
9
- # import numpy as np
10
- # import tempfile
11
- # from PIL import Image
12
  import gradio as gr
13
  from modelscope import AutoModel, AutoTokenizer
14
 
 
6
  import uuid
7
  from pathlib import Path
8
 
 
 
 
9
  import gradio as gr
10
  from modelscope import AutoModel, AutoTokenizer
11
 
app.py CHANGED
@@ -11,7 +11,8 @@ from transformers import AutoConfig, AutoModel, AutoTokenizer
11
  from got_ocr import got_ocr
12
 
13
  # εˆε§‹εŒ–ζ¨‘εž‹ε’Œεˆ†θ―ε™¨
14
- model_name = "stepfun-ai/GOT-OCR2_0"
 
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
 
17
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
 
11
  from got_ocr import got_ocr
12
 
13
  # εˆε§‹εŒ–ζ¨‘εž‹ε’Œεˆ†θ―ε™¨
14
+ # model_name = "stepfun-ai/GOT-OCR2_0"
15
+ model_name = "ucaslcl/GOT-OCR2_0"
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
 
18
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
got_ocr.py CHANGED
@@ -39,12 +39,18 @@ def got_ocr(model, tokenizer, image_path, got_mode="format texts OCR", fine_grai
39
 
40
  # 使用瀺例
41
  if __name__ == "__main__":
42
- from modelscope import AutoModel, AutoTokenizer
 
43
 
44
  # εˆε§‹εŒ–ζ¨‘εž‹ε’Œεˆ†θ―ε™¨
45
- tokenizer = AutoTokenizer.from_pretrained("stepfun-ai/GOT-OCR2_0", trust_remote_code=True)
46
- model = AutoModel.from_pretrained("stepfun-ai/GOT-OCR2_0", trust_remote_code=True, low_cpu_mem_usage=True, device_map="cuda", use_safetensors=True)
47
- model = model.eval().cuda()
 
 
 
 
 
48
 
49
  image_path = "path/to/your/image.png"
50
  result, html = got_ocr(model, tokenizer, image_path, got_mode="format texts OCR")
 
39
 
40
  # 使用瀺例
41
  if __name__ == "__main__":
42
+ import torch
43
+ from transformers import AutoConfig, AutoModel, AutoTokenizer
44
 
45
  # εˆε§‹εŒ–ζ¨‘εž‹ε’Œεˆ†θ―ε™¨
46
+ model_name = "stepfun-ai/GOT-OCR2_0"
47
+ device = "cuda" if torch.cuda.is_available() else "cpu"
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
50
+ config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
51
+ model = AutoModel.from_pretrained(model_name, trust_remote_code=True, low_cpu_mem_usage=True, device_map="cuda", use_safetensors=True)
52
+ model = model.eval().to(device)
53
+ model.config.pad_token_id = tokenizer.eos_token_id
54
 
55
  image_path = "path/to/your/image.png"
56
  result, html = got_ocr(model, tokenizer, image_path, got_mode="format texts OCR")