pracheeeeez commited on
Commit
cb47044
·
verified ·
1 Parent(s): 5f46cc2

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +50 -49
app1.py CHANGED
@@ -1,50 +1,51 @@
1
- from cgitb import text
2
- import streamlit as st
3
- from dotenv import load_dotenv
4
- from PyPDF2 import PdfReader
5
- from langchain_text_splitters import CharacterTextSplitter
6
- from langchain.embeddings import HuggingFaceInstructEmbeddings
7
- from langchain.vectorstores import FAISS
8
-
9
-
10
- def get_text_chunks(raw_text):
11
- text_splitter = CharacterTextSplitter(
12
- separator="\n",
13
- chunk_size=1000, chunk_overlap=200,
14
- length_function= len
15
- )
16
- chunks = text_splitter.split(text)
17
- return chunks
18
-
19
- def get_pdf_text(pdf_docs):
20
- text =""
21
- for pdf in pdf_docs:
22
- pdf_reader = PdfReader(pdf)
23
- for page in pdf_reader.pages:
24
- text += page.extract_text()
25
- return text
26
-
27
- def get_vectorestore(text_chunks):
28
- embeddings =
29
- return
30
-
31
-
32
- def main():
33
- load_dotenv()
34
- st.set_page_config(page_title="Chat with your PDFs", page_icon= ":books:")
35
- st.header("Chat with your PDFs :books:")
36
- st.text_input("Ask a question about your documents:")
37
- with st.sidebar:
38
- st.subheader("Your Documemts")
39
- pdf_docs = st.file_uploader("Upload your PDFs here", accept_multiple_files= True)
40
- if st.button("Enter"):
41
- with st.spinner("Processing"):
42
- # get pdf text
43
- raw_text = get_pdf_text(pdf_docs)
44
- # get text chunks
45
- text_chunks = get_text_chunks(raw_text)
46
- # create vector store
47
- vectorstore = get_vectorstore(text_chunks)
48
-
49
- if __name__ == "__main__":
 
50
  main()
 
1
+ from cgitb import text
2
+ import streamlit as st
3
+ from dotenv import load_dotenv
4
+ from PyPDF2 import PdfReader
5
+ from langchain_text_splitters import CharacterTextSplitter
6
+ from langchain.embeddings import HuggingFaceInstructEmbeddings
7
+ from langchain.vectorstores import FAISS
8
+
9
+
10
+ def get_text_chunks(raw_text):
11
+ text_splitter = CharacterTextSplitter(
12
+ separator="\n",
13
+ chunk_size=1000, chunk_overlap=200,
14
+ length_function= len
15
+ )
16
+ chunks = text_splitter.split(text)
17
+ return chunks
18
+
19
+ def get_pdf_text(pdf_docs):
20
+ text =""
21
+ for pdf in pdf_docs:
22
+ pdf_reader = PdfReader(pdf)
23
+ for page in pdf_reader.pages:
24
+ text += page.extract_text()
25
+ return text
26
+
27
+ def get_vectorestore(text_chunks):
28
+ embeddings = HuggingFaceInstructEmbeddings(model_name = "hkunlp/instructor-xl")
29
+ vectorestore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
30
+ return vectorestore
31
+
32
+
33
+ def main():
34
+ load_dotenv()
35
+ st.set_page_config(page_title="Chat with your PDFs", page_icon= ":books:")
36
+ st.header("Chat with your PDFs :books:")
37
+ st.text_input("Ask a question about your documents:")
38
+ with st.sidebar:
39
+ st.subheader("Your Documemts")
40
+ pdf_docs = st.file_uploader("Upload your PDFs here", accept_multiple_files= True)
41
+ if st.button("Enter"):
42
+ with st.spinner("Processing"):
43
+ # get pdf text
44
+ raw_text = get_pdf_text(pdf_docs)
45
+ # get text chunks
46
+ text_chunks = get_text_chunks(raw_text)
47
+ # create vector store
48
+ vectorstore = get_vectorstore(text_chunks)
49
+
50
+ if __name__ == "__main__":
51
  main()