Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,8 @@ import ssl
|
|
21 |
from io import BytesIO
|
22 |
from concurrent.futures import ThreadPoolExecutor
|
23 |
import math
|
|
|
|
|
24 |
|
25 |
# Initialize Dash app
|
26 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
@@ -199,13 +201,16 @@ async def website_to_pdf(all_pages, progress_callback):
|
|
199 |
except Exception as e:
|
200 |
logger.error(f"Error generating PDF chunk {i}: {str(e)}")
|
201 |
|
202 |
-
# Combine PDF chunks
|
203 |
-
|
204 |
for chunk in pdf_chunks:
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
207 |
|
208 |
-
return
|
209 |
|
210 |
async def process_url(url, depth, progress_callback):
|
211 |
try:
|
|
|
21 |
from io import BytesIO
|
22 |
from concurrent.futures import ThreadPoolExecutor
|
23 |
import math
|
24 |
+
from PyPDF2 import PdfMerger
|
25 |
+
|
26 |
|
27 |
# Initialize Dash app
|
28 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
|
|
201 |
except Exception as e:
|
202 |
logger.error(f"Error generating PDF chunk {i}: {str(e)}")
|
203 |
|
204 |
+
# Combine PDF chunks using PyPDF2
|
205 |
+
merger = PdfMerger()
|
206 |
for chunk in pdf_chunks:
|
207 |
+
merger.append(BytesIO(chunk))
|
208 |
+
|
209 |
+
output = BytesIO()
|
210 |
+
merger.write(output)
|
211 |
+
merger.close()
|
212 |
|
213 |
+
return output.getvalue()
|
214 |
|
215 |
async def process_url(url, depth, progress_callback):
|
216 |
try:
|