NaimaAqeel commited on
Commit
43e526a
·
verified ·
1 Parent(s): 47ecda0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -48,12 +48,14 @@ index_path = "faiss_index.pkl"
48
  if os.path.exists(index_path):
49
  with open(index_path, "rb") as f:
50
  index, document_texts = pickle.load(f)
 
51
  else:
52
  # Create a new FAISS index if it doesn't exist
53
  index = faiss.IndexFlatL2(embedding_model.get_sentence_embedding_dimension())
54
  document_texts = []
55
  with open(index_path, "wb") as f:
56
  pickle.dump((index, document_texts), f)
 
57
 
58
  def upload_files(files):
59
  global index, document_texts
@@ -79,6 +81,7 @@ def upload_files(files):
79
  # Save the updated index and documents
80
  with open(index_path, "wb") as f:
81
  pickle.dump((index, document_texts), f)
 
82
 
83
  return "Files processed successfully"
84
 
@@ -93,6 +96,8 @@ def query_text(text):
93
  for idx in I[0]:
94
  if idx != -1 and idx < len(document_texts): # Ensure that a valid index is found
95
  top_documents.append(document_texts[idx])
 
 
96
 
97
  return top_documents
98
 
 
48
  if os.path.exists(index_path):
49
  with open(index_path, "rb") as f:
50
  index, document_texts = pickle.load(f)
51
+ print("Loaded FAISS index and documents from faiss_index.pkl")
52
  else:
53
  # Create a new FAISS index if it doesn't exist
54
  index = faiss.IndexFlatL2(embedding_model.get_sentence_embedding_dimension())
55
  document_texts = []
56
  with open(index_path, "wb") as f:
57
  pickle.dump((index, document_texts), f)
58
+ print("Created new FAISS index and saved to faiss_index.pkl")
59
 
60
  def upload_files(files):
61
  global index, document_texts
 
81
  # Save the updated index and documents
82
  with open(index_path, "wb") as f:
83
  pickle.dump((index, document_texts), f)
84
+ print("Saved updated FAISS index and documents to faiss_index.pkl")
85
 
86
  return "Files processed successfully"
87
 
 
96
  for idx in I[0]:
97
  if idx != -1 and idx < len(document_texts): # Ensure that a valid index is found
98
  top_documents.append(document_texts[idx])
99
+ else:
100
+ print(f"Invalid index found: {idx}")
101
 
102
  return top_documents
103