NaimaAqeel commited on
Commit
261cad3
·
verified ·
1 Parent(s): 43e526a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -45,16 +45,24 @@ embedding = HuggingFaceEmbeddings()
45
 
46
  # Load or create FAISS index
47
  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
- 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):
@@ -80,8 +88,11 @@ def upload_files(files):
80
 
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
 
@@ -119,6 +130,7 @@ with gr.Blocks() as demo:
119
 
120
  demo.launch()
121
 
 
122
 
123
 
124
 
 
45
 
46
  # Load or create FAISS index
47
  index_path = "faiss_index.pkl"
48
+ document_texts_path = "document_texts.pkl"
49
+
50
  if os.path.exists(index_path):
51
  with open(index_path, "rb") as f:
52
+ index = pickle.load(f)
53
+ print("Loaded FAISS index from faiss_index.pkl")
54
+ if os.path.exists(document_texts_path):
55
+ with open(document_texts_path, "rb") as f:
56
+ document_texts = pickle.load(f)
57
+ print("Loaded document texts from document_texts.pkl")
58
+ else:
59
+ document_texts = []
60
  else:
61
  # Create a new FAISS index if it doesn't exist
62
  index = faiss.IndexFlatL2(embedding_model.get_sentence_embedding_dimension())
63
  document_texts = []
64
  with open(index_path, "wb") as f:
65
+ pickle.dump(index, f)
66
  print("Created new FAISS index and saved to faiss_index.pkl")
67
 
68
  def upload_files(files):
 
88
 
89
  # Save the updated index and documents
90
  with open(index_path, "wb") as f:
91
+ pickle.dump(index, f)
92
+ print("Saved updated FAISS index to faiss_index.pkl")
93
+ with open(document_texts_path, "wb") as f:
94
+ pickle.dump(document_texts, f)
95
+ print("Saved updated document texts to document_texts.pkl")
96
 
97
  return "Files processed successfully"
98
 
 
130
 
131
  demo.launch()
132
 
133
+
134
 
135
 
136