Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -261,11 +261,12 @@ app.layout = dbc.Container([
|
|
261 |
Output("progress-bar", "style"),
|
262 |
Input("submit-button", "n_clicks"),
|
263 |
Input("progress-interval", "n_intervals"),
|
|
|
264 |
State("url-input", "value"),
|
265 |
State("depth-slider", "value"),
|
266 |
prevent_initial_call=True
|
267 |
)
|
268 |
-
def update_output(n_clicks, n_intervals, url, depth):
|
269 |
ctx = dash.callback_context
|
270 |
if not ctx.triggered:
|
271 |
raise PreventUpdate
|
@@ -282,21 +283,20 @@ def update_output(n_clicks, n_intervals, url, depth):
|
|
282 |
|
283 |
return "Processing... Please wait.", False, {"visibility": "visible"}
|
284 |
|
285 |
-
elif triggered_id == "progress-interval":
|
286 |
# Check progress
|
287 |
-
|
288 |
-
if progress is None:
|
289 |
return "Processing... Please wait.", False, {"visibility": "visible"}
|
290 |
|
291 |
-
if isinstance(
|
292 |
-
return
|
293 |
|
294 |
-
if isinstance(
|
295 |
-
return
|
296 |
|
297 |
# PDF generation complete
|
298 |
try:
|
299 |
-
encoded = base64.b64encode(
|
300 |
return html.Div([
|
301 |
html.H4("PDF Generated Successfully"),
|
302 |
html.A(
|
@@ -324,14 +324,12 @@ def update_progress(n):
|
|
324 |
|
325 |
def background_task(url, depth, task_id):
|
326 |
def progress_callback(message):
|
327 |
-
# Update progress in the
|
328 |
-
|
329 |
|
330 |
try:
|
331 |
pdf_content = asyncio.run(process_url(url, depth, progress_callback))
|
332 |
-
# Store the result in
|
333 |
-
# For simplicity, we'll use the progress-store, but in a real application,
|
334 |
-
# you should use a more robust solution for storing large data
|
335 |
app.layout.children[1].data = pdf_content
|
336 |
except Exception as e:
|
337 |
logger.error(f"Error in background task: {str(e)}")
|
|
|
261 |
Output("progress-bar", "style"),
|
262 |
Input("submit-button", "n_clicks"),
|
263 |
Input("progress-interval", "n_intervals"),
|
264 |
+
Input("progress-store", "data"), # Add this line
|
265 |
State("url-input", "value"),
|
266 |
State("depth-slider", "value"),
|
267 |
prevent_initial_call=True
|
268 |
)
|
269 |
+
def update_output(n_clicks, n_intervals, progress_data, url, depth):
|
270 |
ctx = dash.callback_context
|
271 |
if not ctx.triggered:
|
272 |
raise PreventUpdate
|
|
|
283 |
|
284 |
return "Processing... Please wait.", False, {"visibility": "visible"}
|
285 |
|
286 |
+
elif triggered_id == "progress-interval" or triggered_id == "progress-store":
|
287 |
# Check progress
|
288 |
+
if progress_data is None:
|
|
|
289 |
return "Processing... Please wait.", False, {"visibility": "visible"}
|
290 |
|
291 |
+
if isinstance(progress_data, str) and progress_data.startswith("Error"):
|
292 |
+
return progress_data, True, {"visibility": "hidden"}
|
293 |
|
294 |
+
if isinstance(progress_data, str) and progress_data.startswith("Processing"):
|
295 |
+
return progress_data, False, {"visibility": "visible"}
|
296 |
|
297 |
# PDF generation complete
|
298 |
try:
|
299 |
+
encoded = base64.b64encode(progress_data).decode()
|
300 |
return html.Div([
|
301 |
html.H4("PDF Generated Successfully"),
|
302 |
html.A(
|
|
|
324 |
|
325 |
def background_task(url, depth, task_id):
|
326 |
def progress_callback(message):
|
327 |
+
# Update progress in the progress-store
|
328 |
+
app.layout.children[1].data = message
|
329 |
|
330 |
try:
|
331 |
pdf_content = asyncio.run(process_url(url, depth, progress_callback))
|
332 |
+
# Store the result 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)}")
|