Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ import numpy as np
|
|
4 |
import os
|
5 |
import pickle
|
6 |
import torch
|
|
|
|
|
|
|
7 |
from grobidmonkey import reader
|
8 |
|
9 |
from transformers import pipeline
|
@@ -139,4 +142,39 @@ with col3:
|
|
139 |
# Display HTML box
|
140 |
st.markdown(st.session_state.current_text)
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
|
|
4 |
import os
|
5 |
import pickle
|
6 |
import torch
|
7 |
+
import markdown
|
8 |
+
import pdfkit
|
9 |
+
import io
|
10 |
from grobidmonkey import reader
|
11 |
|
12 |
from transformers import pipeline
|
|
|
142 |
# Display HTML box
|
143 |
st.markdown(st.session_state.current_text)
|
144 |
|
145 |
+
def render_markdown_to_html(markdown_str):
|
146 |
+
return markdown.markdown(markdown_str)
|
147 |
+
|
148 |
+
def create_pdf_from_markdown_strings(markdown_strings, output_file):
|
149 |
+
html_pages = [render_markdown_to_html(md) for md in markdown_strings]
|
150 |
+
|
151 |
+
# Combine HTML content with page breaks and add a style section for font size and margins
|
152 |
+
combined_html = '''
|
153 |
+
<html>
|
154 |
+
<head>
|
155 |
+
<style>
|
156 |
+
.page {
|
157 |
+
font-size: 16pt; /* Adjust the font size as needed */
|
158 |
+
margin: 20mm; /* Set margins for top, right, bottom, and left */
|
159 |
+
}
|
160 |
+
</style>
|
161 |
+
</head>
|
162 |
+
<body>
|
163 |
+
'''
|
164 |
+
for i, page in enumerate(html_pages):
|
165 |
+
combined_html += f'<div class="page">{page}</div>'
|
166 |
+
if i < len(html_pages) - 1: # Only add page break after if it's not the last page
|
167 |
+
combined_html += '<div style="page-break-after: always;"></div>'
|
168 |
+
combined_html += '</body></html>'
|
169 |
+
|
170 |
+
# PDF options: landscape orientation and page size
|
171 |
+
options = {
|
172 |
+
'page-size': 'A4',
|
173 |
+
'orientation': 'Landscape'
|
174 |
+
}
|
175 |
+
|
176 |
+
# Convert combined HTML to PDF directly into a file
|
177 |
+
pdfkit.from_string(combined_html, output_file, options=options)
|
178 |
+
|
179 |
+
create_pdf_from_markdown_strings(st.session_state.summ_text, '/tmp/output.pdf')
|
180 |
|