1MR commited on
Commit
51488c8
·
verified ·
1 Parent(s): f27fb7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -101,15 +101,20 @@ def get_conversation_chain(vectorstore, tokenH):
101
 
102
 
103
  def handle_userinput(user_question):
 
104
  if "chat_history" not in st.session_state:
105
  st.session_state.chat_history = []
 
 
106
  response = st.session_state.conversation(user_question)
107
 
108
- st.session_state.chat_history = [{"role": "user", "content": user_question}]
 
109
  st.session_state.chat_history.append({"role": "assistant", "content": response})
110
 
111
- for i, message in enumerate(st.session_state.chat_history):
112
- if i % 2 == 0:
 
113
  st.write(f"<div style='color: gray;'>User: {message['content']}</div>", unsafe_allow_html=True)
114
  else:
115
  st.write(f"<div style='color: black;'>Bot: {message['content']}</div>", unsafe_allow_html=True)
 
101
 
102
 
103
  def handle_userinput(user_question):
104
+ # Ensure chat_history is initialized
105
  if "chat_history" not in st.session_state:
106
  st.session_state.chat_history = []
107
+
108
+ # Get the response from the conversation
109
  response = st.session_state.conversation(user_question)
110
 
111
+ # Append the user's question and the assistant's response to chat history
112
+ st.session_state.chat_history.append({"role": "user", "content": user_question})
113
  st.session_state.chat_history.append({"role": "assistant", "content": response})
114
 
115
+ # Display the chat history
116
+ for message in st.session_state.chat_history:
117
+ if message["role"] == "user":
118
  st.write(f"<div style='color: gray;'>User: {message['content']}</div>", unsafe_allow_html=True)
119
  else:
120
  st.write(f"<div style='color: black;'>Bot: {message['content']}</div>", unsafe_allow_html=True)