Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ from langchain.llms import OpenAI
|
|
| 13 |
from langchain.chains.question_answering import load_qa_chain
|
| 14 |
from langchain.callbacks import get_openai_callback
|
| 15 |
import os
|
|
|
|
| 16 |
|
| 17 |
import pandas as pd
|
| 18 |
import pydeck as pdk
|
|
@@ -43,10 +44,9 @@ api_key = os.getenv("OPENAI_API_KEY")
|
|
| 43 |
|
| 44 |
|
| 45 |
# Updated caching mechanism using st.cache_data
|
| 46 |
-
@st.cache_data(persist="disk")
|
| 47 |
def load_vector_store(file_path, store_name, force_reload=False):
|
| 48 |
-
|
| 49 |
-
# Check if we need to force reload the vector store (e.g., when the PDF changes)
|
| 50 |
if force_reload or not os.path.exists(f"{store_name}.pkl"):
|
| 51 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 52 |
chunk_size=1000,
|
|
@@ -64,9 +64,15 @@ def load_vector_store(file_path, store_name, force_reload=False):
|
|
| 64 |
else:
|
| 65 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 66 |
VectorStore = pickle.load(f)
|
| 67 |
-
|
| 68 |
return VectorStore
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Utility function to load text from a PDF
|
| 71 |
def load_pdf_text(file_path):
|
| 72 |
pdf_reader = PdfReader(file_path)
|
|
|
|
| 13 |
from langchain.chains.question_answering import load_qa_chain
|
| 14 |
from langchain.callbacks import get_openai_callback
|
| 15 |
import os
|
| 16 |
+
import traceback
|
| 17 |
|
| 18 |
import pandas as pd
|
| 19 |
import pydeck as pdk
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
# Updated caching mechanism using st.cache_data
|
| 47 |
+
@st.cache_data(persist="disk")
|
| 48 |
def load_vector_store(file_path, store_name, force_reload=False):
|
| 49 |
+
try:
|
|
|
|
| 50 |
if force_reload or not os.path.exists(f"{store_name}.pkl"):
|
| 51 |
text_splitter = RecursiveCharacterTextSplitter(
|
| 52 |
chunk_size=1000,
|
|
|
|
| 64 |
else:
|
| 65 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 66 |
VectorStore = pickle.load(f)
|
| 67 |
+
|
| 68 |
return VectorStore
|
| 69 |
|
| 70 |
+
except Exception as e:
|
| 71 |
+
st.error(f"An error occurred: {e}")
|
| 72 |
+
traceback.print_exc() # This will print the full traceback to the console
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
|
| 76 |
# Utility function to load text from a PDF
|
| 77 |
def load_pdf_text(file_path):
|
| 78 |
pdf_reader = PdfReader(file_path)
|