Writo commited on
Commit
2301c47
·
1 Parent(s): 7aacd97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -14,6 +14,10 @@ def main():
14
  st.set_page_config(page_title="Chat PDF")
15
  st.header("Chat PDF 💬")
16
 
 
 
 
 
17
  pdfs = st.file_uploader("Upload your PDF files", type="pdf", accept_multiple_files=True)
18
 
19
  text = ""
@@ -37,14 +41,21 @@ def main():
37
  docsearch = FAISS.from_texts(text_chunks, embeddings)
38
  llm = OpenAI()
39
 
40
- chain = load_qa_chain(llm, chain_type="stuff")
41
 
42
  query = st.text_input("Type your question:")
43
 
44
  if query:
45
  docs = docsearch.similarity_search(query)
46
  response = chain.run(input_documents=docs, question=query)
47
- st.write(response)
 
 
 
 
 
 
 
48
 
49
  except Exception as e:
50
  st.error(f"An error occurred: {e}")
 
14
  st.set_page_config(page_title="Chat PDF")
15
  st.header("Chat PDF 💬")
16
 
17
+ # Initialize session state for chat history
18
+ if 'chat_history' not in st.session_state:
19
+ st.session_state.chat_history = []
20
+
21
  pdfs = st.file_uploader("Upload your PDF files", type="pdf", accept_multiple_files=True)
22
 
23
  text = ""
 
41
  docsearch = FAISS.from_texts(text_chunks, embeddings)
42
  llm = OpenAI()
43
 
44
+ chain = load_qa_chain(llm, chain_type="your_chain_type_here") # Replace with the actual chain type
45
 
46
  query = st.text_input("Type your question:")
47
 
48
  if query:
49
  docs = docsearch.similarity_search(query)
50
  response = chain.run(input_documents=docs, question=query)
51
+
52
+ # Update chat history
53
+ st.session_state.chat_history.append({"question": query, "answer": response})
54
+
55
+ # Display chat history
56
+ for chat in st.session_state.chat_history:
57
+ st.text(f"Q: {chat['question']}\nA: {chat['answer']}")
58
+ st.write("---")
59
 
60
  except Exception as e:
61
  st.error(f"An error occurred: {e}")