Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from markitdown import MarkItDown
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def convert_to_markdown(file):
|
| 8 |
+
markitdown = MarkItDown()
|
| 9 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 10 |
+
temp_file.write(file.read())
|
| 11 |
+
temp_file_path = temp_file.name
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
result = markitdown.convert(temp_file_path)
|
| 15 |
+
return result.text_content
|
| 16 |
+
finally:
|
| 17 |
+
os.remove(temp_file_path)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
st.title("File to Markdown Converter")
|
| 22 |
+
st.write("Upload a file to convert its content to Markdown using Microsoft's markitdown library.")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
uploaded_file = st.file_uploader("Upload your file", type=None)
|
| 26 |
+
|
| 27 |
+
if uploaded_file is not None:
|
| 28 |
+
|
| 29 |
+
markdown_output = convert_to_markdown(uploaded_file)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
st.text_area(
|
| 33 |
+
label="Markdown Output",
|
| 34 |
+
value=markdown_output,
|
| 35 |
+
height=300,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
st.download_button(
|
| 40 |
+
label="Download Markdown Output",
|
| 41 |
+
data=markdown_output,
|
| 42 |
+
file_name="markdown_output.md",
|
| 43 |
+
mime="text/markdown"
|
| 44 |
+
)
|