Spaces:
Sleeping
Sleeping
Tushar Malik
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -506,21 +506,19 @@ def chatbot_interface(user_query, response_style, selected_retrieval_methods, se
|
|
| 506 |
vector_db_path = "vector_db.pkl"
|
| 507 |
annoy_index_path = "vector_index.ann"
|
| 508 |
|
| 509 |
-
pdf_path = pdf_file.name
|
| 510 |
-
create_vector_db_and_annoy_index(pdf_path, 'vector_db.pkl', 'vector_index.ann')
|
| 511 |
-
store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
|
| 512 |
|
| 513 |
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
|
|
|
| 524 |
# if pdf_file is not None:
|
| 525 |
# pdf_path = pdf_file.name # Get the path of the uploaded file
|
| 526 |
# create_vector_db_and_annoy_index(pdf_path, 'vector_db.pkl', 'vector_index.ann')
|
|
|
|
| 506 |
vector_db_path = "vector_db.pkl"
|
| 507 |
annoy_index_path = "vector_index.ann"
|
| 508 |
|
|
|
|
|
|
|
|
|
|
| 509 |
|
| 510 |
|
| 511 |
+
|
| 512 |
+
if pdf_file is not None:
|
| 513 |
+
with tempfile.NamedTemporaryFile(mode="wb", suffix=".pdf", delete=False) as tmp:
|
| 514 |
+
tmp.write(pdf_file) # Write the uploaded file content to the temporary file
|
| 515 |
+
pdf_path = tmp.name
|
| 516 |
+
|
| 517 |
+
# Create vector DB and Annoy index
|
| 518 |
+
create_vector_db_and_annoy_index(pdf_path, vector_db_path, annoy_index_path)
|
| 519 |
+
store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
|
| 520 |
+
else:
|
| 521 |
+
return "Please upload a PDF file."
|
| 522 |
# if pdf_file is not None:
|
| 523 |
# pdf_path = pdf_file.name # Get the path of the uploaded file
|
| 524 |
# create_vector_db_and_annoy_index(pdf_path, 'vector_db.pkl', 'vector_index.ann')
|