Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -300,33 +300,26 @@ def update_output(n_clicks, n_intervals, progress_data, url, depth):
|
|
300 |
return progress_data, False, {"visibility": "visible"}
|
301 |
|
302 |
# PDF generation complete
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
html.
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
|
|
|
|
|
|
316 |
|
317 |
raise PreventUpdate
|
318 |
|
319 |
-
@app.callback(
|
320 |
-
Output('progress-store', 'data'),
|
321 |
-
Input('progress-interval', 'n_intervals'),
|
322 |
-
prevent_initial_call=True
|
323 |
-
)
|
324 |
-
def update_progress(n):
|
325 |
-
# This function will be called every second to update the progress
|
326 |
-
# You can implement a mechanism to check the actual progress of the PDF generation
|
327 |
-
# For now, we'll just return a placeholder message
|
328 |
-
return "Processing... Please wait."
|
329 |
-
|
330 |
def background_task(url, depth, task_id):
|
331 |
def progress_callback(message):
|
332 |
# Update progress in the progress-store
|
@@ -336,7 +329,7 @@ def background_task(url, depth, task_id):
|
|
336 |
logger.info(f"Starting background task for URL: {url}, depth: {depth}")
|
337 |
pdf_content = asyncio.run(process_url(url, depth, progress_callback))
|
338 |
logger.info("Background task completed successfully")
|
339 |
-
# Store the
|
340 |
app.layout.children[1].data = pdf_content
|
341 |
except Exception as e:
|
342 |
logger.error(f"Error in background task: {str(e)}")
|
|
|
300 |
return progress_data, False, {"visibility": "visible"}
|
301 |
|
302 |
# PDF generation complete
|
303 |
+
if isinstance(progress_data, bytes):
|
304 |
+
try:
|
305 |
+
encoded = base64.b64encode(progress_data).decode()
|
306 |
+
filename = f"website_content_{int(time.time())}.pdf"
|
307 |
+
return html.Div([
|
308 |
+
html.H4("PDF Generated Successfully"),
|
309 |
+
html.P("Click the link below to download your PDF:"),
|
310 |
+
html.A(
|
311 |
+
filename,
|
312 |
+
href=f"data:application/pdf;base64,{encoded}",
|
313 |
+
download=filename,
|
314 |
+
className="btn btn-success mt-2"
|
315 |
+
)
|
316 |
+
]), True, {"visibility": "hidden"}
|
317 |
+
except Exception as e:
|
318 |
+
logger.error(f"Error creating download link: {str(e)}")
|
319 |
+
return f"An error occurred while creating the download link: {str(e)}", True, {"visibility": "hidden"}
|
320 |
|
321 |
raise PreventUpdate
|
322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
323 |
def background_task(url, depth, task_id):
|
324 |
def progress_callback(message):
|
325 |
# Update progress in the progress-store
|
|
|
329 |
logger.info(f"Starting background task for URL: {url}, depth: {depth}")
|
330 |
pdf_content = asyncio.run(process_url(url, depth, progress_callback))
|
331 |
logger.info("Background task completed successfully")
|
332 |
+
# Store the PDF content directly in the progress-store
|
333 |
app.layout.children[1].data = pdf_content
|
334 |
except Exception as e:
|
335 |
logger.error(f"Error in background task: {str(e)}")
|