Shreyas094 commited on
Commit
4fda547
·
verified ·
1 Parent(s): 2e0823c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -139,11 +139,16 @@ def delete_files(files_to_delete):
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(
@@ -152,7 +157,11 @@ def delete_files(files_to_delete):
152
  label="Select documents to query"
153
  )
154
 
155
- return f"Deleted files: {', '.join(deleted_files)}", updated_selector
 
 
 
 
156
 
157
  def generate_chunked_response(prompt, model, max_tokens=10000, num_calls=3, temperature=0.2, should_stop=False):
158
  print(f"Starting generate_chunked_response with {num_calls} calls")
@@ -573,6 +582,12 @@ with demo:
573
  inputs=[file_input, parser_dropdown],
574
  outputs=[update_output, document_selector])
575
 
 
 
 
 
 
 
576
  # Add delete button
577
  delete_button = gr.Button("Delete Selected Files")
578
  delete_output = gr.Textbox(label="Delete Status")
 
139
  if database.docstore._dict[doc_id].metadata["source"] not in deleted_files:
140
  new_docs.append(database.docstore._dict[doc_id])
141
 
142
+ if new_docs:
143
+ # Create a new FAISS index with the remaining documents
144
+ new_db = FAISS.from_documents(new_docs, embed)
145
+
146
+ # Save the updated database
147
+ new_db.save_local("faiss_database")
148
+ else:
149
+ # If all documents were deleted, remove the database file
150
+ os.remove("faiss_database")
151
+ logging.info("All documents were deleted. Removed the FAISS database file.")
152
 
153
  # Update the document selector
154
  updated_selector = gr.CheckboxGroup(
 
157
  label="Select documents to query"
158
  )
159
 
160
+ status_message = f"Deleted files: {', '.join(deleted_files)}"
161
+ if not uploaded_documents:
162
+ status_message += "\nAll documents have been deleted. Please upload new documents to continue."
163
+
164
+ return status_message, updated_selector
165
 
166
  def generate_chunked_response(prompt, model, max_tokens=10000, num_calls=3, temperature=0.2, should_stop=False):
167
  print(f"Starting generate_chunked_response with {num_calls} calls")
 
582
  inputs=[file_input, parser_dropdown],
583
  outputs=[update_output, document_selector])
584
 
585
+ document_selector = gr.CheckboxGroup(
586
+ choices=[doc["name"] for doc in uploaded_documents],
587
+ value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
588
+ label="Select documents to query"
589
+ )
590
+
591
  # Add delete button
592
  delete_button = gr.Button("Delete Selected Files")
593
  delete_output = gr.Textbox(label="Delete Status")