Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,9 @@ import os
|
|
5 |
import pickle
|
6 |
import torch
|
7 |
import markdown
|
8 |
-
from
|
9 |
import io
|
|
|
10 |
from grobidmonkey import reader
|
11 |
|
12 |
from transformers import pipeline
|
@@ -175,29 +176,21 @@ def create_pdf_from_markdown_strings(markdown_strings):
|
|
175 |
|
176 |
return html_pages
|
177 |
|
178 |
-
def
|
179 |
-
# Create a
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
# Convert combined HTML to PDF directly into a file
|
185 |
-
pdfkit.from_string(combined_html, output_file, options=options)
|
186 |
|
187 |
html_content = create_pdf_from_markdown_strings(st.session_state.summ_text)
|
188 |
-
|
189 |
-
|
190 |
-
if html_content:
|
191 |
-
pdf_path = html_to_pdf(html_content)
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
# Remove the temporary file
|
202 |
-
os.remove(pdf_path)
|
203 |
|
|
|
5 |
import pickle
|
6 |
import torch
|
7 |
import markdown
|
8 |
+
from weasyprint import HTML
|
9 |
import io
|
10 |
+
from io import BytesIO
|
11 |
from grobidmonkey import reader
|
12 |
|
13 |
from transformers import pipeline
|
|
|
176 |
|
177 |
return html_pages
|
178 |
|
179 |
+
def generate_pdf(html):
|
180 |
+
# Create a PDF from the HTML string
|
181 |
+
pdf_file = BytesIO()
|
182 |
+
HTML(string=html).write_pdf(pdf_file)
|
183 |
+
pdf_file.seek(0)
|
184 |
+
return pdf_file
|
|
|
|
|
185 |
|
186 |
html_content = create_pdf_from_markdown_strings(st.session_state.summ_text)
|
187 |
+
pdf_file = generate_pdf(html_content)
|
|
|
|
|
|
|
188 |
|
189 |
+
# Provide download link
|
190 |
+
st.download_button(
|
191 |
+
label="Download PDF",
|
192 |
+
data=pdf_file,
|
193 |
+
file_name="sample.pdf",
|
194 |
+
mime="application/pdf"
|
195 |
+
)
|
|
|
|
|
|
|
196 |
|