bluenevus commited on
Commit
52e01cc
·
verified ·
1 Parent(s): bbd431d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -235,7 +235,9 @@ app.layout = dbc.Container([
235
  dcc.Slider(id="depth-slider", min=1, max=10, step=1, value=3, marks={i: str(i) for i in range(1, 11)}, className="mb-3"),
236
  dbc.Button("Convert to PDF", id="submit-button", color="primary", className="mb-3 w-100"),
237
  dbc.Button("Download PDF", id="download-button", color="secondary", className="mb-3 w-100", disabled=True),
238
- dbc.Spinner(html.Div(id="output-area"), color="primary", type="grow"),
 
 
239
  dcc.Interval(id="progress-interval", interval=1000, n_intervals=0, disabled=True),
240
  dcc.Download(id="download-pdf")
241
  ]),
@@ -243,18 +245,6 @@ app.layout = dbc.Container([
243
  )
244
  ], fluid=True)
245
 
246
- @app.callback(
247
- Output("download-button", "disabled"),
248
- Output("download-button", "color"),
249
- Output("progress-interval", "disabled"),
250
- Output("pdf-store", "data"),
251
- Input("submit-button", "n_clicks"),
252
- Input("progress-interval", "n_intervals"),
253
- Input("progress-store", "data"),
254
- State("url-input", "value"),
255
- State("depth-slider", "value"),
256
- prevent_initial_call=True
257
- )
258
  def update_output(n_clicks, n_intervals, progress_data, url, depth):
259
  ctx = dash.callback_context
260
  if not ctx.triggered:
@@ -264,26 +254,29 @@ def update_output(n_clicks, n_intervals, progress_data, url, depth):
264
 
265
  if triggered_id == "submit-button":
266
  if not url:
267
- return True, "secondary", True, None
268
 
269
  # Start the background task
270
  task_id = str(uuid.uuid4())
271
  executor.submit(background_task, url, depth, task_id)
272
 
273
- return True, "secondary", False, None
274
 
275
  elif triggered_id == "progress-interval" or triggered_id == "progress-store":
276
  if progress_data is None:
277
- return True, "secondary", False, None
278
 
279
- if isinstance(progress_data, str) and progress_data.startswith("Error"):
280
- return True, "secondary", True, None
 
 
 
281
 
282
  if isinstance(progress_data, bytes):
283
  encoded = base64.b64encode(progress_data).decode()
284
- return False, "primary", True, encoded
285
 
286
- return True, "secondary", False, None
287
 
288
  @app.callback(
289
  Output("download-pdf", "data"),
 
235
  dcc.Slider(id="depth-slider", min=1, max=10, step=1, value=3, marks={i: str(i) for i in range(1, 11)}, className="mb-3"),
236
  dbc.Button("Convert to PDF", id="submit-button", color="primary", className="mb-3 w-100"),
237
  dbc.Button("Download PDF", id="download-button", color="secondary", className="mb-3 w-100", disabled=True),
238
+ html.Div([
239
+ dbc.Spinner(html.Div(id="progress-message"), color="primary", type="grow", size="lg"),
240
+ ], className="text-center mb-3"),
241
  dcc.Interval(id="progress-interval", interval=1000, n_intervals=0, disabled=True),
242
  dcc.Download(id="download-pdf")
243
  ]),
 
245
  )
246
  ], fluid=True)
247
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  def update_output(n_clicks, n_intervals, progress_data, url, depth):
249
  ctx = dash.callback_context
250
  if not ctx.triggered:
 
254
 
255
  if triggered_id == "submit-button":
256
  if not url:
257
+ return True, "secondary", True, None, "Please enter a URL"
258
 
259
  # Start the background task
260
  task_id = str(uuid.uuid4())
261
  executor.submit(background_task, url, depth, task_id)
262
 
263
+ return True, "secondary", False, None, "Processing... Please wait."
264
 
265
  elif triggered_id == "progress-interval" or triggered_id == "progress-store":
266
  if progress_data is None:
267
+ return True, "secondary", False, None, "Processing... Please wait."
268
 
269
+ if isinstance(progress_data, str):
270
+ if progress_data.startswith("Error"):
271
+ return True, "secondary", True, None, progress_data
272
+ else:
273
+ return True, "secondary", False, None, progress_data
274
 
275
  if isinstance(progress_data, bytes):
276
  encoded = base64.b64encode(progress_data).decode()
277
+ return False, "primary", True, encoded, "PDF ready for download!"
278
 
279
+ return True, "secondary", False, None, ""
280
 
281
  @app.callback(
282
  Output("download-pdf", "data"),