Spaces:
Runtime error
Runtime error
amoldwalunj
commited on
Commit
•
62ce43e
1
Parent(s):
65a1858
Update app.py
Browse files
app.py
CHANGED
@@ -190,29 +190,23 @@ def form_page():
|
|
190 |
|
191 |
def editor_page():
|
192 |
st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
|
|
|
193 |
st.write("Use the editor below to edit the obituary:")
|
194 |
-
|
195 |
quill_text = st.session_state.output_text
|
196 |
edited_text = st_quill(quill_text)
|
197 |
-
|
198 |
st.write("Here is the edited obituary:")
|
199 |
-
|
200 |
st.session_state.edited_text = edited_text
|
201 |
-
|
202 |
if st.button("Download as PDF"):
|
203 |
# Save edited text as HTML string
|
204 |
html_string = f"<html><head><style>{edited_text['css']}</style></head><body>{edited_text['content']}</body></html>"
|
205 |
# Save HTML string as PDF file and generate download link
|
206 |
with st.spinner("Generating PDF..."):
|
207 |
pdf_file = save_as_pdf(html_string)
|
208 |
-
|
209 |
-
pdf_bytes = f.read()
|
210 |
-
st.download_button(
|
211 |
-
label="Download PDF",
|
212 |
-
data=pdf_bytes,
|
213 |
-
file_name="edited_text.pdf",
|
214 |
-
mime="application/pdf",
|
215 |
-
)
|
216 |
|
217 |
|
218 |
|
|
|
190 |
|
191 |
def editor_page():
|
192 |
st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
|
193 |
+
|
194 |
st.write("Use the editor below to edit the obituary:")
|
195 |
+
|
196 |
quill_text = st.session_state.output_text
|
197 |
edited_text = st_quill(quill_text)
|
198 |
+
|
199 |
st.write("Here is the edited obituary:")
|
200 |
+
|
201 |
st.session_state.edited_text = edited_text
|
202 |
+
|
203 |
if st.button("Download as PDF"):
|
204 |
# Save edited text as HTML string
|
205 |
html_string = f"<html><head><style>{edited_text['css']}</style></head><body>{edited_text['content']}</body></html>"
|
206 |
# Save HTML string as PDF file and generate download link
|
207 |
with st.spinner("Generating PDF..."):
|
208 |
pdf_file = save_as_pdf(html_string)
|
209 |
+
st.markdown(f'<a href="data:application/pdf;base64,{base64.b64encode(open(pdf_file, "rb").read()).decode()} download="edited_text.pdf">Download PDF</a>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
|
212 |
|