Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,7 @@ def upload_document(file_path, embed_model):
|
|
74 |
|
75 |
# Ensure the file is saved to the correct directory with secure handling
|
76 |
file_location = os.path.join(UPLOAD_DIR, os.path.basename(file_path))
|
|
|
77 |
|
78 |
# Safely copy the file to the upload directory
|
79 |
shutil.copy(file_path, file_location)
|
@@ -93,9 +94,14 @@ def upload_document(file_path, embed_model):
|
|
93 |
raise ValueError("Embedding model is not initialized properly.")
|
94 |
|
95 |
vector = embed_model.encode(text).astype("float32")
|
|
|
|
|
96 |
index.add_with_ids(np.array([vector]), np.array([doc_id], dtype=np.int64))
|
97 |
document_store[doc_id] = {"path": file_location, "text": text}
|
98 |
|
|
|
|
|
|
|
99 |
# Save the FAISS index after adding the document
|
100 |
try:
|
101 |
faiss.write_index(index, faiss_index_file)
|
|
|
74 |
|
75 |
# Ensure the file is saved to the correct directory with secure handling
|
76 |
file_location = os.path.join(UPLOAD_DIR, os.path.basename(file_path))
|
77 |
+
print(f"Saving file to: {file_location}") # Log the location
|
78 |
|
79 |
# Safely copy the file to the upload directory
|
80 |
shutil.copy(file_path, file_location)
|
|
|
94 |
raise ValueError("Embedding model is not initialized properly.")
|
95 |
|
96 |
vector = embed_model.encode(text).astype("float32")
|
97 |
+
print(f"Generated vector for document {doc_id}: {vector}") # Log vector
|
98 |
+
|
99 |
index.add_with_ids(np.array([vector]), np.array([doc_id], dtype=np.int64))
|
100 |
document_store[doc_id] = {"path": file_location, "text": text}
|
101 |
|
102 |
+
# Log FAISS index file path
|
103 |
+
print(f"Saving FAISS index to: {faiss_index_file}") # Log the file path
|
104 |
+
|
105 |
# Save the FAISS index after adding the document
|
106 |
try:
|
107 |
faiss.write_index(index, faiss_index_file)
|