update requirements
Browse files- app.py +23 -3
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,18 +1,38 @@
|
|
1 |
import gradio as gr
|
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 |
output_path = image_file.name.replace(os.path.splitext(image_file.name)[1], '.pdf')
|
17 |
converter.convert(image_file.name, output_path)
|
18 |
return output_path
|
|
|
1 |
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 |
+
|
27 |
+
Args:
|
28 |
+
image_file: A file object containing the image to be converted.
|
29 |
+
The file must be in a format supported by the converter
|
30 |
+
(e.g., PNG, JPG, JPEG).
|
31 |
+
|
32 |
+
Returns:
|
33 |
+
str: The file path of the generated PDF file. The output filename will be
|
34 |
+
the same as the input filename but with a .pdf extension.
|
35 |
+
"""
|
36 |
output_path = image_file.name.replace(os.path.splitext(image_file.name)[1], '.pdf')
|
37 |
converter.convert(image_file.name, output_path)
|
38 |
return output_path
|
requirements.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
typing
|
2 |
beautifulsoup4
|
3 |
pdf2image
|
4 |
-
gradio
|
5 |
pdfplumber
|
6 |
python-docx
|
7 |
gradio
|
|
|
1 |
typing
|
2 |
beautifulsoup4
|
3 |
pdf2image
|
4 |
+
gradio[mcp]
|
5 |
pdfplumber
|
6 |
python-docx
|
7 |
gradio
|