add markdown support
Browse files- app.py +24 -5
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
from pdfitdown.pdfconversion import Converter
|
4 |
import fitz
|
5 |
from typing import List
|
6 |
from PIL import Image
|
7 |
from loadimg import load_img
|
8 |
import io
|
9 |
-
|
10 |
|
11 |
converter = Converter()
|
|
|
12 |
|
13 |
def convert_file_to_pdf(filename:str) -> str:
|
14 |
"""
|
@@ -52,6 +52,17 @@ def convert_file_to_img(image_file:str=None,txt:str="") -> List[Image.Image] :
|
|
52 |
return img_list
|
53 |
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
# Create individual interfaces
|
@@ -63,7 +74,7 @@ file_to_pdf = gr.Interface(
|
|
63 |
description="Convert your files to PDF format"
|
64 |
)
|
65 |
|
66 |
-
|
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"),
|
@@ -71,10 +82,18 @@ image_to_pdf = gr.Interface(
|
|
71 |
description="Convert your images to an image format"
|
72 |
)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Create tabbed interface
|
75 |
demo = gr.TabbedInterface(
|
76 |
-
[file_to_pdf,
|
77 |
-
["File to PDF", "File to Image"],
|
78 |
)
|
79 |
|
80 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from pdfitdown.pdfconversion import Converter
|
3 |
import fitz
|
4 |
from typing import List
|
5 |
from PIL import Image
|
6 |
from loadimg import load_img
|
7 |
import io
|
8 |
+
from docling.document_converter import DocumentConverter
|
9 |
|
10 |
converter = Converter()
|
11 |
+
docling_converter = DocumentConverter()
|
12 |
|
13 |
def convert_file_to_pdf(filename:str) -> str:
|
14 |
"""
|
|
|
52 |
return img_list
|
53 |
|
54 |
|
55 |
+
def convert_file_to_markdown(filename:str) -> str:
|
56 |
+
"""
|
57 |
+
Converts a file to markdown format.
|
58 |
+
Args:
|
59 |
+
filename: str
|
60 |
+
The path to the file to be converted.
|
61 |
+
Returns:
|
62 |
+
str: The markdown representation of the file.
|
63 |
+
"""
|
64 |
+
result = converter.convert(filename)
|
65 |
+
return result.document.export_to_markdown()
|
66 |
|
67 |
|
68 |
# Create individual interfaces
|
|
|
74 |
description="Convert your files to PDF format"
|
75 |
)
|
76 |
|
77 |
+
file_to_image = gr.Interface(
|
78 |
fn=convert_file_to_img,
|
79 |
inputs=[gr.File(label="Upload Image"),gr.Textbox(label="base64, url")],
|
80 |
outputs=gr.Gallery(label="Converted Images"),
|
|
|
82 |
description="Convert your images to an image format"
|
83 |
)
|
84 |
|
85 |
+
file_to_markdown = gr.Interface(
|
86 |
+
fn=convert_file_to_markdown,
|
87 |
+
inputs=gr.File(label="Upload File"),
|
88 |
+
outputs=gr.Textbox(label="Converted Markdown"),
|
89 |
+
title="File to Markdown Converter",
|
90 |
+
description="Convert your files to markdown format"
|
91 |
+
)
|
92 |
+
|
93 |
# Create tabbed interface
|
94 |
demo = gr.TabbedInterface(
|
95 |
+
[file_to_pdf, file_to_image, file_to_markdown],
|
96 |
+
["File to PDF", "File to Image", "File to Markdown"],
|
97 |
)
|
98 |
|
99 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -7,4 +7,5 @@ python-docx
|
|
7 |
gradio
|
8 |
python-pptx
|
9 |
pdfitdown
|
10 |
-
loadimg
|
|
|
|
7 |
gradio
|
8 |
python-pptx
|
9 |
pdfitdown
|
10 |
+
loadimg
|
11 |
+
docling
|