Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -64,12 +64,10 @@ def process_document(action, selected_filename=None, chat_input=None):
|
|
64 |
global shredded_document, generated_response
|
65 |
logging.info(f"Process document called with action: {action}")
|
66 |
|
67 |
-
# Select document content to use, if needed
|
68 |
doc_content = None
|
69 |
if selected_filename and selected_filename in uploaded_documents:
|
70 |
doc_content = uploaded_documents[selected_filename]
|
71 |
elif uploaded_documents:
|
72 |
-
# Default to the first document if not specified
|
73 |
doc_content = next(iter(uploaded_documents.values()))
|
74 |
selected_filename = next(iter(uploaded_documents.keys()))
|
75 |
else:
|
@@ -261,13 +259,11 @@ def update_uploaded_docs(content, filename, delete_clicks, children, selected_do
|
|
261 |
if delete_clicks:
|
262 |
for i, n_click in enumerate(delete_clicks):
|
263 |
if n_click:
|
264 |
-
# The delete button's id is a dict with 'index' = filename
|
265 |
btn_id = ctx.inputs_list[2][i]['id']
|
266 |
del_filename = btn_id['index']
|
267 |
if del_filename in uploaded_documents:
|
268 |
del uploaded_documents[del_filename]
|
269 |
logging.info(f"Document deleted: {del_filename}")
|
270 |
-
# If the selected doc is deleted, choose another
|
271 |
if selected_doc == del_filename:
|
272 |
selected_doc = next(iter(uploaded_documents), None)
|
273 |
break
|
@@ -290,7 +286,6 @@ def handle_upload(content, filename):
|
|
290 |
if text is None:
|
291 |
return html.Div("Error: Could not decode document. Please upload a valid text file.", style={"wordWrap": "break-word"})
|
292 |
else:
|
293 |
-
# Already handled and added in update_uploaded_docs
|
294 |
return html.Div(f"Document '{filename}' uploaded successfully.", style={"wordWrap": "break-word"})
|
295 |
return ""
|
296 |
|
@@ -312,22 +307,29 @@ def handle_actions(shred_clicks, generate_clicks, compliance_clicks, recover_cli
|
|
312 |
ctx = callback_context
|
313 |
if not ctx.triggered:
|
314 |
logging.info("No action triggered yet.")
|
315 |
-
return "No action taken yet."
|
316 |
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
317 |
logging.info(f"Button pressed: {button_id}")
|
|
|
318 |
if button_id == 'shred-action-btn':
|
319 |
-
|
320 |
elif button_id == 'generate-action-btn':
|
321 |
-
|
322 |
elif button_id == 'compliance-action-btn':
|
323 |
-
|
324 |
elif button_id == 'recover-action-btn':
|
325 |
-
|
326 |
elif button_id == 'board-action-btn':
|
327 |
-
|
328 |
elif button_id == 'loe-action-btn':
|
329 |
-
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
if __name__ == '__main__':
|
333 |
print("Starting the Dash application...")
|
|
|
64 |
global shredded_document, generated_response
|
65 |
logging.info(f"Process document called with action: {action}")
|
66 |
|
|
|
67 |
doc_content = None
|
68 |
if selected_filename and selected_filename in uploaded_documents:
|
69 |
doc_content = uploaded_documents[selected_filename]
|
70 |
elif uploaded_documents:
|
|
|
71 |
doc_content = next(iter(uploaded_documents.values()))
|
72 |
selected_filename = next(iter(uploaded_documents.keys()))
|
73 |
else:
|
|
|
259 |
if delete_clicks:
|
260 |
for i, n_click in enumerate(delete_clicks):
|
261 |
if n_click:
|
|
|
262 |
btn_id = ctx.inputs_list[2][i]['id']
|
263 |
del_filename = btn_id['index']
|
264 |
if del_filename in uploaded_documents:
|
265 |
del uploaded_documents[del_filename]
|
266 |
logging.info(f"Document deleted: {del_filename}")
|
|
|
267 |
if selected_doc == del_filename:
|
268 |
selected_doc = next(iter(uploaded_documents), None)
|
269 |
break
|
|
|
286 |
if text is None:
|
287 |
return html.Div("Error: Could not decode document. Please upload a valid text file.", style={"wordWrap": "break-word"})
|
288 |
else:
|
|
|
289 |
return html.Div(f"Document '{filename}' uploaded successfully.", style={"wordWrap": "break-word"})
|
290 |
return ""
|
291 |
|
|
|
307 |
ctx = callback_context
|
308 |
if not ctx.triggered:
|
309 |
logging.info("No action triggered yet.")
|
310 |
+
return html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
311 |
button_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
312 |
logging.info(f"Button pressed: {button_id}")
|
313 |
+
result = ""
|
314 |
if button_id == 'shred-action-btn':
|
315 |
+
result = process_document('shred', selected_filename, chat_input)
|
316 |
elif button_id == 'generate-action-btn':
|
317 |
+
result = process_document('generate', selected_filename, chat_input)
|
318 |
elif button_id == 'compliance-action-btn':
|
319 |
+
result = process_document('compliance', selected_filename, chat_input)
|
320 |
elif button_id == 'recover-action-btn':
|
321 |
+
result = process_document('recover', selected_filename, chat_input)
|
322 |
elif button_id == 'board-action-btn':
|
323 |
+
result = process_document('board', selected_filename, chat_input)
|
324 |
elif button_id == 'loe-action-btn':
|
325 |
+
result = process_document('loe', selected_filename, chat_input)
|
326 |
+
else:
|
327 |
+
result = "Action not implemented yet."
|
328 |
+
if isinstance(result, str) and result.strip().startswith("Error"):
|
329 |
+
return html.Div(result, style={"wordWrap": "break-word"})
|
330 |
+
if isinstance(result, str) and ("not implemented" in result or "No document uploaded" in result or "Shredding in progress" in result or "Generating response" in result or "Shredded document not available" in result):
|
331 |
+
return html.Div(result, style={"wordWrap": "break-word"})
|
332 |
+
return dcc.Markdown(result, style={"whiteSpace": "pre-wrap", "wordWrap": "break-word"})
|
333 |
|
334 |
if __name__ == '__main__':
|
335 |
print("Starting the Dash application...")
|