Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,9 +39,22 @@ def create_vector_db(uploaded_files):
|
|
39 |
model_kwargs={'device': 'cpu'}
|
40 |
)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Create and save FAISS database
|
43 |
db = FAISS.from_documents(texts, embeddings)
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
return True
|
46 |
|
47 |
def main():
|
@@ -63,4 +76,4 @@ def main():
|
|
63 |
st.error(f"An error occurred: {str(e)}")
|
64 |
|
65 |
if __name__ == "__main__":
|
66 |
-
main()
|
|
|
39 |
model_kwargs={'device': 'cpu'}
|
40 |
)
|
41 |
|
42 |
+
# Create the vectorstore directory if it doesn't exist
|
43 |
+
if not os.path.exists(DB_FAISS_PATH):
|
44 |
+
try:
|
45 |
+
os.makedirs(DB_FAISS_PATH)
|
46 |
+
print(f"Created directory {DB_FAISS_PATH}")
|
47 |
+
except Exception as e:
|
48 |
+
print(f"Error creating directory: {e}")
|
49 |
+
|
50 |
# Create and save FAISS database
|
51 |
db = FAISS.from_documents(texts, embeddings)
|
52 |
+
try:
|
53 |
+
db.save_local(DB_FAISS_PATH)
|
54 |
+
print(f"FAISS database saved to {DB_FAISS_PATH}")
|
55 |
+
except Exception as e:
|
56 |
+
print(f"Error saving FAISS database: {e}")
|
57 |
+
|
58 |
return True
|
59 |
|
60 |
def main():
|
|
|
76 |
st.error(f"An error occurred: {str(e)}")
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
+
main()
|