amoldwalunj commited on
Commit
9bce769
·
1 Parent(s): ab01f25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -76,15 +76,15 @@ def process_text(inputs):
76
  # st.markdown(href, unsafe_allow_html=True)
77
 
78
 
79
- import weasyprint
80
-
81
  def save_as_pdf(text):
82
  # convert quill editor HTML to PDF
83
- pdf_file = BytesIO()
84
- weasyprint.HTML(string=text).write_pdf(pdf_file)
 
 
85
 
86
  # encode the PDF to base64
87
- b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
88
 
89
  # generate a download link for the PDF
90
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
@@ -191,7 +191,8 @@ def editor_page():
191
  quill_text = st.session_state.output_text
192
  edited_text = st_quill(quill_text)
193
 
194
- st.markdown(edited_text, unsafe_allow_html=True)
 
195
 
196
  st.session_state.edited_text = edited_text
197
 
 
76
  # st.markdown(href, unsafe_allow_html=True)
77
 
78
 
 
 
79
  def save_as_pdf(text):
80
  # convert quill editor HTML to PDF
81
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
82
+ tmpfile.write(text.encode("utf-8"))
83
+ tmpfile.flush()
84
+ pdf_file = HTML(tmpfile.name).write_pdf()
85
 
86
  # encode the PDF to base64
87
+ b64 = base64.b64encode(pdf_file).decode('utf-8')
88
 
89
  # generate a download link for the PDF
90
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
 
191
  quill_text = st.session_state.output_text
192
  edited_text = st_quill(quill_text)
193
 
194
+ st.write("Here is the edited obituary:")
195
+ st.write(edited_text)
196
 
197
  st.session_state.edited_text = edited_text
198