Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -133,11 +133,17 @@ def delete_files(files_to_delete):
|
|
133 |
embed = get_embeddings()
|
134 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
135 |
|
136 |
-
#
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
# Save the updated database
|
140 |
-
|
141 |
|
142 |
# Update the document selector
|
143 |
updated_selector = gr.CheckboxGroup(
|
|
|
133 |
embed = get_embeddings()
|
134 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
135 |
|
136 |
+
# Create a new list of documents, excluding the deleted ones
|
137 |
+
new_docs = []
|
138 |
+
for i, doc_id in enumerate(database.index_to_docstore_id.values()):
|
139 |
+
if database.docstore._dict[doc_id].metadata["source"] not in deleted_files:
|
140 |
+
new_docs.append(database.docstore._dict[doc_id])
|
141 |
+
|
142 |
+
# Create a new FAISS index with the remaining documents
|
143 |
+
new_db = FAISS.from_documents(new_docs, embed)
|
144 |
|
145 |
# Save the updated database
|
146 |
+
new_db.save_local("faiss_database")
|
147 |
|
148 |
# Update the document selector
|
149 |
updated_selector = gr.CheckboxGroup(
|