aimal-khan commited on
Commit
3703ba9
·
verified ·
1 Parent(s): 12dd225

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from docling.document_converter import DocumentConverter
3
+
4
+ # 1) Initialize
5
+ converter = DocumentConverter()
6
+
7
+ # 2) Conversion function
8
+ def convert(file, out_format):
9
+ # load & convert
10
+ doc = converter.load_file(file.name)
11
+ if out_format == "Markdown":
12
+ return doc.to_markdown()
13
+ if out_format == "HTML":
14
+ return doc.to_html()
15
+ if out_format == "JSON":
16
+ return doc.to_json()
17
+ # …add more formats if you like
18
+
19
+ # 3) Build Gradio interface
20
+ with gr.Blocks() as demo:
21
+ # — Top: explanatory text
22
+ gr.Markdown(
23
+ """
24
+ # 📝 Docling Demo
25
+ Upload any supported file (PDF, DOCX, PPTX, images, audio…),
26
+ choose your output format, and see the result instantly.
27
+ """
28
+ )
29
+ # — Main row: uploader + options + convert button
30
+ with gr.Row():
31
+ inp = gr.File(label="📂 Upload your document", file_count="single",
32
+ file_types=[".pdf",".docx",".pptx",".xlsx",
33
+ ".html",".png",".jpg",".jpeg",".tiff",
34
+ ".wav",".mp3"])
35
+ fmt = gr.Dropdown(choices=["Markdown","HTML","JSON"],
36
+ label="🔄 Select output format")
37
+ btn = gr.Button("Convert")
38
+ # — Output pane
39
+ out = gr.Textbox(label="📄 Converted output", lines=20)
40
+ # — Wire it up
41
+ btn.click(fn=convert, inputs=[inp, fmt], outputs=out)
42
+
43
+ # 4) Launch
44
+ demo.launch()