Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,13 +27,16 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages='all')
|
|
27 |
pages_to_be_loaded = pages.copy()
|
28 |
else:
|
29 |
page_numbers = relevant_pages.split(",")
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
#To create a vector store, we use the Chroma class, which takes the documents (pages in our case) and the embeddings instance
|
39 |
vectordb = Chroma.from_documents(pages_to_be_loaded, embedding=embeddings)
|
|
|
27 |
pages_to_be_loaded = pages.copy()
|
28 |
else:
|
29 |
page_numbers = relevant_pages.split(",")
|
30 |
+
if len(page_numbers) != 0:
|
31 |
+
for page_number in page_numbers:
|
32 |
+
pageIndex = int(page_number)-1
|
33 |
+
if pageIndex >=0 and pageIndex <len(pages):
|
34 |
+
pages_to_be_loaded.append(pages[pageIndex])
|
35 |
+
#In the scenario where none of the page numbers supplied exist in the PDF, we will revert to using the entire PDF.
|
36 |
+
if len(pages_to_be_loaded) ==0:
|
37 |
+
pages_to_be_loaded = pages.copy()
|
38 |
+
else:
|
39 |
+
pages_to_be_loaded = pages.copy()
|
40 |
|
41 |
#To create a vector store, we use the Chroma class, which takes the documents (pages in our case) and the embeddings instance
|
42 |
vectordb = Chroma.from_documents(pages_to_be_loaded, embedding=embeddings)
|