Tonic commited on
Commit
b513b33
β€’
1 Parent(s): ed456c1

initial commit

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -44,23 +44,21 @@ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True,
44
  model = model.eval().cuda()
45
  model.config.pad_token_id = tokenizer.eos_token_id
46
 
 
47
  @spaces.GPU
48
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
49
-
50
- attention_mask = torch.ones((1, model.config.max_position_embeddings), dtype=torch.long, device=model.device)
51
-
52
  if task == "Plain Text OCR":
53
- res = model.chat(tokenizer, image, ocr_type='ocr', attention_mask=attention_mask)
54
  elif task == "Format Text OCR":
55
- res = model.chat(tokenizer, image, ocr_type='format', attention_mask=attention_mask)
56
  elif task == "Fine-grained OCR (Box)":
57
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box, attention_mask=attention_mask)
58
  elif task == "Fine-grained OCR (Color)":
59
- res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color, attention_mask=attention_mask)
60
  elif task == "Multi-crop OCR":
61
- res = model.chat_crop(tokenizer, image_file=image, attention_mask=attention_mask)
62
  elif task == "Render Formatted OCR":
63
- res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html', attention_mask=attention_mask)
64
  with open('./demo.html', 'r') as f:
65
  html_content = f.read()
66
  return res, html_content
 
44
  model = model.eval().cuda()
45
  model.config.pad_token_id = tokenizer.eos_token_id
46
 
47
+
48
  @spaces.GPU
49
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
 
 
 
50
  if task == "Plain Text OCR":
51
+ res = model.chat(tokenizer, image, ocr_type='ocr')
52
  elif task == "Format Text OCR":
53
+ res = model.chat(tokenizer, image, ocr_type='format')
54
  elif task == "Fine-grained OCR (Box)":
55
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box)
56
  elif task == "Fine-grained OCR (Color)":
57
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color)
58
  elif task == "Multi-crop OCR":
59
+ res = model.chat_crop(tokenizer, image_file=image)
60
  elif task == "Render Formatted OCR":
61
+ res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
62
  with open('./demo.html', 'r') as f:
63
  html_content = f.read()
64
  return res, html_content