File size: 1,070 Bytes
4b4bfa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d51167e
 
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
42
43
44
45
46
47
import streamlit as st
from markitdown import MarkItDown
import tempfile
import os


def convert_to_markdown(file):
    markitdown = MarkItDown()
    with tempfile.NamedTemporaryFile(delete=False) as temp_file:
        temp_file.write(file.read())
        temp_file_path = temp_file.name

    try:
        result = markitdown.convert(temp_file_path)
        return result.text_content
    finally:
        os.remove(temp_file_path)



st.title("File to Markdown Converter")
st.write("Upload a file to convert its content to Markdown using Microsoft's markitdown library.")


uploaded_file = st.file_uploader("Upload your file", type=None)

if uploaded_file is not None:

    markdown_output = convert_to_markdown(uploaded_file)


    st.text_area(
        label="Markdown Output",
        value=markdown_output,
        height=300,
    )


    st.download_button(
        label="Download Markdown Output",
        data=markdown_output,
        file_name="markdown_output.md",
        mime="text/markdown"
    )

st.write("NOTE : Scanned or Image PDF is Not Supported.")