Sharal commited on
Commit
f5daac6
·
verified ·
1 Parent(s): 2e1d4d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -160,14 +160,6 @@ def main():
160
  st.title("Chat with your Document")
161
 
162
  if st.session_state['qa_chain']:
163
- message = st.text_input("Ask a question")
164
-
165
- if st.button("Submit"):
166
- with st.spinner("Generating response..."):
167
- qa_chain, chat_history, response_answer, sources = conversation(st.session_state['qa_chain'], message, st.session_state['chat_history'])
168
- st.session_state['qa_chain'] = qa_chain
169
- st.session_state['chat_history'] = chat_history
170
-
171
  st.markdown("### Chatbot Response")
172
 
173
  # Display the chat history in a chat-like interface
@@ -175,9 +167,22 @@ def main():
175
  st.markdown(f"**User:** {user_msg}")
176
  st.markdown(f"**Assistant:** {bot_msg}")
177
 
 
 
178
  with st.expander("Relevant context from the source document"):
179
- for source in sources:
180
- st.text_area(f"Source - Page {source['page']}", value=source["content"], height=100)
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if __name__ == "__main__":
183
  main()
 
160
  st.title("Chat with your Document")
161
 
162
  if st.session_state['qa_chain']:
 
 
 
 
 
 
 
 
163
  st.markdown("### Chatbot Response")
164
 
165
  # Display the chat history in a chat-like interface
 
167
  st.markdown(f"**User:** {user_msg}")
168
  st.markdown(f"**Assistant:** {bot_msg}")
169
 
170
+ st.markdown("### Relevant context from the source document")
171
+
172
  with st.expander("Relevant context from the source document"):
173
+ if 'sources' in st.session_state:
174
+ for i, source in enumerate(st.session_state['sources']):
175
+ st.text_area(f"Source {i + 1} - Page {source['page']}", value=source["content"], height=100)
176
+
177
+ message = st.text_input("Ask a question", key="message")
178
+
179
+ if st.button("Submit"):
180
+ with st.spinner("Generating response..."):
181
+ qa_chain, chat_history, response_answer, sources = conversation(st.session_state['qa_chain'], st.session_state['message'], st.session_state['chat_history'])
182
+ st.session_state['qa_chain'] = qa_chain
183
+ st.session_state['chat_history'] = chat_history
184
+ st.session_state['sources'] = sources
185
+ st.session_state['message'] = ""
186
 
187
  if __name__ == "__main__":
188
  main()