Shabdobhedi commited on
Commit
9a20526
1 Parent(s): 2883d0c

Upload 3 files

Browse files
Files changed (3) hide show
  1. src/__init__.py +0 -0
  2. src/helper.py +30 -0
  3. src/prompt.py +12 -0
src/__init__.py ADDED
File without changes
src/helper.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.document_loaders import PyPDFLoader, DirectoryLoader
2
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
3
+ from langchain.embeddings import HuggingFaceEmbeddings
4
+
5
+
6
+ # Extract data from the PDF
7
+ def load_pdf(data):
8
+ loader = DirectoryLoader(data,
9
+ glob="*.pdf",
10
+ loader_cls=PyPDFLoader)
11
+
12
+ documents = loader.load()
13
+
14
+ return documents
15
+
16
+
17
+ # Create text chunks
18
+ def text_split(extracted_data):
19
+ text_splitter = RecursiveCharacterTextSplitter(
20
+ chunk_size=500, chunk_overlap=20)
21
+ text_chunks = text_splitter.split_documents(extracted_data)
22
+
23
+ return text_chunks
24
+
25
+
26
+ # download embedding model
27
+ def download_hugging_face_embeddings():
28
+ embeddings = HuggingFaceEmbeddings(
29
+ model_name='sentence-transformers/all-MiniLM-L6-v2')
30
+ return embeddings
src/prompt.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ prompt_template = """
4
+ Use the following pieces of information to answer the user's question.
5
+ If you don't know the answer, just say that you don't know, don't try to make up an answer.
6
+
7
+ Context: {context}
8
+ Question: {question}
9
+
10
+ Only return the helpful answer below and nothing else.
11
+ Helpful answer:
12
+ """