Update app.py
Browse files
app.py
CHANGED
@@ -40,33 +40,35 @@ from helper import conversational_chat,pdf_loader,splitDoc,makeEmbeddings,create
|
|
40 |
|
41 |
def ui():
|
42 |
st.title('PDF Question Answer Bot')
|
43 |
-
|
44 |
llm = create_flan_t5_base(load_in_8bit=False)
|
45 |
hf_llm = HuggingFacePipeline(pipeline=llm)
|
46 |
|
47 |
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf"])
|
48 |
#saving the uploaded pdf file
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
#loading the pdf file
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
70 |
|
71 |
def show_chat_interface(qa_chain):
|
72 |
if 'history' not in st.session_state:
|
|
|
40 |
|
41 |
def ui():
|
42 |
st.title('PDF Question Answer Bot')
|
43 |
+
hugging_face_key = os.environ["HUGGINGFACE_HUB_TOKEN"]
|
44 |
llm = create_flan_t5_base(load_in_8bit=False)
|
45 |
hf_llm = HuggingFacePipeline(pipeline=llm)
|
46 |
|
47 |
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf"])
|
48 |
#saving the uploaded pdf file
|
49 |
+
if uploaded_file is not None:
|
50 |
+
save_path = "./uploaded_file.pdf"
|
51 |
+
with open(save_path, "wb") as f:
|
52 |
+
f.write(uploaded_file.read())
|
53 |
|
54 |
#loading the pdf file
|
55 |
+
pdf_doc=pdf_loader('./uploaded_file.pdf')
|
56 |
+
vector_database = makeEmbeddings(pdf_doc)
|
57 |
+
#making the retriever of the vector database
|
58 |
+
retriever = vector_database.as_retriever(search_kwargs={"k":4})
|
59 |
+
qa_chain = RetrievalQA.from_chain_type(llm=hf_llm, chain_type="stuff",retriever=retriever)
|
60 |
+
|
61 |
+
# Create an empty container to hold the PDF loader section
|
62 |
+
pdf_loader_container = st.empty()
|
63 |
+
|
64 |
+
# Check if the PDF file is uploaded or not
|
65 |
+
if uploaded_file is not None:
|
66 |
+
print("The file has been uploaded successfully")
|
67 |
+
# Hide the PDF loader interface when the file is uploaded
|
68 |
+
pdf_loader_container.empty()
|
69 |
+
# Show the chat interface
|
70 |
+
show_chat_interface(qa_chain)
|
71 |
+
|
72 |
|
73 |
def show_chat_interface(qa_chain):
|
74 |
if 'history' not in st.session_state:
|