Skip to content

Replace PyPDF2 with pypdfium2 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import streamlit as st
from dotenv import load_dotenv
from PyPDF2 import PdfReader
import pypdfium2 as pdfium
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
from langchain.vectorstores import FAISS
Expand All @@ -10,12 +10,15 @@
from htmlTemplates import css, bot_template, user_template
from langchain.llms import HuggingFaceHub


def get_pdf_text(pdf_docs):
text = ""
for pdf in pdf_docs:
pdf_reader = PdfReader(pdf)
for page in pdf_reader.pages:
text += page.extract_text()
pdf_reader = pdfium.PdfDocument(pdf)
for i in range(len(pdf_reader)):
page = pdf_reader.get_page(i)
textpage = page.get_textpage()
text += textpage.get_text_range() + "\n"
return text


Expand Down Expand Up @@ -88,7 +91,6 @@ def main():
with st.spinner("Processing"):
# get pdf text
raw_text = get_pdf_text(pdf_docs)

# get the text chunks
text_chunks = get_text_chunks(raw_text)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
langchain==0.0.184
PyPDF2==3.0.1
python-dotenv==1.0.0
streamlit==1.18.1
openai==0.27.6
faiss-cpu==1.7.4
altair==4
tiktoken==0.4.0
pypdfium2==4.18.0
# uncomment to use huggingface llms
# huggingface-hub==0.14.1

Expand Down