Rulga commited on
Commit
199cd7b
·
1 Parent(s): 03a0824

fix errors

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -47,8 +47,8 @@ if 'messages' not in st.session_state:
47
  st.session_state.messages = []
48
 
49
  # Create history folder if not exists
50
- if not os.path.exists("chat_history"):
51
- os.makedirs("chat_history")
52
 
53
  # Display title and knowledge base info
54
  # st.title("www.Status.Law Legal Assistant")
@@ -71,7 +71,7 @@ if st.session_state.kb_info['build_time'] and st.session_state.kb_info['size']:
71
  f"size: {st.session_state.kb_info['size']:.2f} MB)")
72
 
73
  # Path to store vector database
74
- VECTOR_STORE_PATH = "vector_store"
75
 
76
  # Website URLs
77
  urls = [
@@ -134,7 +134,7 @@ def build_knowledge_base(embeddings):
134
 
135
  vector_store = FAISS.from_documents(chunks, embeddings)
136
 
137
- # Force save the vector store using absolute path
138
  force_save_vector_store(vector_store)
139
 
140
  end_time = time.time()
@@ -237,7 +237,8 @@ def force_save_vector_store(vector_store):
237
  if not os.access(index_file, os.R_OK | os.W_OK):
238
  raise Exception(f"Insufficient permissions for vector store files")
239
 
240
- st.caption("✅ Vector store saved successfully")
 
241
 
242
  except Exception as e:
243
  error_msg = f"❌ Failed to save vector store: {str(e)}"
@@ -270,6 +271,7 @@ def force_save_chat_history(chat_entry):
270
  json.dump(existing_history, f, ensure_ascii=False, indent=2)
271
  f.flush()
272
  os.fsync(f.fileno())
 
273
 
274
  # Verify file was created and is readable
275
  if not os.path.exists(filename):
@@ -278,7 +280,8 @@ def force_save_chat_history(chat_entry):
278
  if not os.access(filename, os.R_OK | os.W_OK):
279
  raise Exception(f"Insufficient permissions for chat history file")
280
 
281
- st.caption("✅ Chat history saved successfully")
 
282
 
283
  except Exception as e:
284
  error_msg = f"❌ Failed to save chat history: {str(e)}"
@@ -316,6 +319,11 @@ def main():
316
  except Exception as e:
317
  st.error(f"Error loading knowledge base: {e}")
318
  return
 
 
 
 
 
319
 
320
  # Chat mode
321
  if 'vector_store' in st.session_state:
 
47
  st.session_state.messages = []
48
 
49
  # Create history folder if not exists
50
+ #if not os.path.exists("chat_history"):
51
+ # os.makedirs("chat_history")
52
 
53
  # Display title and knowledge base info
54
  # st.title("www.Status.Law Legal Assistant")
 
71
  f"size: {st.session_state.kb_info['size']:.2f} MB)")
72
 
73
  # Path to store vector database
74
+ # VECTOR_STORE_PATH = "vector_store"
75
 
76
  # Website URLs
77
  urls = [
 
134
 
135
  vector_store = FAISS.from_documents(chunks, embeddings)
136
 
137
+ # Immediately save vector store after creation
138
  force_save_vector_store(vector_store)
139
 
140
  end_time = time.time()
 
237
  if not os.access(index_file, os.R_OK | os.W_OK):
238
  raise Exception(f"Insufficient permissions for vector store files")
239
 
240
+ #st.caption("✅ Vector store saved successfully")
241
+ st.toast("✅ Vector store saved", icon="💾")
242
 
243
  except Exception as e:
244
  error_msg = f"❌ Failed to save vector store: {str(e)}"
 
271
  json.dump(existing_history, f, ensure_ascii=False, indent=2)
272
  f.flush()
273
  os.fsync(f.fileno())
274
+ os.sync() # Принудительная синхронизация файловой системы
275
 
276
  # Verify file was created and is readable
277
  if not os.path.exists(filename):
 
280
  if not os.access(filename, os.R_OK | os.W_OK):
281
  raise Exception(f"Insufficient permissions for chat history file")
282
 
283
+ #st.caption("✅ Chat history saved successfully")
284
+ st.toast("✅ Chat history saved", icon="💬")
285
 
286
  except Exception as e:
287
  error_msg = f"❌ Failed to save chat history: {str(e)}"
 
319
  except Exception as e:
320
  st.error(f"Error loading knowledge base: {e}")
321
  return
322
+
323
+ with st.sidebar:
324
+ st.write(f"Working directory: {BASE_DIR}")
325
+ st.write(f"Vector store: {VECTOR_STORE_PATH}")
326
+ st.write(f"Chat history: {CHAT_HISTORY_DIR}")
327
 
328
  # Chat mode
329
  if 'vector_store' in st.session_state: