not-lain commited on
Commit
c52be9c
·
1 Parent(s): 72423ad
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -25,7 +25,7 @@ def convert_file_to_pdf(filename:str) -> str:
25
  converter.convert(filename.name, output_path)
26
  return output_path
27
 
28
- def convert_file_to_img(image_file:str) -> List[Image.Image] :
29
  """
30
  Convert an image file to PDF format.
31
 
@@ -39,12 +39,15 @@ def convert_file_to_img(image_file:str) -> List[Image.Image] :
39
  the same as the input filename but with a .pdf extension.
40
  """
41
  img_list = []
42
- output_path = image_file.name.rsplit('.', 1)[0] + '.pdf'
43
- converter.convert(image_file.name, output_path)
44
- doc = fitz.open(output_path)
45
- for page in doc:
46
- page_bytes = page.get_pixmap().tobytes("png")
47
- img_list.append(load_img(Image.open(io.BytesIO(page_bytes))).convert("RGB"))
 
 
 
48
  doc.close()
49
  return img_list
50
 
@@ -62,7 +65,7 @@ file_to_pdf = gr.Interface(
62
 
63
  image_to_pdf = gr.Interface(
64
  fn=convert_file_to_img,
65
- inputs=gr.File(label="Upload Image"),
66
  outputs=gr.Gallery(label="Converted Images"),
67
  title="File to Images Converter",
68
  description="Convert your images to an image format"
 
25
  converter.convert(filename.name, output_path)
26
  return output_path
27
 
28
+ def convert_file_to_img(image_file:str=None,txt:str=None) -> List[Image.Image] :
29
  """
30
  Convert an image file to PDF format.
31
 
 
39
  the same as the input filename but with a .pdf extension.
40
  """
41
  img_list = []
42
+ if txt is not None:
43
+ image_file.append(load_img(txt))
44
+ if image_file is not None :
45
+ output_path = image_file.name.rsplit('.', 1)[0] + '.pdf'
46
+ converter.convert(image_file.name, output_path)
47
+ doc = fitz.open(output_path)
48
+ for page in doc:
49
+ page_bytes = page.get_pixmap().tobytes("png")
50
+ img_list.append(load_img(Image.open(io.BytesIO(page_bytes))).convert("RGB"))
51
  doc.close()
52
  return img_list
53
 
 
65
 
66
  image_to_pdf = gr.Interface(
67
  fn=convert_file_to_img,
68
+ inputs=[gr.File(label="Upload Image"),gr.Textbox(label="base64, url")],
69
  outputs=gr.Gallery(label="Converted Images"),
70
  title="File to Images Converter",
71
  description="Convert your images to an image format"