Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,15 +130,17 @@ def get_vectorstore(text_chunks):
|
|
| 130 |
|
| 131 |
|
| 132 |
# Handling user questions
|
| 133 |
-
def handle_userinput(question, pdf_vectorstore, dfs):
|
| 134 |
-
if pdf_vectorstore and st.session_state.conversation:
|
| 135 |
response = st.session_state.conversation({"question": question})
|
| 136 |
-
st.session_state.chat_history
|
| 137 |
-
|
| 138 |
-
st.
|
| 139 |
-
elif dfs:
|
| 140 |
answer = generateResponse(question, dfs)
|
| 141 |
-
st.
|
|
|
|
|
|
|
| 142 |
else:
|
| 143 |
st.write("Please upload and process your documents/data first.")
|
| 144 |
|
|
@@ -161,10 +163,16 @@ def main():
|
|
| 161 |
st.session_state.chat_history = None
|
| 162 |
if "vectorstore" not in st.session_state: #Store vectorstore in session state
|
| 163 |
st.session_state.vectorstore = None
|
|
|
|
| 164 |
|
| 165 |
st.header("Chat with PDFs and Data :books: :bar_chart:")
|
| 166 |
|
| 167 |
-
user_question = st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
if user_question:
|
| 170 |
handle_userinput(user_question, st.session_state.vectorstore, st.session_state.dfs)
|
|
@@ -227,5 +235,9 @@ def main():
|
|
| 227 |
else:
|
| 228 |
st.session_state.dfs = None
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
if __name__ == "__main__":
|
| 231 |
main()
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
# Handling user questions
|
| 133 |
+
def handle_userinput(question, pdf_vectorstore, dfs):
|
| 134 |
+
if pdf_vectorstore and st.session_state.conversation:
|
| 135 |
response = st.session_state.conversation({"question": question})
|
| 136 |
+
st.session_state.chat_history.append({"role": "user", "content": question}) # Add to chat history
|
| 137 |
+
st.session_state.chat_history.append({"role": "assistant", "content": response['answer']}) # Add to chat history
|
| 138 |
+
st.rerun() # Rerun to update the chat display
|
| 139 |
+
elif dfs:
|
| 140 |
answer = generateResponse(question, dfs)
|
| 141 |
+
st.session_state.chat_history.append({"role": "user", "content": question}) # Add to chat history
|
| 142 |
+
st.session_state.chat_history.append({"role": "assistant", "content": answer}) # Add to chat history
|
| 143 |
+
st.rerun() # Rerun to update the chat display
|
| 144 |
else:
|
| 145 |
st.write("Please upload and process your documents/data first.")
|
| 146 |
|
|
|
|
| 163 |
st.session_state.chat_history = None
|
| 164 |
if "vectorstore" not in st.session_state: #Store vectorstore in session state
|
| 165 |
st.session_state.vectorstore = None
|
| 166 |
+
|
| 167 |
|
| 168 |
st.header("Chat with PDFs and Data :books: :bar_chart:")
|
| 169 |
|
| 170 |
+
user_question = st.chat_input("Ask a question about your documents or data:")
|
| 171 |
+
|
| 172 |
+
# Chat display
|
| 173 |
+
for message in st.session_state.chat_history:
|
| 174 |
+
with st.chat_message(message["role"]):
|
| 175 |
+
st.write(message["content"])
|
| 176 |
|
| 177 |
if user_question:
|
| 178 |
handle_userinput(user_question, st.session_state.vectorstore, st.session_state.dfs)
|
|
|
|
| 235 |
else:
|
| 236 |
st.session_state.dfs = None
|
| 237 |
|
| 238 |
+
if st.button("Clear Chat"):
|
| 239 |
+
st.session_state.chat_history = []
|
| 240 |
+
st.rerun()
|
| 241 |
+
|
| 242 |
if __name__ == "__main__":
|
| 243 |
main()
|