amoldwalunj commited on
Commit
a747bfb
1 Parent(s): 34ba2e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -55,28 +55,25 @@ def process_text(inputs):
55
  # #from streamlit_quill import Delta, Renderer
56
  # from quill.delta import Delta
57
 
58
- import base64
59
- from io import BytesIO
60
- from delta import Delta, html
61
- from weasyprint import HTML
62
-
63
  def save_as_pdf(text):
64
- # convert quill editor Delta object to HTML
65
- delta = Delta(text)
66
- html_str = html.render(delta)
67
-
68
- # convert HTML to PDF
69
  pdf_file = BytesIO()
70
- HTML(string=html_str).write_pdf(pdf_file)
71
-
 
 
 
 
 
72
  # encode the PDF to base64
73
  b64 = base64.b64encode(pdf_file.getvalue()).decode('utf-8')
74
-
75
  # generate a download link for the PDF
76
  href = f'<a href="data:application/octet-stream;base64,{b64}" download="output.pdf">Download PDF</a>'
77
  st.markdown(href, unsafe_allow_html=True)
78
 
79
 
 
80
  def form_page():
81
 
82
  st.markdown("### Your custom obituary writer :pencil:")
@@ -171,23 +168,16 @@ def editor_page():
171
 
172
  st.write("Use the editor below to edit the obituary:")
173
 
174
- # Get the initial text to be edited
175
- initial_text = st.session_state.output_text
176
-
177
- # Create a Delta object from the edited text
178
- edited_delta = Delta(st.text_input("Edited text", value=initial_text))
179
-
180
- # Render the Delta object using the Renderer class
181
- edited_html = Renderer().render(edited_delta)
182
 
183
  st.write("Here is the edited obituary:")
184
- st.write(edited_html, unsafe_allow_html=True)
185
 
186
- # Store the edited text in session state
187
- st.session_state.edited_text = edited_html
188
 
189
  if st.button("Save as PDF"):
190
- # Save the edited text as a PDF
191
  save_as_pdf(st.session_state.edited_text)
192
  st.write("The custom obituary has been saved as a PDF.")
193
 
@@ -210,6 +200,7 @@ def editor_page():
210
  </style>
211
  """, unsafe_allow_html=True)
212
 
 
213
 
214
 
215
 
 
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
+
77
  def form_page():
78
 
79
  st.markdown("### Your custom obituary writer :pencil:")
 
168
 
169
  st.write("Use the editor below to edit the obituary:")
170
 
171
+ quill_text = st.session_state.edited_text
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 = 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.edited_text)
182
  st.write("The custom obituary has been saved as a PDF.")
183
 
 
200
  </style>
201
  """, unsafe_allow_html=True)
202
 
203
+
204
 
205
 
206