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

Upload app1.py

Browse files
Files changed (1) hide show
  1. app1.py +50 -0
app1.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()