Tonic commited on
Commit
bc9bd2e
Β·
unverified Β·
1 Parent(s): 1a87a19

do it normally

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -49,25 +49,24 @@ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True,
49
  model = model.eval().cuda()
50
  model.config.pad_token_id = tokenizer.eos_token_id
51
 
52
- # def image_to_base64(image):
53
- # buffered = io.BytesIO()
54
- # image.save(buffered, format="PNG")
55
- # return base64.b64encode(buffered.getvalue()).decode()
56
-
57
-
58
- def numpy_to_pil(image_np):
59
- return Image.fromarray(image_np.astype('uint8'), 'RGB')
60
 
61
  @spaces.GPU
62
- def process_image(image_np, task, ocr_type=None, ocr_box=None, ocr_color=None):
63
  try:
64
- if image_np is None:
65
  return "No image provided", None
66
 
67
- image = numpy_to_pil(image_np)
68
 
69
  with io.BytesIO() as buffer:
70
- image.save(buffer, format="PNG")
71
  image_path = "/tmp/temp_image.png"
72
  with open(image_path, "wb") as f:
73
  f.write(buffer.getvalue())
 
49
  model = model.eval().cuda()
50
  model.config.pad_token_id = tokenizer.eos_token_id
51
 
52
+ def process_input_image(image):
53
+ if isinstance(image, np.ndarray):
54
+ return Image.fromarray(image.astype('uint8'), 'RGB')
55
+ elif isinstance(image, str):
56
+ return Image.open(image)
57
+ else:
58
+ raise ValueError("Unsupported image type")
 
59
 
60
  @spaces.GPU
61
+ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
62
  try:
63
+ if image is None:
64
  return "No image provided", None
65
 
66
+ pil_image = process_input_image(image)
67
 
68
  with io.BytesIO() as buffer:
69
+ pil_image.save(buffer, format="PNG")
70
  image_path = "/tmp/temp_image.png"
71
  with open(image_path, "wb") as f:
72
  f.write(buffer.getvalue())