Tonic commited on
Commit
69377bc
Β·
unverified Β·
1 Parent(s): ec040ed

do it normally

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -51,13 +51,10 @@ model.config.pad_token_id = tokenizer.eos_token_id
51
 
52
 
53
 
54
- def process_input_image(image):
55
- if isinstance(image, str):
56
- return Image.open(image)
57
- elif isinstance(image, Image.Image):
58
- return image
59
- else:
60
- raise ValueError("Unsupported image type")
61
 
62
  @spaces.GPU
63
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
@@ -65,8 +62,8 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
65
  if image is None:
66
  return "No image provided", None
67
 
68
- # Process the input image
69
- pil_image = process_input_image(image)
70
 
71
  with io.BytesIO() as buffer:
72
  pil_image.save(buffer, format="PNG")
 
51
 
52
 
53
 
54
+ def save_image_to_temp_file(image):
55
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
56
+ image.save(temp_file, format="PNG")
57
+ return temp_file.name
 
 
 
58
 
59
  @spaces.GPU
60
  def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
 
62
  if image is None:
63
  return "No image provided", None
64
 
65
+ # Save the PIL Image to a temporary file
66
+ temp_image_path = save_image_to_temp_file(image)
67
 
68
  with io.BytesIO() as buffer:
69
  pil_image.save(buffer, format="PNG")