Vageesh1 commited on
Commit
027f572
·
1 Parent(s): d258a15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
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
- # 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
- save_path = "./uploaded_file.pdf"
50
- with open(save_path, "wb") as f:
51
- f.write(uploaded_file.read())
 
52
 
53
  #loading the pdf file
54
- pdf_doc=pdf_loader('./uploaded_file.pdf')
55
- vector_database = makeEmbeddings(pdf_doc)
56
- #making the retriever of the vector database
57
- retriever = vector_database.as_retriever(search_kwargs={"k":4})
58
- qa_chain = RetrievalQA.from_chain_type(llm=hf_llm, chain_type="stuff",retriever=retriever)
59
-
60
- # Create an empty container to hold the PDF loader section
61
- pdf_loader_container = st.empty()
62
-
63
- # Check if the PDF file is uploaded or not
64
- if uploaded_file is not None:
65
- print("The file has been uploaded successfully")
66
- # Hide the PDF loader interface when the file is uploaded
67
- pdf_loader_container.empty()
68
- # Show the chat interface
69
- show_chat_interface(qa_chain)
 
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: