Ary-007 commited on
Commit
7b2a2d7
·
verified ·
1 Parent(s): 75b750d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -92,16 +92,27 @@ with st.sidebar:
92
 
93
  st.markdown("---")
94
  if st.button("🗑️ Clear Chat & Reset"):
95
- # Cleanup Pinecone
96
- cleanup_session_index(st.session_state.session_id)
97
- # Reset State
98
- st.session_state.session_id = str(uuid.uuid4())
99
- st.session_state.doc_store = SessionDocStore()
100
- st.session_state.messages = []
101
- st.session_state.bm25 = None
102
- st.session_state.processed_file = None
103
- st.session_state.uploader_key = str(uuid.uuid4())
104
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  st.markdown("### ℹ️ How to Use")
107
  st.info(
 
92
 
93
  st.markdown("---")
94
  if st.button("🗑️ Clear Chat & Reset"):
95
+ try:
96
+ # 1. Attempt Cleanup with visual feedback
97
+ with st.spinner(f"Deleting vector data for {st.session_state.session_id}..."):
98
+ cleanup_session_index(st.session_state.session_id)
99
+
100
+ # 2. Reset Local State (Only if cleanup succeeded)
101
+ st.session_state.session_id = str(uuid.uuid4())
102
+ st.session_state.doc_store = SessionDocStore()
103
+ st.session_state.messages = []
104
+ st.session_state.bm25 = None
105
+ st.session_state.processed_file = None
106
+ st.session_state.uploader_key = str(uuid.uuid4())
107
+
108
+ # 3. Re-attach Janitor for new session
109
+ st.session_state.janitor = SessionJanitor(st.session_state.session_id)
110
+
111
+ st.success("Cache cleared successfully!")
112
+ st.rerun()
113
+
114
+ except Exception as e:
115
+ st.error(f"Cleanup failed! Check Pinecone Console.\nError: {e}")
116
 
117
  st.markdown("### ℹ️ How to Use")
118
  st.info(