Spaces:
Running
Running
fix: cuda device
Browse files- app-ocr.py +0 -3
- app.py +2 -1
- 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 |
-
|
|
|
43 |
|
44 |
# εε§ε樑εεεθ―ε¨
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
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")
|