update
Browse files- app.py +16 -17
- 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(
|
| 6 |
|
| 7 |
-
def
|
| 8 |
"""
|
| 9 |
Converts a markdown file to PDF format.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
Returns:
|
| 16 |
-
str:
|
| 17 |
-
replacing the '.md' extension of the input file with '.pdf'.
|
| 18 |
"""
|
| 19 |
-
output_path =
|
| 20 |
-
converter.convert(
|
| 21 |
return output_path
|
| 22 |
|
| 23 |
-
def
|
| 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 |
-
|
| 44 |
-
fn=
|
| 45 |
-
inputs=gr.File(label="Upload README/Markdown file"
|
| 46 |
outputs=gr.File(label="Converted PDF"),
|
| 47 |
-
title="
|
| 48 |
-
description="Convert your
|
| 49 |
)
|
| 50 |
|
| 51 |
image_to_pdf = gr.Interface(
|
| 52 |
-
fn=
|
| 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 |
-
[
|
| 62 |
-
["
|
| 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
|