weege007 commited on
Commit
c213a00
·
verified ·
1 Parent(s): bac4a8b

Update modeling_deepseekocr.py

Browse files
Files changed (1) hide show
  1. modeling_deepseekocr.py +4 -2
modeling_deepseekocr.py CHANGED
@@ -27,7 +27,9 @@ import time
27
  def load_image(image_path):
28
 
29
  try:
30
- image = Image.open(image_path)
 
 
31
 
32
  corrected_image = ImageOps.exif_transpose(image)
33
 
@@ -722,7 +724,7 @@ class DeepseekOCRForCausalLM(DeepseekV2ForCausalLM):
722
  # "content": "<image>\nFree OCR. ",
723
  # "content": "<image>\nParse the figure. ",
724
  # "content": "<image>\nExtract the text in the image. ",
725
- "images": [image_file] if isinstance(image_file, BytesIO) else [f'{image_file}'],
726
  },
727
  {"role": "<|Assistant|>", "content": ""},
728
  ]
 
27
  def load_image(image_path):
28
 
29
  try:
30
+ image = image_path
31
+ if not isinstance(image_path, Image.Image):
32
+ image = Image.open(image_path)
33
 
34
  corrected_image = ImageOps.exif_transpose(image)
35
 
 
724
  # "content": "<image>\nFree OCR. ",
725
  # "content": "<image>\nParse the figure. ",
726
  # "content": "<image>\nExtract the text in the image. ",
727
+ "images": [image_file] if isinstance(image_file, (BytesIO, Image.Image)) else [f'{image_file}'],
728
  },
729
  {"role": "<|Assistant|>", "content": ""},
730
  ]