Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
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")
|