Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -255,14 +255,17 @@ app.layout = dbc.Container([
|
|
| 255 |
Output("progress-bar", "value"),
|
| 256 |
Output("progress-message", "children"),
|
| 257 |
Output("pdf-store", "data"),
|
|
|
|
| 258 |
Input("submit-button", "n_clicks"),
|
|
|
|
| 259 |
Input("progress-interval", "n_intervals"),
|
| 260 |
State("url-input", "value"),
|
| 261 |
State("depth-slider", "value"),
|
| 262 |
State("progress-store", "data"),
|
|
|
|
| 263 |
prevent_initial_call=True
|
| 264 |
)
|
| 265 |
-
def
|
| 266 |
ctx = dash.callback_context
|
| 267 |
if not ctx.triggered:
|
| 268 |
raise PreventUpdate
|
|
@@ -271,26 +274,33 @@ def update_output(n_clicks, n_intervals, url, depth, progress_data):
|
|
| 271 |
|
| 272 |
if triggered_id == "submit-button":
|
| 273 |
if not url:
|
| 274 |
-
return False, 0, "Please enter a URL", None
|
| 275 |
|
| 276 |
# Start the background task
|
| 277 |
task_id = str(uuid.uuid4())
|
| 278 |
executor.submit(background_task, url, depth, task_id)
|
| 279 |
|
| 280 |
-
return True, 0, "Processing... Please wait.", None
|
| 281 |
|
| 282 |
elif triggered_id == "progress-interval":
|
| 283 |
progress = progress_data['progress']
|
| 284 |
message = progress_data['message']
|
| 285 |
|
| 286 |
if isinstance(message, str) and message.startswith("Error"):
|
| 287 |
-
return False, 100, message, None
|
| 288 |
elif progress == 100 and generated_file:
|
| 289 |
-
return False, 100, "PDF ready for download!", generated_file
|
| 290 |
elif progress > 0:
|
| 291 |
-
return True, progress, message, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
-
return False, 0, "", None
|
| 294 |
|
| 295 |
@app.callback(
|
| 296 |
Output("download-pdf", "data"),
|
|
|
|
| 255 |
Output("progress-bar", "value"),
|
| 256 |
Output("progress-message", "children"),
|
| 257 |
Output("pdf-store", "data"),
|
| 258 |
+
Output("download-pdf", "data"),
|
| 259 |
Input("submit-button", "n_clicks"),
|
| 260 |
+
Input("download-button", "n_clicks"),
|
| 261 |
Input("progress-interval", "n_intervals"),
|
| 262 |
State("url-input", "value"),
|
| 263 |
State("depth-slider", "value"),
|
| 264 |
State("progress-store", "data"),
|
| 265 |
+
State("pdf-store", "data"),
|
| 266 |
prevent_initial_call=True
|
| 267 |
)
|
| 268 |
+
def update_and_download(submit_clicks, download_clicks, n_intervals, url, depth, progress_data, pdf_data):
|
| 269 |
ctx = dash.callback_context
|
| 270 |
if not ctx.triggered:
|
| 271 |
raise PreventUpdate
|
|
|
|
| 274 |
|
| 275 |
if triggered_id == "submit-button":
|
| 276 |
if not url:
|
| 277 |
+
return False, 0, "Please enter a URL", None, None
|
| 278 |
|
| 279 |
# Start the background task
|
| 280 |
task_id = str(uuid.uuid4())
|
| 281 |
executor.submit(background_task, url, depth, task_id)
|
| 282 |
|
| 283 |
+
return True, 0, "Processing... Please wait.", None, None
|
| 284 |
|
| 285 |
elif triggered_id == "progress-interval":
|
| 286 |
progress = progress_data['progress']
|
| 287 |
message = progress_data['message']
|
| 288 |
|
| 289 |
if isinstance(message, str) and message.startswith("Error"):
|
| 290 |
+
return False, 100, message, None, None
|
| 291 |
elif progress == 100 and generated_file:
|
| 292 |
+
return False, 100, "PDF ready for download!", generated_file, None
|
| 293 |
elif progress > 0:
|
| 294 |
+
return True, progress, message, None, None
|
| 295 |
+
|
| 296 |
+
elif triggered_id == "download-button":
|
| 297 |
+
if pdf_data is None:
|
| 298 |
+
# If PDF is not ready, return None to prevent download
|
| 299 |
+
return dash.no_update, dash.no_update, dash.no_update, dash.no_update, None
|
| 300 |
+
|
| 301 |
+
return dash.no_update, dash.no_update, dash.no_update, dash.no_update, dcc.send_bytes(pdf_data, f"website_content_{int(time.time())}.pdf")
|
| 302 |
|
| 303 |
+
return False, 0, "", None, None
|
| 304 |
|
| 305 |
@app.callback(
|
| 306 |
Output("download-pdf", "data"),
|