bluenevus commited on
Commit
593df52
·
1 Parent(s): 936a628

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -673,7 +673,6 @@ def unified_master_callback(
673
  chat_input, cancel_clicks, preview_window_state,
674
  session_id_state, session_id_store_input
675
  ):
676
- # Determine session_id
677
  sid = get_session_id(session_id_state if session_id_state else session_id_store_input)
678
  sess_data = get_session_data(sid)
679
  ctx = callback_context
@@ -690,7 +689,6 @@ def unified_master_callback(
690
  doc_delete_clicks = safe_get_n_clicks(ctx, 8)
691
  proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
692
 
693
- # On first page load, just show the lists
694
  if not ctx.triggered or triggered_id in ['session-id-store']:
695
  doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
696
  doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
@@ -759,25 +757,29 @@ def unified_master_callback(
759
  else:
760
  logging.error(f"[{sid}] Failed to decode uploaded proposal: {proposal_filename}")
761
 
 
762
  if triggered_id and isinstance(doc_delete_clicks, list):
763
  for i, n_click in enumerate(doc_delete_clicks):
764
  if n_click:
765
  btn_id = ctx.inputs_list[8][i]['id']
766
  del_filename = btn_id['index']
 
767
  if del_filename in sess_data["uploaded_documents"]:
768
  del sess_data["uploaded_documents"][del_filename]
769
- if del_filename in sess_data["uploaded_documents_fileid"]:
770
- try:
771
- genai.delete_file(sess_data["uploaded_documents_fileid"][del_filename])
772
- except Exception as e:
773
- logging.warning(f"[{sid}] Failed to delete Gemini file {del_filename}: {e}")
774
- del sess_data["uploaded_documents_fileid"][del_filename]
775
- if del_filename in sess_data["uploaded_documents_bytes"]:
776
- del sess_data["uploaded_documents_bytes"][del_filename]
777
- logging.info(f"[{sid}] Document deleted: {del_filename}")
 
 
778
  if del_filename in sess_data["shredded_documents"]:
779
  del sess_data["shredded_documents"][del_filename]
780
- logging.info(f"[{sid}] Shredded doc deleted: {del_filename}")
781
  if selected_doc == del_filename:
782
  selected_doc = None
783
  break
@@ -787,15 +789,17 @@ def unified_master_callback(
787
  if n_click:
788
  btn_id = ctx.inputs_list[12][i]['id']
789
  del_filename = btn_id['index']
 
790
  if del_filename in sess_data["proposals"]:
791
  del sess_data["proposals"][del_filename]
792
- if del_filename in sess_data["proposals_fileid"]:
793
- try:
794
- genai.delete_file(sess_data["proposals_fileid"][del_filename])
795
- except Exception as e:
796
- logging.warning(f"[{sid}] Failed to delete Gemini proposal file {del_filename}: {e}")
797
- del sess_data["proposals_fileid"][del_filename]
798
- logging.info(f"[{sid}] Proposal deleted: {del_filename}")
 
799
  if selected_proposal == del_filename:
800
  selected_proposal = None
801
  break
 
673
  chat_input, cancel_clicks, preview_window_state,
674
  session_id_state, session_id_store_input
675
  ):
 
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
 
689
  doc_delete_clicks = safe_get_n_clicks(ctx, 8)
690
  proposal_delete_clicks = safe_get_n_clicks(ctx, 12)
691
 
 
692
  if not ctx.triggered or triggered_id in ['session-id-store']:
693
  doc_options = [{'label': truncate_filename(fn), 'value': fn} for fn in sess_data["uploaded_documents"].keys()]
694
  doc_value = next(iter(sess_data["uploaded_documents"]), None) if sess_data["uploaded_documents"] else None
 
757
  else:
758
  logging.error(f"[{sid}] Failed to decode uploaded proposal: {proposal_filename}")
759
 
760
+ # --- Fix for delete buttons below ---
761
  if triggered_id and isinstance(doc_delete_clicks, list):
762
  for i, n_click in enumerate(doc_delete_clicks):
763
  if n_click:
764
  btn_id = ctx.inputs_list[8][i]['id']
765
  del_filename = btn_id['index']
766
+ # Remove from uploaded_documents
767
  if del_filename in sess_data["uploaded_documents"]:
768
  del sess_data["uploaded_documents"][del_filename]
769
+ # Remove from uploaded_documents_fileid and delete Gemini file if exists
770
+ if del_filename in sess_data["uploaded_documents_fileid"]:
771
+ try:
772
+ genai.delete_file(sess_data["uploaded_documents_fileid"][del_filename])
773
+ except Exception as e:
774
+ logging.warning(f"[{sid}] Failed to delete Gemini file {del_filename}: {e}")
775
+ del sess_data["uploaded_documents_fileid"][del_filename]
776
+ # Remove from uploaded_documents_bytes
777
+ if del_filename in sess_data["uploaded_documents_bytes"]:
778
+ del sess_data["uploaded_documents_bytes"][del_filename]
779
+ # Remove from shredded_documents
780
  if del_filename in sess_data["shredded_documents"]:
781
  del sess_data["shredded_documents"][del_filename]
782
+ logging.info(f"[{sid}] Document deleted: {del_filename}")
783
  if selected_doc == del_filename:
784
  selected_doc = None
785
  break
 
789
  if n_click:
790
  btn_id = ctx.inputs_list[12][i]['id']
791
  del_filename = btn_id['index']
792
+ # Remove from proposals
793
  if del_filename in sess_data["proposals"]:
794
  del sess_data["proposals"][del_filename]
795
+ # Remove from proposals_fileid and delete Gemini file if exists
796
+ if del_filename in sess_data["proposals_fileid"]:
797
+ try:
798
+ genai.delete_file(sess_data["proposals_fileid"][del_filename])
799
+ except Exception as e:
800
+ logging.warning(f"[{sid}] Failed to delete Gemini proposal file {del_filename}: {e}")
801
+ del sess_data["proposals_fileid"][del_filename]
802
+ logging.info(f"[{sid}] Proposal deleted: {del_filename}")
803
  if selected_proposal == del_filename:
804
  selected_proposal = None
805
  break