Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -676,29 +676,23 @@ def unified_master_callback(
|
|
676 |
sid = get_session_id(session_id_state if session_id_state else session_id_store_input)
|
677 |
sess_data = get_session_data(sid)
|
678 |
ctx = callback_context
|
679 |
-
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0] if ctx.triggered else None
|
680 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
681 |
uploaded_rfp_decoded_bytes = None
|
682 |
|
683 |
-
#
|
684 |
is_doc_delete = False
|
685 |
is_proposal_delete = False
|
686 |
doc_del_filename = None
|
687 |
proposal_del_filename = None
|
688 |
-
if ctx.triggered and ctx.triggered[0]
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
prop_id = json.loads(prop_id_str.replace("'", '"'))
|
693 |
-
except Exception:
|
694 |
-
prop_id = None
|
695 |
-
if isinstance(prop_id, dict):
|
696 |
-
if prop_id.get('type') == 'delete-doc-btn' and prop_id.get('group') == 'doc':
|
697 |
is_doc_delete = True
|
698 |
-
doc_del_filename =
|
699 |
-
elif
|
700 |
is_proposal_delete = True
|
701 |
-
proposal_del_filename =
|
702 |
|
703 |
if is_doc_delete and doc_del_filename:
|
704 |
if doc_del_filename in sess_data["uploaded_documents"]:
|
@@ -713,7 +707,6 @@ def unified_master_callback(
|
|
713 |
del sess_data["uploaded_documents_bytes"][doc_del_filename]
|
714 |
if doc_del_filename in sess_data["shredded_documents"]:
|
715 |
del sess_data["shredded_documents"][doc_del_filename]
|
716 |
-
# Remove from disk if present
|
717 |
tempdir = sess_data.get("session_tempdir")
|
718 |
if tempdir and os.path.isdir(tempdir):
|
719 |
try:
|
@@ -735,7 +728,6 @@ def unified_master_callback(
|
|
735 |
except Exception as e:
|
736 |
logging.warning(f"[{sid}] Failed to delete Gemini proposal file {proposal_del_filename}: {e}")
|
737 |
del sess_data["proposals_fileid"][proposal_del_filename]
|
738 |
-
# Remove from disk if present
|
739 |
tempdir = sess_data.get("session_tempdir")
|
740 |
if tempdir and os.path.isdir(tempdir):
|
741 |
try:
|
@@ -757,7 +749,7 @@ def unified_master_callback(
|
|
757 |
doc_delete_clicks = safe_get_n_clicks(ctx, 8)
|
758 |
proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
|
759 |
|
760 |
-
if not ctx.triggered or
|
761 |
doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
|
762 |
doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
|
763 |
proposal_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["proposals"].keys()]
|
@@ -771,7 +763,7 @@ def unified_master_callback(
|
|
771 |
"expanded"
|
772 |
)
|
773 |
|
774 |
-
if
|
775 |
lock = sess_data.get("gemini_lock")
|
776 |
if lock and lock.locked():
|
777 |
try:
|
@@ -793,7 +785,7 @@ def unified_master_callback(
|
|
793 |
"expanded"
|
794 |
)
|
795 |
|
796 |
-
if
|
797 |
content_type, content_string = rfp_content.split(',')
|
798 |
decoded = base64.b64decode(content_string)
|
799 |
uploaded_rfp_decoded_bytes = decoded
|
@@ -810,7 +802,7 @@ def unified_master_callback(
|
|
810 |
else:
|
811 |
logging.error(f"[{sid}] Failed to decode uploaded document: {rfp_filename}")
|
812 |
|
813 |
-
if
|
814 |
content_type, content_string = proposal_content.split(',')
|
815 |
decoded = base64.b64decode(content_string)
|
816 |
text = decode_document(decoded)
|
@@ -837,7 +829,7 @@ def unified_master_callback(
|
|
837 |
'recover-action-btn', 'board-action-btn', 'loe-action-btn'
|
838 |
]
|
839 |
|
840 |
-
if
|
841 |
got_lock = sess_data["gemini_lock"].acquire(blocking=False)
|
842 |
if not got_lock:
|
843 |
output_data_upload = html.Div("Another Gemini operation is in progress. Please wait or cancel.", style={"wordWrap": "break-word"})
|
@@ -848,6 +840,7 @@ def unified_master_callback(
|
|
848 |
"expanded"
|
849 |
)
|
850 |
try:
|
|
|
851 |
if triggered_id == "shred-action-btn":
|
852 |
action_name = "shred"
|
853 |
result, generated_filename, generated_xlsx_bytes, _, _ = process_document(sess_data, action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, None)
|
|
|
676 |
sid = get_session_id(session_id_state if session_id_state else session_id_store_input)
|
677 |
sess_data = get_session_data(sid)
|
678 |
ctx = callback_context
|
|
|
679 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
680 |
uploaded_rfp_decoded_bytes = None
|
681 |
|
682 |
+
# NEW delete logic: use ctx.triggered[0]['id'] which is a dict for pattern-matched IDs
|
683 |
is_doc_delete = False
|
684 |
is_proposal_delete = False
|
685 |
doc_del_filename = None
|
686 |
proposal_del_filename = None
|
687 |
+
if ctx.triggered and ctx.triggered[0].get('id', None):
|
688 |
+
triggered_id_dict = ctx.triggered[0]['id']
|
689 |
+
if isinstance(triggered_id_dict, dict):
|
690 |
+
if triggered_id_dict.get('type') == 'delete-doc-btn' and triggered_id_dict.get('group') == 'doc':
|
|
|
|
|
|
|
|
|
|
|
691 |
is_doc_delete = True
|
692 |
+
doc_del_filename = triggered_id_dict.get('index')
|
693 |
+
elif triggered_id_dict.get('type') == 'delete-proposal-btn' and triggered_id_dict.get('group') == 'proposal':
|
694 |
is_proposal_delete = True
|
695 |
+
proposal_del_filename = triggered_id_dict.get('index')
|
696 |
|
697 |
if is_doc_delete and doc_del_filename:
|
698 |
if doc_del_filename in sess_data["uploaded_documents"]:
|
|
|
707 |
del sess_data["uploaded_documents_bytes"][doc_del_filename]
|
708 |
if doc_del_filename in sess_data["shredded_documents"]:
|
709 |
del sess_data["shredded_documents"][doc_del_filename]
|
|
|
710 |
tempdir = sess_data.get("session_tempdir")
|
711 |
if tempdir and os.path.isdir(tempdir):
|
712 |
try:
|
|
|
728 |
except Exception as e:
|
729 |
logging.warning(f"[{sid}] Failed to delete Gemini proposal file {proposal_del_filename}: {e}")
|
730 |
del sess_data["proposals_fileid"][proposal_del_filename]
|
|
|
731 |
tempdir = sess_data.get("session_tempdir")
|
732 |
if tempdir and os.path.isdir(tempdir):
|
733 |
try:
|
|
|
749 |
doc_delete_clicks = safe_get_n_clicks(ctx, 8)
|
750 |
proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
|
751 |
|
752 |
+
if not ctx.triggered or (ctx.triggered[0].get('prop_id', None) in ['session-id-store']):
|
753 |
doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
|
754 |
doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
|
755 |
proposal_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["proposals"].keys()]
|
|
|
763 |
"expanded"
|
764 |
)
|
765 |
|
766 |
+
if ctx.triggered[0].get('prop_id', None) == 'cancel-action-btn.n_clicks':
|
767 |
lock = sess_data.get("gemini_lock")
|
768 |
if lock and lock.locked():
|
769 |
try:
|
|
|
785 |
"expanded"
|
786 |
)
|
787 |
|
788 |
+
if ctx.triggered[0].get('prop_id', None) == 'upload-document.contents' and rfp_content is not None and rfp_filename:
|
789 |
content_type, content_string = rfp_content.split(',')
|
790 |
decoded = base64.b64decode(content_string)
|
791 |
uploaded_rfp_decoded_bytes = decoded
|
|
|
802 |
else:
|
803 |
logging.error(f"[{sid}] Failed to decode uploaded document: {rfp_filename}")
|
804 |
|
805 |
+
if ctx.triggered[0].get('prop_id', None) == 'upload-proposal.contents' and proposal_content is not None and proposal_filename:
|
806 |
content_type, content_string = proposal_content.split(',')
|
807 |
decoded = base64.b64decode(content_string)
|
808 |
text = decode_document(decoded)
|
|
|
829 |
'recover-action-btn', 'board-action-btn', 'loe-action-btn'
|
830 |
]
|
831 |
|
832 |
+
if ctx.triggered[0].get('prop_id', '').split('.')[0] in action_btns:
|
833 |
got_lock = sess_data["gemini_lock"].acquire(blocking=False)
|
834 |
if not got_lock:
|
835 |
output_data_upload = html.Div("Another Gemini operation is in progress. Please wait or cancel.", style={"wordWrap": "break-word"})
|
|
|
840 |
"expanded"
|
841 |
)
|
842 |
try:
|
843 |
+
triggered_id = ctx.triggered[0].get('prop_id', '').split('.')[0]
|
844 |
if triggered_id == "shred-action-btn":
|
845 |
action_name = "shred"
|
846 |
result, generated_filename, generated_xlsx_bytes, _, _ = process_document(sess_data, action_name, doc_value, chat_input, uploaded_rfp_decoded_bytes, None)
|