Suprito commited on
Commit
4e26fb5
·
verified ·
1 Parent(s): b643f1b

Upload utils.py

Browse files
Files changed (1) hide show
  1. utils.py +28 -0
utils.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.document_loaders import PyPDFLoader
2
+ from langchain_text_splitters import RecursiveCharacterTextSplitter
3
+
4
+ file_path = "data/MedicalBook.pdf"
5
+
6
+ def load_docs(file_path):
7
+ loader=PyPDFLoader(file_path)
8
+ documents=loader.load()
9
+ #print(f"Document Loaded with page Numbers: {len(documents)}")
10
+ return documents
11
+
12
+
13
+ def split_docs(documents):
14
+ #split the doc into chunks
15
+ text_splitter = RecursiveCharacterTextSplitter(
16
+ chunk_size=600,
17
+ chunk_overlap=200,
18
+ separators=["\n\n", "\n", " ", ""])
19
+ text_chunks= text_splitter.split_documents(documents)
20
+ return text_chunks
21
+
22
+
23
+ # if __name__ == "__main__":
24
+ # raw_documents = load_docs(file_path)
25
+ # text_chunks=split_docs(raw_documents)
26
+ # print(f"Length of the raw documents: {len(raw_documents)}")
27
+ # print(f"Length of the chunks: {len(text_chunks)}")
28
+