File size: 951 Bytes
eaa0c7a
d46886b
 
 
 
f017143
d46886b
 
 
 
eaa0c7a
 
d46886b
eaa0c7a
 
d46886b
 
 
 
 
d8432f9
2aa380f
eaa0c7a
2aa380f
d46886b
 
 
d8432f9
 
3486df4
 
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
import os
import gradio as gr
from docling.document_converter import DocumentConverter, PdfFormatOption
from docling.datamodel.base_models import InputFormat
import tempfile

def pdf_to_markdown(file):
    # Save uploaded file temporarily
    tmp_path = file.name
    # Convert PDF using Docling/VLM (Granite Docling)
    converter = DocumentConverter(
        format_options={
            InputFormat.PDF: PdfFormatOption()
        }
    )
    result = converter.convert(tmp_path)
    doc = result.document
    # Export to Markdown (or you can export to JSON via doc.model_dump())
    md = doc.export_to_markdown()
    return md

interface = gr.Interface(
    fn=pdf_to_markdown,
    inputs=gr.File(file_types=[".pdf"]),
    outputs="text",
    title="PDF β†’ Markdown/JSON with Granite Docling",
    description="Upload a PDF and get parsed Markdown (or JSON) using Granite Docling via Docling."
)

if __name__ == "__main__":
    interface.launch()