|
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.") |
|
|