Spaces:
Zienab
/
Runtime error

Zienab commited on
Commit
5ae7a14
·
verified ·
1 Parent(s): 0886032

Update app/utils.py

Browse files
Files changed (1) hide show
  1. app/utils.py +12 -15
app/utils.py CHANGED
@@ -1,36 +1,33 @@
1
- from transformers import AutoModel, AutoTokenizer
2
  import os
3
- import torch
4
- from PIL import Image
5
 
6
  class OCRModel:
7
  _instance = None
8
-
9
  def __new__(cls):
10
  if cls._instance is None:
11
  cls._instance = super(OCRModel, cls).__new__(cls)
12
  cls._instance.initialize()
13
  return cls._instance
14
-
15
  def initialize(self):
16
  model_path = os.getenv('MODEL_PATH', 'RufusRubin777/GOT-OCR2_0_CPU')
17
 
18
- self.tokenizer = AutoTokenizer.from_pretrained(
19
- model_path,
20
- trust_remote_code=True,
 
 
21
  local_files_only=False
22
  )
23
 
24
- self.model = AutoModel.from_pretrained(
25
  model_path,
26
- trust_remote_code=True,
27
- low_cpu_mem_usage=True,
28
- device_map='cpu',
29
- use_safetensors=True,
30
- pad_token_id=self.tokenizer.eos_token_id
31
  )
32
 
33
- self.model = self.model.eval()
34
 
35
  def process_image(self, image_stream):
36
  try:
 
 
1
  import os
2
+ from transformers import AutoModel, AutoTokenizer
3
+ from transformers_modules.RufusRubin777.GOT_OCR2_0_CPU.modeling_GOT import GOTModel, GOTConfig
4
 
5
  class OCRModel:
6
  _instance = None
7
+
8
  def __new__(cls):
9
  if cls._instance is None:
10
  cls._instance = super(OCRModel, cls).__new__(cls)
11
  cls._instance.initialize()
12
  return cls._instance
13
+
14
  def initialize(self):
15
  model_path = os.getenv('MODEL_PATH', 'RufusRubin777/GOT-OCR2_0_CPU')
16
 
17
+ # تحميل النموذج بالطريقة الصحيحة
18
+ config = GOTConfig.from_pretrained(model_path)
19
+ self.model = GOTModel.from_pretrained(
20
+ model_path,
21
+ config=config,
22
  local_files_only=False
23
  )
24
 
25
+ self.tokenizer = AutoTokenizer.from_pretrained(
26
  model_path,
27
+ local_files_only=False
 
 
 
 
28
  )
29
 
30
+ self.model.eval()
31
 
32
  def process_image(self, image_stream):
33
  try: