Spaces:
Running
Running
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) |