Spaces:
Sleeping
Sleeping
Tushar Malik
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -509,16 +509,18 @@ def chatbot_interface(user_query, response_style, selected_retrieval_methods, se
|
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
-
|
|
|
|
| 513 |
with tempfile.NamedTemporaryFile(mode="wb", suffix=".pdf", delete=False) as tmp:
|
| 514 |
-
|
| 515 |
-
|
|
|
|
| 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')
|
|
|
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
+
if pdf_file is not None:
|
| 513 |
+
# Assume `pdf_file` is the path to the file, so no need for `.read()`
|
| 514 |
with tempfile.NamedTemporaryFile(mode="wb", suffix=".pdf", delete=False) as tmp:
|
| 515 |
+
with open(pdf_file, "rb") as f: # Open the file in binary mode
|
| 516 |
+
tmp.write(f.read()) # Write the file content to the temporary file
|
| 517 |
+
pdf_path = tmp.name # Store the path of the temporary file
|
| 518 |
|
| 519 |
+
# Create vector DB and Annoy index
|
| 520 |
create_vector_db_and_annoy_index(pdf_path, vector_db_path, annoy_index_path)
|
| 521 |
store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
|
| 522 |
else:
|
| 523 |
+
return "Please upload a PDF file."
|
| 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')
|