Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -44,21 +44,20 @@ 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
-
48
  @spaces.GPU
49
- def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=True):
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
@@ -85,8 +84,8 @@ def update_inputs(task):
85
  elif task == "Render Formatted OCR":
86
  return [gr.update(visible=False)] * 3 + [gr.update(visible=True)]
87
 
88
- def ocr_demo(image, task, ocr_type, ocr_box, ocr_color, render):
89
- res, html_content = process_image(image, task, ocr_type, ocr_box, ocr_color, render)
90
  if html_content:
91
  return res, html_content
92
  return res, None
 
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
  if task == "Plain Text OCR":
50
+ res = model.chat(tokenizer, image, ocr_type='ocr', attention_mask=attention_mask)
51
  elif task == "Format Text OCR":
52
+ res = model.chat(tokenizer, image, ocr_type='format', attention_mask=attention_mask)
53
  elif task == "Fine-grained OCR (Box)":
54
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box, attention_mask=attention_mask)
55
  elif task == "Fine-grained OCR (Color)":
56
+ res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color, attention_mask=attention_mask)
57
  elif task == "Multi-crop OCR":
58
+ res = model.chat_crop(tokenizer, image_file=image, attention_mask=attention_mask)
59
  elif task == "Render Formatted OCR":
60
+ res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html', attention_mask=attention_mask)
61
  with open('./demo.html', 'r') as f:
62
  html_content = f.read()
63
  return res, html_content
 
84
  elif task == "Render Formatted OCR":
85
  return [gr.update(visible=False)] * 3 + [gr.update(visible=True)]
86
 
87
+ def ocr_demo(image, task, ocr_type, ocr_box, ocr_color):
88
+ res, html_content = process_image(image, task, ocr_type, ocr_box, ocr_color)
89
  if html_content:
90
  return res, html_content
91
  return res, None