Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ with st.sidebar:
|
|
| 36 |
|
| 37 |
openai_api_key = st.text_input("Enter your OpenAI API key:")
|
| 38 |
|
| 39 |
-
def load_pdf(file_path):
|
| 40 |
pdf_reader = PdfReader(file_path)
|
| 41 |
text = ""
|
| 42 |
for page in pdf_reader.pages:
|
|
@@ -55,7 +55,7 @@ def load_pdf(file_path):
|
|
| 55 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 56 |
VectorStore = pickle.load(f)
|
| 57 |
else:
|
| 58 |
-
embeddings = OpenAIEmbeddings()
|
| 59 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
| 60 |
with open(f"{store_name}.pkl", "wb") as f:
|
| 61 |
pickle.dump(VectorStore, f)
|
|
@@ -82,6 +82,10 @@ def main():
|
|
| 82 |
if "processing_input" not in st.session_state:
|
| 83 |
st.session_state['processing_input'] = ""
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
display_chat_history(st.session_state['chat_history'])
|
| 86 |
|
| 87 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|
|
|
|
| 36 |
|
| 37 |
openai_api_key = st.text_input("Enter your OpenAI API key:")
|
| 38 |
|
| 39 |
+
def load_pdf(file_path, openai_api_key):
|
| 40 |
pdf_reader = PdfReader(file_path)
|
| 41 |
text = ""
|
| 42 |
for page in pdf_reader.pages:
|
|
|
|
| 55 |
with open(f"{store_name}.pkl", "rb") as f:
|
| 56 |
VectorStore = pickle.load(f)
|
| 57 |
else:
|
| 58 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key) # Pass the API key here
|
| 59 |
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
| 60 |
with open(f"{store_name}.pkl", "wb") as f:
|
| 61 |
pickle.dump(VectorStore, f)
|
|
|
|
| 82 |
if "processing_input" not in st.session_state:
|
| 83 |
st.session_state['processing_input'] = ""
|
| 84 |
|
| 85 |
+
# Pass the openai_api_key parameter here
|
| 86 |
+
VectorStore = load_pdf(pdf, openai_api_key)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
display_chat_history(st.session_state['chat_history'])
|
| 90 |
|
| 91 |
st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
|