Sharal commited on
Commit
f4bc94d
·
verified ·
1 Parent(s): d2af1df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -176,22 +176,20 @@ def main():
176
  st.text_area(f"Source {i + 1} - Page {source['page']}", value=source["content"], height=100)
177
 
178
  with st.form(key="question_form"):
179
- message = st.text_input("Ask a question", key="message_input")
180
  submit_button = st.form_submit_button(label="Submit")
181
 
182
  if submit_button:
183
  with st.spinner("Generating response..."):
184
- # Process the form input
185
- qa_chain, chat_history, response_answer, sources = conversation(
186
- st.session_state['qa_chain'], message, st.session_state['chat_history']
187
- )
188
  st.session_state['qa_chain'] = qa_chain
189
  st.session_state['chat_history'] = chat_history
190
  st.session_state['sources'] = sources
191
 
192
- # Clear the form input field by simply not including the key update
193
- # The form input should be handled directly in the form submit button
194
- st.rerun()
195
 
196
  if __name__ == "__main__":
197
  main()
 
176
  st.text_area(f"Source {i + 1} - Page {source['page']}", value=source["content"], height=100)
177
 
178
  with st.form(key="question_form"):
179
+ message = st.text_input("Ask a question", key="message")
180
  submit_button = st.form_submit_button(label="Submit")
181
 
182
  if submit_button:
183
  with st.spinner("Generating response..."):
184
+ # Call the conversation function inside the form
185
+ qa_chain, chat_history, response_answer, sources = conversation(st.session_state['qa_chain'], message, st.session_state['chat_history'])
 
 
186
  st.session_state['qa_chain'] = qa_chain
187
  st.session_state['chat_history'] = chat_history
188
  st.session_state['sources'] = sources
189
 
190
+ # Clear the text input after submission
191
+ st.session_state.message = ""
192
+ st.experimental_rerun() # Force a rerun to update the UI
193
 
194
  if __name__ == "__main__":
195
  main()