Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -117,52 +117,6 @@ def update_vectors(files, parser):
|
|
117 |
label="Select documents to query"
|
118 |
)
|
119 |
|
120 |
-
def delete_files(files_to_delete):
|
121 |
-
global uploaded_documents
|
122 |
-
if not files_to_delete:
|
123 |
-
return "No files selected for deletion.", document_selector
|
124 |
-
|
125 |
-
deleted_files = []
|
126 |
-
for file_name in files_to_delete:
|
127 |
-
# Remove the file from uploaded_documents
|
128 |
-
uploaded_documents = [doc for doc in uploaded_documents if doc["name"] != file_name]
|
129 |
-
deleted_files.append(file_name)
|
130 |
-
|
131 |
-
# Update the FAISS database
|
132 |
-
if os.path.exists("faiss_database"):
|
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 |
-
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(
|
155 |
-
choices=[doc["name"] for doc in uploaded_documents],
|
156 |
-
value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
|
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")
|
168 |
full_response = ""
|
@@ -581,15 +535,6 @@ with demo:
|
|
581 |
update_button.click(update_vectors,
|
582 |
inputs=[file_input, parser_dropdown],
|
583 |
outputs=[update_output, document_selector])
|
584 |
-
|
585 |
-
# Add delete button
|
586 |
-
delete_button = gr.Button("Delete Selected Files")
|
587 |
-
delete_output = gr.Textbox(label="Delete Status")
|
588 |
-
|
589 |
-
# Connect delete button to the delete_files function
|
590 |
-
delete_button.click(delete_files,
|
591 |
-
inputs=[document_selector],
|
592 |
-
outputs=[delete_output, document_selector])
|
593 |
|
594 |
gr.Markdown(
|
595 |
"""
|
@@ -597,11 +542,10 @@ with demo:
|
|
597 |
1. Upload PDF documents using the file input at the top.
|
598 |
2. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store.
|
599 |
3. Select the documents you want to query using the checkboxes.
|
600 |
-
4.
|
601 |
-
5.
|
602 |
-
6.
|
603 |
-
7.
|
604 |
-
8. Use the provided examples or ask your own questions.
|
605 |
"""
|
606 |
)
|
607 |
|
|
|
117 |
label="Select documents to query"
|
118 |
)
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
def generate_chunked_response(prompt, model, max_tokens=10000, num_calls=3, temperature=0.2, should_stop=False):
|
121 |
print(f"Starting generate_chunked_response with {num_calls} calls")
|
122 |
full_response = ""
|
|
|
535 |
update_button.click(update_vectors,
|
536 |
inputs=[file_input, parser_dropdown],
|
537 |
outputs=[update_output, document_selector])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
gr.Markdown(
|
540 |
"""
|
|
|
542 |
1. Upload PDF documents using the file input at the top.
|
543 |
2. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store.
|
544 |
3. Select the documents you want to query using the checkboxes.
|
545 |
+
4. Ask questions in the chat interface.
|
546 |
+
5. Toggle "Use Web Search" to switch between PDF chat and web search.
|
547 |
+
6. Adjust Temperature and Number of API Calls to fine-tune the response generation.
|
548 |
+
7. Use the provided examples or ask your own questions.
|
|
|
549 |
"""
|
550 |
)
|
551 |
|