File size: 905 Bytes
4e26fb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from langchain_community.document_loaders import PyPDFLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter

file_path = "data/MedicalBook.pdf"

def load_docs(file_path):
    loader=PyPDFLoader(file_path)
    documents=loader.load()
    #print(f"Document Loaded with page Numbers: {len(documents)}")
    return documents


def split_docs(documents):
    #split the doc into chunks
    text_splitter = RecursiveCharacterTextSplitter(
        chunk_size=600, 
        chunk_overlap=200,
        separators=["\n\n", "\n", " ", ""])
    text_chunks= text_splitter.split_documents(documents)
    return text_chunks


# if __name__ == "__main__":
#      raw_documents = load_docs(file_path)
#      text_chunks=split_docs(raw_documents)
#      print(f"Length of the raw documents: {len(raw_documents)}")
#      print(f"Length of the chunks: {len(text_chunks)}")