Sharal commited on
Commit
30b2990
·
verified ·
1 Parent(s): 6cf6d58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -103,7 +103,8 @@ def initialize_LLM(llm_option, vector_db):
103
  def format_chat_history(chat_history):
104
  formatted_chat_history = []
105
  for user_message, bot_message in chat_history:
106
- formatted_chat_history.append(f"User: {user_message}\nAssistant: {bot_message}\n")
 
107
  return formatted_chat_history
108
 
109
  def conversation(qa_chain, message, history):
@@ -126,11 +127,6 @@ def conversation(qa_chain, message, history):
126
  st.error(f"Error in conversation: {e}")
127
  return qa_chain, history, "", []
128
 
129
- def download_history(chat_history):
130
- formatted_chat_history = format_chat_history(chat_history)
131
- history_text = "\n".join(formatted_chat_history)
132
- st.download_button(label="Download Chat History", data=history_text, file_name="chat_history.txt", mime="text/plain")
133
-
134
  def main():
135
  st.sidebar.title("PDF Chatbot")
136
 
@@ -150,9 +146,6 @@ def main():
150
  if 'qa_chain' not in st.session_state:
151
  st.session_state['qa_chain'] = None
152
 
153
- if 'chat_history' not in st.session_state:
154
- st.session_state['chat_history'] = []
155
-
156
  st.sidebar.markdown("### Select Large Language Model (LLM)")
157
  llm_option = st.sidebar.radio("Available LLMs", list_llm_simple)
158
 
@@ -165,13 +158,13 @@ def main():
165
  st.title("Chat with your Document")
166
 
167
  if st.session_state['qa_chain']:
 
168
  message = st.text_input("Ask a question")
169
 
170
  if st.button("Submit"):
171
  with st.spinner("Generating response..."):
172
- qa_chain, chat_history, response_answer, sources = conversation(st.session_state['qa_chain'], message, st.session_state['chat_history'])
173
  st.session_state['qa_chain'] = qa_chain
174
- st.session_state['chat_history'] = chat_history
175
 
176
  st.markdown("### Chatbot Response")
177
  st.write(response_answer)
@@ -180,7 +173,5 @@ def main():
180
  for source in sources:
181
  st.text_area(f"Source - Page {source['page']}", value=source["content"], height=100)
182
 
183
- download_history(st.session_state['chat_history'])
184
-
185
  if __name__ == "__main__":
186
  main()
 
103
  def format_chat_history(chat_history):
104
  formatted_chat_history = []
105
  for user_message, bot_message in chat_history:
106
+ formatted_chat_history.append(f"User: {user_message}")
107
+ formatted_chat_history.append(f"Assistant: {bot_message}")
108
  return formatted_chat_history
109
 
110
  def conversation(qa_chain, message, history):
 
127
  st.error(f"Error in conversation: {e}")
128
  return qa_chain, history, "", []
129
 
 
 
 
 
 
130
  def main():
131
  st.sidebar.title("PDF Chatbot")
132
 
 
146
  if 'qa_chain' not in st.session_state:
147
  st.session_state['qa_chain'] = None
148
 
 
 
 
149
  st.sidebar.markdown("### Select Large Language Model (LLM)")
150
  llm_option = st.sidebar.radio("Available LLMs", list_llm_simple)
151
 
 
158
  st.title("Chat with your Document")
159
 
160
  if st.session_state['qa_chain']:
161
+ history = []
162
  message = st.text_input("Ask a question")
163
 
164
  if st.button("Submit"):
165
  with st.spinner("Generating response..."):
166
+ qa_chain, history, response_answer, sources = conversation(st.session_state['qa_chain'], message, history)
167
  st.session_state['qa_chain'] = qa_chain
 
168
 
169
  st.markdown("### Chatbot Response")
170
  st.write(response_answer)
 
173
  for source in sources:
174
  st.text_area(f"Source - Page {source['page']}", value=source["content"], height=100)
175
 
 
 
176
  if __name__ == "__main__":
177
  main()