Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -680,67 +680,73 @@ def unified_master_callback(
|
|
680 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
681 |
uploaded_rfp_decoded_bytes = None
|
682 |
|
683 |
-
#
|
684 |
-
|
|
|
|
|
|
|
685 |
if ctx.triggered and ctx.triggered[0]['prop_id']:
|
686 |
prop_id_str = ctx.triggered[0]['prop_id'].split('.')[0]
|
687 |
-
|
688 |
-
|
689 |
-
prop_id =
|
690 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
try:
|
692 |
-
|
693 |
-
|
|
|
694 |
except Exception:
|
695 |
-
|
696 |
-
if
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
logging.info(f"[{sid}] Document deleted: {del_filename}")
|
722 |
-
elif isinstance(prop_id, dict) and prop_id.get('type') == 'delete-proposal-btn' and prop_id.get('group') == 'proposal':
|
723 |
-
del_filename = prop_id.get('index')
|
724 |
-
if del_filename in sess_data["proposals"]:
|
725 |
-
del sess_data["proposals"][del_filename]
|
726 |
-
if del_filename in sess_data["proposals_fileid"]:
|
727 |
-
try:
|
728 |
-
genai.delete_file(sess_data["proposals_fileid"][del_filename])
|
729 |
-
except Exception as e:
|
730 |
-
logging.warning(f"[{sid}] Failed to delete Gemini proposal file {del_filename}: {e}")
|
731 |
-
del sess_data["proposals_fileid"][del_filename]
|
732 |
-
# If there are temp files on disk, attempt to remove them
|
733 |
-
tempdir = sess_data.get("session_tempdir")
|
734 |
-
if tempdir and os.path.isdir(tempdir):
|
735 |
-
try:
|
736 |
-
file_path = os.path.join(tempdir, del_filename)
|
737 |
-
if os.path.exists(file_path):
|
738 |
-
os.remove(file_path)
|
739 |
-
except Exception:
|
740 |
-
pass
|
741 |
-
if selected_proposal == del_filename:
|
742 |
-
selected_proposal = None
|
743 |
-
logging.info(f"[{sid}] Proposal deleted: {del_filename}")
|
744 |
|
745 |
def safe_get_n_clicks(ctx, idx):
|
746 |
try:
|
|
|
680 |
output_data_upload = html.Div("No action taken yet.", style={"wordWrap": "break-word"})
|
681 |
uploaded_rfp_decoded_bytes = None
|
682 |
|
683 |
+
# Robust delete button handling for pattern-matching IDs
|
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]['prop_id']:
|
689 |
prop_id_str = ctx.triggered[0]['prop_id'].split('.')[0]
|
690 |
+
try:
|
691 |
+
import json
|
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 = prop_id.get('index')
|
699 |
+
elif prop_id.get('type') == 'delete-proposal-btn' and prop_id.get('group') == 'proposal':
|
700 |
+
is_proposal_delete = True
|
701 |
+
proposal_del_filename = prop_id.get('index')
|
702 |
+
|
703 |
+
if is_doc_delete and doc_del_filename:
|
704 |
+
if doc_del_filename in sess_data["uploaded_documents"]:
|
705 |
+
del sess_data["uploaded_documents"][doc_del_filename]
|
706 |
+
if doc_del_filename in sess_data["uploaded_documents_fileid"]:
|
707 |
+
try:
|
708 |
+
genai.delete_file(sess_data["uploaded_documents_fileid"][doc_del_filename])
|
709 |
+
except Exception as e:
|
710 |
+
logging.warning(f"[{sid}] Failed to delete Gemini file {doc_del_filename}: {e}")
|
711 |
+
del sess_data["uploaded_documents_fileid"][doc_del_filename]
|
712 |
+
if doc_del_filename in sess_data["uploaded_documents_bytes"]:
|
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:
|
720 |
+
file_path = os.path.join(tempdir, doc_del_filename)
|
721 |
+
if os.path.exists(file_path):
|
722 |
+
os.remove(file_path)
|
723 |
except Exception:
|
724 |
+
pass
|
725 |
+
if selected_doc == doc_del_filename:
|
726 |
+
selected_doc = None
|
727 |
+
logging.info(f"[{sid}] Document deleted: {doc_del_filename}")
|
728 |
+
|
729 |
+
if is_proposal_delete and proposal_del_filename:
|
730 |
+
if proposal_del_filename in sess_data["proposals"]:
|
731 |
+
del sess_data["proposals"][proposal_del_filename]
|
732 |
+
if proposal_del_filename in sess_data["proposals_fileid"]:
|
733 |
+
try:
|
734 |
+
genai.delete_file(sess_data["proposals_fileid"][proposal_del_filename])
|
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:
|
742 |
+
file_path = os.path.join(tempdir, proposal_del_filename)
|
743 |
+
if os.path.exists(file_path):
|
744 |
+
os.remove(file_path)
|
745 |
+
except Exception:
|
746 |
+
pass
|
747 |
+
if selected_proposal == proposal_del_filename:
|
748 |
+
selected_proposal = None
|
749 |
+
logging.info(f"[{sid}] Proposal deleted: {proposal_del_filename}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
750 |
|
751 |
def safe_get_n_clicks(ctx, idx):
|
752 |
try:
|