bluenevus commited on
Commit
2129dfb
·
1 Parent(s): 579948a

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -45,7 +45,6 @@ def get_right_col_content(selected_type):
45
  html.Div([
46
  html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
47
  ], style={'textAlign':'center', 'marginBottom':'10px'}),
48
- html.Div(id='status-bar', className="alert alert-info", style={'marginBottom': '20px'}),
49
  dcc.Loading(
50
  id="loading-indicator",
51
  type="dot",
@@ -70,7 +69,6 @@ def get_right_col_content(selected_type):
70
  html.Div([
71
  html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
72
  ], style={'textAlign':'center', 'marginBottom':'10px'}),
73
- html.Div(id='status-bar', className="alert alert-info", style={'marginBottom': '20px'}),
74
  dcc.Loading(
75
  id="loading-indicator",
76
  type="dot",
@@ -188,7 +186,6 @@ def process_document(contents, filename):
188
 
189
  @app.callback(
190
  Output('file-list', 'children'),
191
- Output('status-bar', 'children'),
192
  Input('upload-document', 'contents'),
193
  State('upload-document', 'filename'),
194
  State('file-list', 'children')
@@ -208,12 +205,11 @@ def update_output(list_of_contents, list_of_names, existing_files):
208
  existing_files = []
209
  shredded_document = None
210
  logging.info("Documents uploaded and file list updated.")
211
- return existing_files + new_files, "Document uploaded. Please click 'Shred' to proceed."
212
- return existing_files, "Please upload a document and click 'Shred' to begin."
213
 
214
  @app.callback(
215
  Output('file-list', 'children', allow_duplicate=True),
216
- Output('status-bar', 'children', allow_duplicate=True),
217
  Input({'type': 'remove-file', 'index': ALL}, 'n_clicks'),
218
  State('file-list', 'children'),
219
  prevent_initial_call=True
@@ -227,7 +223,7 @@ def remove_file(n_clicks, existing_files):
227
  uploaded_files.pop(removed_file, None)
228
  shredded_document = None
229
  logging.info(f"Removed file: {removed_file}")
230
- return [file for file in existing_files if file['props']['children'][1]['props']['children'] != removed_file], "Document removed. Please upload a document and click 'Shred' to begin."
231
 
232
  @app.callback(
233
  Output('right-col-content', 'children'),
@@ -298,22 +294,21 @@ Now, generate the {document_type}:
298
  @app.callback(
299
  Output('document-preview', 'children'),
300
  Output('loading-output', 'children'),
301
- Output('status-bar', 'children', allow_duplicate=True),
302
  Input({'type': 'btn-doc-type', 'index': 'Shred'}, 'n_clicks'),
303
  prevent_initial_call=True
304
  )
305
  def generate_shred_doc(n_clicks):
306
  global current_document, document_type, shredded_document
307
  if not uploaded_files:
308
- return html.Div("Please upload a document before shredding."), "", "Please upload a document before shredding."
309
  file_contents = list(uploaded_files.values())
310
  try:
311
  shredded_document = generate_document("Shred", file_contents)
312
  current_document = shredded_document
313
- return dcc.Markdown(shredded_document), "Shred generated", "Document shredded. You can now proceed with other operations."
314
  except Exception as e:
315
  logging.error(f"Error generating document: {str(e)}")
316
- return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while shredding the document."
317
 
318
  @app.callback(
319
  Output({'type': 'uploaded-doc-name', 'index': MATCH}, 'children'),
@@ -332,7 +327,6 @@ def update_uploaded_doc_name(contents, filename, id_dict):
332
  @app.callback(
333
  Output('document-preview', 'children', allow_duplicate=True),
334
  Output('loading-output', 'children', allow_duplicate=True),
335
- Output('status-bar', 'children', allow_duplicate=True),
336
  Input({'type': 'btn-generate-doc', 'index': ALL}, 'n_clicks'),
337
  State({'type': 'btn-generate-doc', 'index': ALL}, 'id'),
338
  State({'type': 'radio-doc-source', 'index': ALL}, 'value'),
@@ -356,7 +350,7 @@ def generate_other_doc(n_clicks_list, btn_ids, radio_values, upload_contents, up
356
  raise dash.exceptions.PreventUpdate
357
 
358
  if shredded_document is None:
359
- return html.Div("Please shred a document first."), "", "Please shred a document first."
360
 
361
  source = radio_values[idx] if radio_values and len(radio_values) > idx else 'loaded'
362
  doc_content = None
@@ -365,7 +359,7 @@ def generate_other_doc(n_clicks_list, btn_ids, radio_values, upload_contents, up
365
  if upload_contents and len(upload_contents) > idx and upload_contents[idx] and upload_filenames and len(upload_filenames) > idx and upload_filenames[idx]:
366
  doc_content = process_document(upload_contents[idx], upload_filenames[idx])
367
  else:
368
- return html.Div("Please upload a document to use as source."), "", "Please upload a document to use as source."
369
  else:
370
  if doc_type == "Pink":
371
  doc_content = shredded_document
@@ -395,10 +389,10 @@ def generate_other_doc(n_clicks_list, btn_ids, radio_values, upload_contents, up
395
  else:
396
  current_document = generate_document(doc_type, [doc_content])
397
  logging.info(f"{doc_type} document generated successfully.")
398
- return dcc.Markdown(current_document), f"{doc_type} generated", f"{doc_type} document generated successfully."
399
  except Exception as e:
400
  logging.error(f"Error generating document: {str(e)}")
401
- return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while generating the document."
402
 
403
  @app.callback(
404
  Output('chat-output', 'children'),
 
45
  html.Div([
46
  html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
47
  ], style={'textAlign':'center', 'marginBottom':'10px'}),
 
48
  dcc.Loading(
49
  id="loading-indicator",
50
  type="dot",
 
69
  html.Div([
70
  html.Div(className="blinking-dot", style={'margin':'0 auto','width':'16px','height':'16px'}),
71
  ], style={'textAlign':'center', 'marginBottom':'10px'}),
 
72
  dcc.Loading(
73
  id="loading-indicator",
74
  type="dot",
 
186
 
187
  @app.callback(
188
  Output('file-list', 'children'),
 
189
  Input('upload-document', 'contents'),
190
  State('upload-document', 'filename'),
191
  State('file-list', 'children')
 
205
  existing_files = []
206
  shredded_document = None
207
  logging.info("Documents uploaded and file list updated.")
208
+ return existing_files + new_files
209
+ return existing_files
210
 
211
  @app.callback(
212
  Output('file-list', 'children', allow_duplicate=True),
 
213
  Input({'type': 'remove-file', 'index': ALL}, 'n_clicks'),
214
  State('file-list', 'children'),
215
  prevent_initial_call=True
 
223
  uploaded_files.pop(removed_file, None)
224
  shredded_document = None
225
  logging.info(f"Removed file: {removed_file}")
226
+ return [file for file in existing_files if file['props']['children'][1]['props']['children'] != removed_file]
227
 
228
  @app.callback(
229
  Output('right-col-content', 'children'),
 
294
  @app.callback(
295
  Output('document-preview', 'children'),
296
  Output('loading-output', 'children'),
 
297
  Input({'type': 'btn-doc-type', 'index': 'Shred'}, 'n_clicks'),
298
  prevent_initial_call=True
299
  )
300
  def generate_shred_doc(n_clicks):
301
  global current_document, document_type, shredded_document
302
  if not uploaded_files:
303
+ return html.Div("Please upload a document before shredding."), ""
304
  file_contents = list(uploaded_files.values())
305
  try:
306
  shredded_document = generate_document("Shred", file_contents)
307
  current_document = shredded_document
308
+ return dcc.Markdown(shredded_document), "Shred generated"
309
  except Exception as e:
310
  logging.error(f"Error generating document: {str(e)}")
311
+ return html.Div(f"Error generating document: {str(e)}"), "Error"
312
 
313
  @app.callback(
314
  Output({'type': 'uploaded-doc-name', 'index': MATCH}, 'children'),
 
327
  @app.callback(
328
  Output('document-preview', 'children', allow_duplicate=True),
329
  Output('loading-output', 'children', allow_duplicate=True),
 
330
  Input({'type': 'btn-generate-doc', 'index': ALL}, 'n_clicks'),
331
  State({'type': 'btn-generate-doc', 'index': ALL}, 'id'),
332
  State({'type': 'radio-doc-source', 'index': ALL}, 'value'),
 
350
  raise dash.exceptions.PreventUpdate
351
 
352
  if shredded_document is None:
353
+ return html.Div("Please shred a document first."), ""
354
 
355
  source = radio_values[idx] if radio_values and len(radio_values) > idx else 'loaded'
356
  doc_content = None
 
359
  if upload_contents and len(upload_contents) > idx and upload_contents[idx] and upload_filenames and len(upload_filenames) > idx and upload_filenames[idx]:
360
  doc_content = process_document(upload_contents[idx], upload_filenames[idx])
361
  else:
362
+ return html.Div("Please upload a document to use as source."), ""
363
  else:
364
  if doc_type == "Pink":
365
  doc_content = shredded_document
 
389
  else:
390
  current_document = generate_document(doc_type, [doc_content])
391
  logging.info(f"{doc_type} document generated successfully.")
392
+ return dcc.Markdown(current_document), f"{doc_type} generated"
393
  except Exception as e:
394
  logging.error(f"Error generating document: {str(e)}")
395
+ return html.Div(f"Error generating document: {str(e)}"), "Error"
396
 
397
  @app.callback(
398
  Output('chat-output', 'children'),