Spaces:
Running
Running
File size: 1,249 Bytes
e2d728a 8e024f6 e2d728a cfdee1a 8604d96 e2d728a 8604d96 4a9e7b8 8604d96 4a9e7b8 e2d728a 4a9e7b8 e2d728a a07d796 8604d96 e2d728a a07d796 8604d96 a07d796 8604d96 4a9e7b8 a07d796 e2d728a e665966 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import gradio as gr
from docling.document_converter import DocumentConverter
import spaces
def convert_document(file, method):
if method == "Docling":
# Load document and convert it using Docling
converter = DocumentConverter()
result = converter.convert(file.name)
# Check available attributes in DoclingDocument
available_attributes = dir(result.document)
document = result.document
# Output
converted_text = result.document.export_to_markdown()
return converted_text
elif method == "Marker":
return 'unsupported method'
else:
return 'unknown method'
with gr.Blocks() as app:
gr.Markdown("# Document Converter")
gr.Markdown("Upload a document, choose the backend, and get the converted text with metadata.")
file_input = gr.File(label="Upload Document")
method_input = gr.Radio(["Docling", "Marker"], label="Choose Conversion Backend")
output_text = gr.Textbox(label="Converted Document")
convert_button = gr.Button("Convert")
convert_button.click(
convert_document,
inputs=[file_input, method_input],
outputs=[output_text]
)
app.launch(debug=True, show_error=True) |