Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,13 +45,11 @@ api_key = os.getenv("OPENAI_API_KEY")
|
|
| 45 |
# Retrieve the API key from st.secrets
|
| 46 |
|
| 47 |
|
| 48 |
-
|
| 49 |
# Updated caching mechanism using st.cache_data
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
def load_vector_store(file_path, store_name, force_reload=False):
|
| 54 |
-
|
|
|
|
| 55 |
if force_reload or not os.path.exists(f"{store_name}.pkl"):
|
| 56 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 57 |
chunk_size=1000,
|
|
@@ -64,22 +62,12 @@ def load_vector_store(file_path, store_name, force_reload=False):
|
|
| 64 |
|
| 65 |
embeddings = OpenAIEmbeddings()
|
| 66 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
| 67 |
-
|
| 68 |
-
# Inspect the VectorStore object
|
| 69 |
-
print("Inspecting VectorStore object...")
|
| 70 |
-
print("Type of VectorStore:", type(VectorStore))
|
| 71 |
-
print("Attributes of VectorStore:", dir(VectorStore))
|
| 72 |
-
|
| 73 |
-
# Additional specific inspections if necessary
|
| 74 |
-
# for example, if VectorStore has an attribute 'some_attribute':
|
| 75 |
-
# print("VectorStore.some_attribute:", VectorStore.some_attribute)
|
| 76 |
-
|
| 77 |
with open(f"{store_name}.pkl", "wb") as f:
|
| 78 |
pickle.dump(VectorStore, f)
|
| 79 |
else:
|
| 80 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 81 |
VectorStore = pickle.load(f)
|
| 82 |
-
|
| 83 |
return VectorStore
|
| 84 |
|
| 85 |
except Exception as e:
|
|
|
|
| 45 |
# Retrieve the API key from st.secrets
|
| 46 |
|
| 47 |
|
|
|
|
| 48 |
# Updated caching mechanism using st.cache_data
|
| 49 |
+
@st.cache_data(persist="disk") # Using persist="disk" to save cache across sessions
|
|
|
|
|
|
|
| 50 |
def load_vector_store(file_path, store_name, force_reload=False):
|
| 51 |
+
|
| 52 |
+
# Check if we need to force reload the vector store (e.g., when the PDF changes)
|
| 53 |
if force_reload or not os.path.exists(f"{store_name}.pkl"):
|
| 54 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 55 |
chunk_size=1000,
|
|
|
|
| 62 |
|
| 63 |
embeddings = OpenAIEmbeddings()
|
| 64 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
with open(f"{store_name}.pkl", "wb") as f:
|
| 66 |
pickle.dump(VectorStore, f)
|
| 67 |
else:
|
| 68 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 69 |
VectorStore = pickle.load(f)
|
| 70 |
+
|
| 71 |
return VectorStore
|
| 72 |
|
| 73 |
except Exception as e:
|