Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
|
@@ -254,7 +254,6 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
| 254 |
return result, None, None, None, None
|
| 255 |
|
| 256 |
elif action == 'recover':
|
| 257 |
-
# For recover: need compliance check or shred (selected_filename), and proposal (selected_proposal_filename)
|
| 258 |
if not selected_proposal_filename or selected_proposal_filename not in proposals:
|
| 259 |
logging.error("No proposal document selected for recovery.")
|
| 260 |
return "No proposal document selected for recovery.", None, None, None, None
|
|
@@ -267,7 +266,6 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
| 267 |
findings_fileid = uploaded_documents_fileid.get(selected_filename)
|
| 268 |
proposal_fileid = proposals_fileid.get(selected_proposal_filename)
|
| 269 |
|
| 270 |
-
# Upload findings doc if not already uploaded
|
| 271 |
if not findings_fileid:
|
| 272 |
if selected_filename in shredded_documents:
|
| 273 |
findings_bytes = shredded_documents[selected_filename]
|
|
@@ -284,7 +282,6 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
| 284 |
except Exception as e:
|
| 285 |
logging.error(f"Failed to upload findings doc {selected_filename} for recover: {e}")
|
| 286 |
|
| 287 |
-
# Upload proposal doc if not already uploaded
|
| 288 |
if not proposal_fileid:
|
| 289 |
proposal_bytes = None
|
| 290 |
if selected_proposal_filename in proposals:
|
|
@@ -315,7 +312,6 @@ def process_document(action, selected_filename=None, chat_input=None, rfp_decode
|
|
| 315 |
"---\nOriginal Proposal:\n"
|
| 316 |
f"{proposal_text}\n"
|
| 317 |
)
|
| 318 |
-
# If both are present, use both as file context for Gemini
|
| 319 |
used_fileid = None
|
| 320 |
if findings_fileid:
|
| 321 |
used_fileid = findings_fileid
|
|
@@ -507,6 +503,7 @@ app.layout = dbc.Container([
|
|
| 507 |
Input('shred-action-btn', 'n_clicks'),
|
| 508 |
Input('proposal-action-btn', 'n_clicks'),
|
| 509 |
Input('compliance-action-btn', 'n_clicks'),
|
|
|
|
| 510 |
Input('upload-document', 'contents'),
|
| 511 |
State('upload-document', 'filename'),
|
| 512 |
Input({'type': 'delete-doc-btn', 'index': ALL, 'group': 'doc'}, 'n_clicks'),
|
|
@@ -521,7 +518,7 @@ app.layout = dbc.Container([
|
|
| 521 |
prevent_initial_call=True
|
| 522 |
)
|
| 523 |
def master_callback(
|
| 524 |
-
shred_clicks, proposal_clicks, compliance_clicks,
|
| 525 |
rfp_content, rfp_filename, doc_delete_clicks, selected_doc,
|
| 526 |
proposal_content, proposal_filename, proposal_delete_clicks, selected_proposal,
|
| 527 |
chat_input, cancel_clicks
|
|
@@ -535,8 +532,8 @@ def master_callback(
|
|
| 535 |
except Exception:
|
| 536 |
return []
|
| 537 |
|
| 538 |
-
doc_delete_clicks = safe_get_n_clicks(ctx,
|
| 539 |
-
proposal_delete_clicks = safe_get_n_clicks(ctx,
|
| 540 |
uploaded_rfp_decoded_bytes = None
|
| 541 |
|
| 542 |
global gemini_lock, uploaded_documents_bytes
|
|
@@ -590,7 +587,7 @@ def master_callback(
|
|
| 590 |
if triggered_id and isinstance(doc_delete_clicks, list):
|
| 591 |
for i, n_click in enumerate(doc_delete_clicks):
|
| 592 |
if n_click:
|
| 593 |
-
btn_id = ctx.inputs_list[
|
| 594 |
del_filename = btn_id['index']
|
| 595 |
if del_filename in uploaded_documents:
|
| 596 |
del uploaded_documents[del_filename]
|
|
@@ -613,7 +610,7 @@ def master_callback(
|
|
| 613 |
if triggered_id and isinstance(proposal_delete_clicks, list):
|
| 614 |
for i, n_click in enumerate(proposal_delete_clicks):
|
| 615 |
if n_click:
|
| 616 |
-
btn_id = ctx.inputs_list[
|
| 617 |
del_filename = btn_id['index']
|
| 618 |
if del_filename in proposals:
|
| 619 |
del proposals[del_filename]
|
|
|
|
| 254 |
return result, None, None, None, None
|
| 255 |
|
| 256 |
elif action == 'recover':
|
|
|
|
| 257 |
if not selected_proposal_filename or selected_proposal_filename not in proposals:
|
| 258 |
logging.error("No proposal document selected for recovery.")
|
| 259 |
return "No proposal document selected for recovery.", None, None, None, None
|
|
|
|
| 266 |
findings_fileid = uploaded_documents_fileid.get(selected_filename)
|
| 267 |
proposal_fileid = proposals_fileid.get(selected_proposal_filename)
|
| 268 |
|
|
|
|
| 269 |
if not findings_fileid:
|
| 270 |
if selected_filename in shredded_documents:
|
| 271 |
findings_bytes = shredded_documents[selected_filename]
|
|
|
|
| 282 |
except Exception as e:
|
| 283 |
logging.error(f"Failed to upload findings doc {selected_filename} for recover: {e}")
|
| 284 |
|
|
|
|
| 285 |
if not proposal_fileid:
|
| 286 |
proposal_bytes = None
|
| 287 |
if selected_proposal_filename in proposals:
|
|
|
|
| 312 |
"---\nOriginal Proposal:\n"
|
| 313 |
f"{proposal_text}\n"
|
| 314 |
)
|
|
|
|
| 315 |
used_fileid = None
|
| 316 |
if findings_fileid:
|
| 317 |
used_fileid = findings_fileid
|
|
|
|
| 503 |
Input('shred-action-btn', 'n_clicks'),
|
| 504 |
Input('proposal-action-btn', 'n_clicks'),
|
| 505 |
Input('compliance-action-btn', 'n_clicks'),
|
| 506 |
+
Input('recover-action-btn', 'n_clicks'),
|
| 507 |
Input('upload-document', 'contents'),
|
| 508 |
State('upload-document', 'filename'),
|
| 509 |
Input({'type': 'delete-doc-btn', 'index': ALL, 'group': 'doc'}, 'n_clicks'),
|
|
|
|
| 518 |
prevent_initial_call=True
|
| 519 |
)
|
| 520 |
def master_callback(
|
| 521 |
+
shred_clicks, proposal_clicks, compliance_clicks, recover_clicks,
|
| 522 |
rfp_content, rfp_filename, doc_delete_clicks, selected_doc,
|
| 523 |
proposal_content, proposal_filename, proposal_delete_clicks, selected_proposal,
|
| 524 |
chat_input, cancel_clicks
|
|
|
|
| 532 |
except Exception:
|
| 533 |
return []
|
| 534 |
|
| 535 |
+
doc_delete_clicks = safe_get_n_clicks(ctx, 6)
|
| 536 |
+
proposal_delete_clicks = safe_get_n_clicks(ctx, 10)
|
| 537 |
uploaded_rfp_decoded_bytes = None
|
| 538 |
|
| 539 |
global gemini_lock, uploaded_documents_bytes
|
|
|
|
| 587 |
if triggered_id and isinstance(doc_delete_clicks, list):
|
| 588 |
for i, n_click in enumerate(doc_delete_clicks):
|
| 589 |
if n_click:
|
| 590 |
+
btn_id = ctx.inputs_list[6][i]['id']
|
| 591 |
del_filename = btn_id['index']
|
| 592 |
if del_filename in uploaded_documents:
|
| 593 |
del uploaded_documents[del_filename]
|
|
|
|
| 610 |
if triggered_id and isinstance(proposal_delete_clicks, list):
|
| 611 |
for i, n_click in enumerate(proposal_delete_clicks):
|
| 612 |
if n_click:
|
| 613 |
+
btn_id = ctx.inputs_list[10][i]['id']
|
| 614 |
del_filename = btn_id['index']
|
| 615 |
if del_filename in proposals:
|
| 616 |
del proposals[del_filename]
|