Anne31415 commited on
Commit
ab80b1b
·
1 Parent(s): 36da990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -11
app.py CHANGED
@@ -126,7 +126,6 @@ def main():
126
  st.write("<!-- End Spacer -->", unsafe_allow_html=True)
127
 
128
  new_messages_placeholder = st.empty()
129
-
130
  loading_message = None # Initialize the loading_message variable
131
 
132
  if pdf_path is not None:
@@ -148,7 +147,7 @@ def main():
148
  if st.button("Ask") or (not st.session_state['chat_history'] and query) or (st.session_state['chat_history'] and query != st.session_state['chat_history'][-1][1]):
149
  st.session_state['chat_history'].append(("User", query, "new"))
150
 
151
- loading_message = st.empty()
152
  loading_message.text('Bot is thinking...')
153
 
154
  VectorStore = load_pdf(pdf_path)
@@ -175,8 +174,6 @@ def main():
175
  # Scroll to the latest response using JavaScript
176
  st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
177
 
178
- loading_message.empty()
179
-
180
  # Clear the input field by setting the query variable to an empty string
181
  query = ""
182
 
@@ -190,16 +187,11 @@ def main():
190
  background_color = "#FFA07A" if chat[2] == "new" else "#D1D1E0" if chat[0] == "User" else "#D1D1E0" # Use a very light purple-grey color
191
  new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
192
 
193
-
194
-
195
  # Scroll to the latest response using JavaScript
196
  st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
197
 
198
- loading_message.empty()
199
-
200
- # Clear the input field by setting the query variable to an empty string
201
- query = ""
202
-
203
 
204
 
205
  def display_chat_history(chat_history):
 
126
  st.write("<!-- End Spacer -->", unsafe_allow_html=True)
127
 
128
  new_messages_placeholder = st.empty()
 
129
  loading_message = None # Initialize the loading_message variable
130
 
131
  if pdf_path is not None:
 
147
  if st.button("Ask") or (not st.session_state['chat_history'] and query) or (st.session_state['chat_history'] and query != st.session_state['chat_history'][-1][1]):
148
  st.session_state['chat_history'].append(("User", query, "new"))
149
 
150
+ loading_message = st.empty() # Assign the loading_message variable here
151
  loading_message.text('Bot is thinking...')
152
 
153
  VectorStore = load_pdf(pdf_path)
 
174
  # Scroll to the latest response using JavaScript
175
  st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
176
 
 
 
177
  # Clear the input field by setting the query variable to an empty string
178
  query = ""
179
 
 
187
  background_color = "#FFA07A" if chat[2] == "new" else "#D1D1E0" if chat[0] == "User" else "#D1D1E0" # Use a very light purple-grey color
188
  new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
189
 
 
 
190
  # Scroll to the latest response using JavaScript
191
  st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
192
 
193
+ if loading_message is not None:
194
+ loading_message.empty() # Call empty() only if loading_message is not None
 
 
 
195
 
196
 
197
  def display_chat_history(chat_history):