fix
Browse files
app.py
CHANGED
@@ -2,27 +2,24 @@ import gradio as gr
|
|
2 |
from PIL import Image
|
3 |
import os
|
4 |
from typing import List
|
5 |
-
from pdfitdown import
|
6 |
from pdf2image import convert_from_path
|
7 |
|
|
|
|
|
8 |
def convert_readme_to_pdf(markdown_file) -> str:
|
9 |
output_path = markdown_file.name.replace('.md', '.pdf')
|
10 |
-
|
11 |
return output_path
|
12 |
|
13 |
def convert_image_to_pdf(image_file) -> str:
|
14 |
# Open image and convert to PDF
|
15 |
-
output_path = image_file.name.replace(os.path.splitext(image_file.name)[1], '.pdf')
|
16 |
image = Image.open(image_file.name)
|
17 |
-
|
18 |
-
|
19 |
-
image.save(output_path, 'PDF')
|
20 |
return output_path
|
|
|
21 |
|
22 |
-
def convert_pdf_to_images(pdf_file) -> List[Image.Image]:
|
23 |
-
# Convert PDF to list of images
|
24 |
-
images = convert_from_path(pdf_file.name)
|
25 |
-
return images
|
26 |
|
27 |
# Create individual interfaces
|
28 |
readme_to_pdf = gr.Interface(
|
@@ -41,18 +38,10 @@ image_to_pdf = gr.Interface(
|
|
41 |
description="Convert your images to PDF format"
|
42 |
)
|
43 |
|
44 |
-
pdf_to_images = gr.Interface(
|
45 |
-
fn=convert_pdf_to_images,
|
46 |
-
inputs=gr.File(label="Upload PDF", file_types=[".pdf"]),
|
47 |
-
outputs=gr.Gallery(label="Converted Images"),
|
48 |
-
title="PDF to Images Converter",
|
49 |
-
description="Convert your PDF to a series of images"
|
50 |
-
)
|
51 |
-
|
52 |
# Create tabbed interface
|
53 |
demo = gr.TabbedInterface(
|
54 |
-
[readme_to_pdf, image_to_pdf
|
55 |
-
["README to PDF", "Image to PDF"
|
56 |
title="File Conversion Tools"
|
57 |
)
|
58 |
|
|
|
2 |
from PIL import Image
|
3 |
import os
|
4 |
from typing import List
|
5 |
+
from pdfitdown.pdfconversion import Converter
|
6 |
from pdf2image import convert_from_path
|
7 |
|
8 |
+
converter = Converter(reader="docling")
|
9 |
+
|
10 |
def convert_readme_to_pdf(markdown_file) -> str:
|
11 |
output_path = markdown_file.name.replace('.md', '.pdf')
|
12 |
+
converter.convert(markdown_file.name, output_path)
|
13 |
return output_path
|
14 |
|
15 |
def convert_image_to_pdf(image_file) -> str:
|
16 |
# Open image and convert to PDF
|
|
|
17 |
image = Image.open(image_file.name)
|
18 |
+
output_path = image_file.name.replace(os.path.splitext(image_file.name)[1], '.pdf')
|
19 |
+
converter.convert(image_file.name, output_path)
|
|
|
20 |
return output_path
|
21 |
+
|
22 |
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Create individual interfaces
|
25 |
readme_to_pdf = gr.Interface(
|
|
|
38 |
description="Convert your images to PDF format"
|
39 |
)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Create tabbed interface
|
42 |
demo = gr.TabbedInterface(
|
43 |
+
[readme_to_pdf, image_to_pdf],
|
44 |
+
["README to PDF", "Image to PDF"],
|
45 |
title="File Conversion Tools"
|
46 |
)
|
47 |
|