lekkalar commited on
Commit
5900010
·
1 Parent(s): 172abd0

Update app.py

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