Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,17 +28,37 @@ from langchain.chains import ConversationalRetrievalChain
|
|
| 28 |
GROQ_API_KEY = os.getenv("groq")
|
| 29 |
# gemni_KEY = os.getenv("gemni")
|
| 30 |
# export GOOGLE_API_KEY=gemni_KEY
|
| 31 |
-
loaders = [
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
]
|
| 35 |
-
documents = []
|
| 36 |
-
for ldr in loaders:
|
| 37 |
-
docs = ldr.load()
|
| 38 |
-
documents.extend(docs)
|
| 39 |
-
|
| 40 |
-
print(f"Loaded {len(documents)} file(s)")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# --------------------------------------------------------------------------------------
|
| 43 |
# 2. Chunk documents & build FAISS index
|
| 44 |
# --------------------------------------------------------------------------------------
|
|
|
|
| 28 |
GROQ_API_KEY = os.getenv("groq")
|
| 29 |
# gemni_KEY = os.getenv("gemni")
|
| 30 |
# export GOOGLE_API_KEY=gemni_KEY
|
| 31 |
+
# loaders = [
|
| 32 |
+
# DirectoryLoader("bonusGeneralTerms_bs.pdf", loader_cls=PyPDFLoader),
|
| 33 |
+
# DirectoryLoader("FAQ.pdf", loader_cls=PyPDFLoader),
|
| 34 |
+
# ]
|
| 35 |
+
# documents = []
|
| 36 |
+
# for ldr in loaders:
|
| 37 |
+
# docs = ldr.load()
|
| 38 |
+
# documents.extend(docs)
|
| 39 |
+
|
| 40 |
+
# print(f"Loaded {len(documents)} file(s)")
|
| 41 |
+
file_paths = [
|
| 42 |
+
"bonusGeneralTerms_bs.pdf",
|
| 43 |
+
"FAQ.pdf"
|
| 44 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
documents = []
|
| 47 |
+
# 2. Loop through the list of file paths.
|
| 48 |
+
for path in file_paths:
|
| 49 |
+
try:
|
| 50 |
+
# 3. Use PyPDFLoader for each individual file path.
|
| 51 |
+
loader = PyPDFLoader(path)
|
| 52 |
+
# Load the documents for the current file and add them to the list.
|
| 53 |
+
# .load() returns a list of Document objects (one per page).
|
| 54 |
+
documents.extend(loader.load())
|
| 55 |
+
except Exception as e:
|
| 56 |
+
# Optional: Add error handling in case a file is missing or corrupt.
|
| 57 |
+
print(f"Error loading file {path}: {e}")
|
| 58 |
+
|
| 59 |
+
# The user's original print statement works perfectly here.
|
| 60 |
+
# Note: This will print the total number of *pages*, not files.
|
| 61 |
+
print(f"Loaded {len(documents)} document pages from {len(file_paths)} file(s)")
|
| 62 |
# --------------------------------------------------------------------------------------
|
| 63 |
# 2. Chunk documents & build FAISS index
|
| 64 |
# --------------------------------------------------------------------------------------
|