Spaces:
Sleeping
Sleeping
Delete app1.py
Browse files
app1.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|