File size: 939 Bytes
441778d
 
 
 
 
 
 
 
d6bc506
441778d
 
 
d6bc506
 
 
 
441778d
 
d6bc506
441778d
 
d6bc506
 
 
 
 
 
 
 
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
import gradio as gr
from markitdown import MarkItDown

def convert_to_markdown(file):
    markitdown = MarkItDown()
    result = markitdown.convert(file.name)
    return result.text_content

# Create Gradio interface
iface = gr.Interface(
    fn=convert_to_markdown,
    inputs=gr.File(label="Upload your file"),
    outputs=[
        gr.Textbox(label="Markdown Output", lines=20, interactive=False, show_label=False),
        gr.Button("Copy to Clipboard")  # Button to copy the text to clipboard
    ],
    title="File to Markdown Converter",
    description="Upload a file to convert its content to Markdown using Microsoft's markitdown library.",
    layout="vertical"
)

# Adding functionality to copy the text to clipboard
def copy_to_clipboard(text):
    return text  # This is handled automatically by Gradio

# Bind copy button to copy functionality
iface.load(fn=None, inputs=None, outputs=None, api_name="copy")

iface.launch()