not-lain commited on
Commit
df1c5ff
·
1 Parent(s): e40d876
Files changed (2) hide show
  1. app.py +16 -17
  2. requirements.txt +2 -1
app.py CHANGED
@@ -2,25 +2,24 @@ import gradio as gr
2
  import os
3
  from pdfitdown.pdfconversion import Converter
4
 
5
- converter = Converter(reader="docling")
6
 
7
- def convert_readme_to_pdf(markdown_file) -> str:
8
  """
9
  Converts a markdown file to PDF format.
10
 
11
  Args:
12
- markdown_file: A file object representing the markdown file to be converted.
13
- Expected to have a 'name' attribute containing the file path.
14
 
15
  Returns:
16
- str: Path to the generated PDF file. The output filename is created by
17
- replacing the '.md' extension of the input file with '.pdf'.
18
  """
19
- output_path = markdown_file.name.replace('.md', '.pdf')
20
- converter.convert(markdown_file.name, output_path)
21
  return output_path
22
 
23
- def convert_image_to_pdf(image_file) -> str:
24
  """
25
  Convert an image file to PDF format.
26
 
@@ -40,16 +39,16 @@ def convert_image_to_pdf(image_file) -> str:
40
 
41
 
42
  # Create individual interfaces
43
- readme_to_pdf = gr.Interface(
44
- fn=convert_readme_to_pdf,
45
- inputs=gr.File(label="Upload README/Markdown file", file_types=[".md"]),
46
  outputs=gr.File(label="Converted PDF"),
47
- title="README to PDF Converter",
48
- description="Convert your markdown files to PDF format"
49
  )
50
 
51
  image_to_pdf = gr.Interface(
52
- fn=convert_image_to_pdf,
53
  inputs=gr.File(label="Upload Image", file_types=["image"]),
54
  outputs=gr.File(label="Converted PDF"),
55
  title="Image to PDF Converter",
@@ -58,8 +57,8 @@ image_to_pdf = gr.Interface(
58
 
59
  # Create tabbed interface
60
  demo = gr.TabbedInterface(
61
- [readme_to_pdf, image_to_pdf],
62
- ["README to PDF", "Image to PDF"],
63
  )
64
 
65
  if __name__ == "__main__":
 
2
  import os
3
  from pdfitdown.pdfconversion import Converter
4
 
5
+ converter = Converter()
6
 
7
+ def convert_file_to_pdf(filename:str) -> str:
8
  """
9
  Converts a markdown file to PDF format.
10
 
11
  Args:
12
+ filename: str
13
+ The path to the markdown file to be converted.
14
 
15
  Returns:
16
+ str: The file path of the generated PDF file.
 
17
  """
18
+ output_path = filename.name.rsplit('.', 1)[0] + '.pdf'
19
+ converter.convert(filename.name, output_path)
20
  return output_path
21
 
22
+ def convert_file_to_img(image_file) -> str:
23
  """
24
  Convert an image file to PDF format.
25
 
 
39
 
40
 
41
  # Create individual interfaces
42
+ file_to_pdf = gr.Interface(
43
+ fn=convert_file_to_pdf,
44
+ inputs=gr.File(label="Upload README/Markdown file"),
45
  outputs=gr.File(label="Converted PDF"),
46
+ title="File to PDF Converter",
47
+ description="Convert your files to PDF format"
48
  )
49
 
50
  image_to_pdf = gr.Interface(
51
+ fn=convert_file_to_img,
52
  inputs=gr.File(label="Upload Image", file_types=["image"]),
53
  outputs=gr.File(label="Converted PDF"),
54
  title="Image to PDF Converter",
 
57
 
58
  # Create tabbed interface
59
  demo = gr.TabbedInterface(
60
+ [file_to_pdf, image_to_pdf],
61
+ ["File to PDF", "File to Image"],
62
  )
63
 
64
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -6,4 +6,5 @@ pdfplumber
6
  python-docx
7
  gradio
8
  python-pptx
9
- pdfitdown
 
 
6
  python-docx
7
  gradio
8
  python-pptx
9
+ pdfitdown
10
+ loadimg