-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (40 loc) · 1.38 KB
/
Copy pathapp.py
File metadata and controls
50 lines (40 loc) · 1.38 KB
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
48
49
50
import streamlit as st
from docx import Document
from io import BytesIO
def strip_docx_content(docx_file):
# Load the uploaded .docx file
doc = Document(docx_file)
# Replace paragraph text with "[Blank]"
for para in doc.paragraphs:
if para.text.strip(): # Skip truly empty paragraphs
for run in para.runs:
run.text = "[Blank]"
# Replace table cell content with "[Blank]"
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
for para in cell.paragraphs:
if para.text.strip():
for run in para.runs:
run.text = "[Blank]"
return doc
def save_docx_to_bytes(doc):
buffer = BytesIO()
doc.save(buffer)
buffer.seek(0)
return buffer
# Streamlit UI
st.title("DocMold - Strip and Preserve Layout")
uploaded_file = st.file_uploader("Upload a DOCX template", type=["docx"])
if uploaded_file:
st.success("File uploaded successfully!")
# Process file
stripped_doc = strip_docx_content(uploaded_file)
output = save_docx_to_bytes(stripped_doc)
# Download button
st.download_button(
label="Download Stripped Template",
data=output,
file_name="stripped_template.docx",
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)