Spaces:
Runtime error
Runtime error
amoldwalunj
commited on
Commit
•
b3b6b61
1
Parent(s):
a747bfb
Update app.py
Browse files
app.py
CHANGED
@@ -55,15 +55,28 @@ def process_text(inputs):
|
|
55 |
# #from streamlit_quill import Delta, Renderer
|
56 |
# from quill.delta import Delta
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def save_as_pdf(text):
|
59 |
# convert quill editor HTML to PDF
|
60 |
pdf_file = BytesIO()
|
61 |
-
HTML(string=text).write_pdf(pdf_file
|
62 |
-
.ql-editor {
|
63 |
-
font-size: 16px;
|
64 |
-
line-height: 1.6;
|
65 |
-
}
|
66 |
-
""")], style_tags=True)
|
67 |
|
68 |
# encode the PDF to base64
|
69 |
b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
@@ -164,21 +177,38 @@ def form_page():
|
|
164 |
#from quill.delta import Delta, Renderer
|
165 |
|
166 |
def editor_page():
|
|
|
167 |
st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
|
168 |
|
169 |
st.write("Use the editor below to edit the obituary:")
|
170 |
|
171 |
-
quill_text = st.session_state.
|
172 |
edited_text = st_quill(quill_text)
|
173 |
-
|
174 |
st.write("Here is the edited obituary:")
|
175 |
-
st.write(edited_text)
|
176 |
|
177 |
-
st.session_state.edited_text
|
178 |
|
179 |
if st.button("Save as PDF"):
|
180 |
# Save the output text as a PDF
|
181 |
-
save_as_pdf(st.session_state.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
st.write("The custom obituary has been saved as a PDF.")
|
183 |
|
184 |
# Add some custom CSS to style the editor
|
@@ -200,7 +230,6 @@ def editor_page():
|
|
200 |
</style>
|
201 |
""", unsafe_allow_html=True)
|
202 |
|
203 |
-
|
204 |
|
205 |
|
206 |
|
|
|
55 |
# #from streamlit_quill import Delta, Renderer
|
56 |
# from quill.delta import Delta
|
57 |
|
58 |
+
# def save_as_pdf(text):
|
59 |
+
# # convert quill editor HTML to PDF
|
60 |
+
# pdf_file = BytesIO()
|
61 |
+
# HTML(string=text).write_pdf(pdf_file, stylesheets=[CSS(string="""
|
62 |
+
# .ql-editor {
|
63 |
+
# font-size: 16px;
|
64 |
+
# line-height: 1.6;
|
65 |
+
# }
|
66 |
+
# """)], style_tags=True)
|
67 |
+
|
68 |
+
# # encode the PDF to base64
|
69 |
+
# b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
70 |
+
|
71 |
+
# # generate a download link for the PDF
|
72 |
+
# href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
|
73 |
+
# st.markdown(href, unsafe_allow_html=True)
|
74 |
+
|
75 |
+
|
76 |
def save_as_pdf(text):
|
77 |
# convert quill editor HTML to PDF
|
78 |
pdf_file = BytesIO()
|
79 |
+
HTML(string=text).write_pdf(pdf_file)
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# encode the PDF to base64
|
82 |
b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
|
|
|
177 |
#from quill.delta import Delta, Renderer
|
178 |
|
179 |
def editor_page():
|
180 |
+
#st.markdown("### Editor :smile:")
|
181 |
st.markdown("<h1 style='text-align: center; color: Red;'>Editor</h1>", unsafe_allow_html=True)
|
182 |
|
183 |
st.write("Use the editor below to edit the obituary:")
|
184 |
|
185 |
+
quill_text = st.session_state.output_text
|
186 |
edited_text = st_quill(quill_text)
|
187 |
+
|
188 |
st.write("Here is the edited obituary:")
|
189 |
+
#st.write(edited_text)
|
190 |
|
191 |
+
st.session_state.edited_text= edited_text
|
192 |
|
193 |
if st.button("Save as PDF"):
|
194 |
# Save the output text as a PDF
|
195 |
+
# save_as_pdf(st.session_state.output_text)
|
196 |
+
|
197 |
+
# Generate HTML code for the edited text with formatting
|
198 |
+
html_code = f"""
|
199 |
+
<html>
|
200 |
+
<head>
|
201 |
+
<style>
|
202 |
+
{edited_text['css']}
|
203 |
+
</style>
|
204 |
+
</head>
|
205 |
+
<body>
|
206 |
+
{edited_text['html']}
|
207 |
+
</body>
|
208 |
+
</html>
|
209 |
+
"""
|
210 |
+
|
211 |
+
save_as_pdf(html_code)
|
212 |
st.write("The custom obituary has been saved as a PDF.")
|
213 |
|
214 |
# Add some custom CSS to style the editor
|
|
|
230 |
</style>
|
231 |
""", unsafe_allow_html=True)
|
232 |
|
|
|
233 |
|
234 |
|
235 |
|