I found the solution to this:
First, import python-docx - from docx import Document
def get_docx(text):
document = Document()
document.add_paragraph(text)
bio = io.BytesIO()
document.save(bio)
return bio.getvalue()
And then:
st.download_button("Download Cover Letter", data=get_docx(cover_letter), file_name="cover_letter.docx", mime="docx")
I got this from: