Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,13 +15,13 @@ from langchain_core.prompts import ChatPromptTemplate
|
|
| 15 |
from langchain_huggingface import HuggingFaceEndpoint, HuggingFaceEndpointEmbeddings, ChatHuggingFace
|
| 16 |
# ... rest of your code ...
|
| 17 |
@st.cache_data
|
| 18 |
-
def get_pdf_text(
|
| 19 |
"""
|
| 20 |
Extracts text from PDFs and creates Document objects with metadata.
|
| 21 |
Returns a list of Document objects, not a string.
|
| 22 |
"""
|
| 23 |
documents = []
|
| 24 |
-
for pdf in
|
| 25 |
pdf_reader = PdfReader(pdf)
|
| 26 |
pdf_filename = pdf.name
|
| 27 |
|
|
@@ -78,9 +78,9 @@ def get_hf_llm():
|
|
| 78 |
return ChatHuggingFace(llm=llm)
|
| 79 |
|
| 80 |
# --- Vector Store Functions (UPDATED) ---
|
| 81 |
-
def get_vector_store(
|
| 82 |
"""Creates FAISS vector store from Document objects."""
|
| 83 |
-
if not
|
| 84 |
st.error("No text chunks found.")
|
| 85 |
return
|
| 86 |
|
|
@@ -90,7 +90,7 @@ def get_vector_store(text_chunks):
|
|
| 90 |
|
| 91 |
try:
|
| 92 |
# Use from_documents instead of from_texts to keep metadata
|
| 93 |
-
vector_store = FAISS.from_documents(documents=
|
| 94 |
vector_store.save_local("faiss_index")
|
| 95 |
st.success("Vector store created and saved locally.")
|
| 96 |
except Exception as e:
|
|
|
|
| 15 |
from langchain_huggingface import HuggingFaceEndpoint, HuggingFaceEndpointEmbeddings, ChatHuggingFace
|
| 16 |
# ... rest of your code ...
|
| 17 |
@st.cache_data
|
| 18 |
+
def get_pdf_text(_pdf_docs):
|
| 19 |
"""
|
| 20 |
Extracts text from PDFs and creates Document objects with metadata.
|
| 21 |
Returns a list of Document objects, not a string.
|
| 22 |
"""
|
| 23 |
documents = []
|
| 24 |
+
for pdf in _pdf_docs:
|
| 25 |
pdf_reader = PdfReader(pdf)
|
| 26 |
pdf_filename = pdf.name
|
| 27 |
|
|
|
|
| 78 |
return ChatHuggingFace(llm=llm)
|
| 79 |
|
| 80 |
# --- Vector Store Functions (UPDATED) ---
|
| 81 |
+
def get_vector_store(_text_chunks):
|
| 82 |
"""Creates FAISS vector store from Document objects."""
|
| 83 |
+
if not _text_chunks:
|
| 84 |
st.error("No text chunks found.")
|
| 85 |
return
|
| 86 |
|
|
|
|
| 90 |
|
| 91 |
try:
|
| 92 |
# Use from_documents instead of from_texts to keep metadata
|
| 93 |
+
vector_store = FAISS.from_documents(documents=_text_chunks, embedding=embeddings)
|
| 94 |
vector_store.save_local("faiss_index")
|
| 95 |
st.success("Vector store created and saved locally.")
|
| 96 |
except Exception as e:
|