rtabrizi commited on
Commit
fa7567e
β€’
1 Parent(s): c7191ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -161,30 +161,25 @@ question_model_name = "facebook/dpr-question_encoder-single-nq-base"
161
 
162
  rag = RAG(file_path, device)
163
 
164
- st.title("RAG Model Query Interface")
165
 
166
  # Initialize session state to keep track of the list of answers and questions
167
- if 'questions' not in st.session_state:
168
- st.session_state.questions = []
169
- if 'answers' not in st.session_state:
170
- st.session_state.answers = []
171
 
172
- question = st.text_input("Ask a question", "")
173
 
174
  if st.button("Ask"):
175
  # Fetch the answer for the question
176
  answer = rag.extractive_query(question)
177
 
178
- # Store the question and its answer in session state
179
- st.session_state.questions.append(question)
180
- st.session_state.answers.append(answer)
181
-
182
- # Display the questions and their answers
183
- for q, a in zip(st.session_state.questions, st.session_state.answers):
184
- st.write(f"Q: {q}\nA: {a}")
185
-
186
- # Button to ask another question which simply refreshes the page to get a new question input
187
- if st.button("Ask another question"):
188
- st.session_state.questions = []
189
- st.session_state.answers = []
190
- st.experimental_rerun()
 
161
 
162
  rag = RAG(file_path, device)
163
 
164
+ st.title("RAG Model Query Interface Chatbot")
165
 
166
  # Initialize session state to keep track of the list of answers and questions
167
+ if 'history' not in st.session_state:
168
+ st.session_state.history = []
 
 
169
 
170
+ question = st.text_input("Enter your question:")
171
 
172
  if st.button("Ask"):
173
  # Fetch the answer for the question
174
  answer = rag.extractive_query(question)
175
 
176
+ # Add the question and its answer to the history
177
+ st.session_state.history.append({"type": "question", "content": question})
178
+ st.session_state.history.append({"type": "answer", "content": answer})
179
+
180
+ # Display the chat history
181
+ for item in st.session_state.history:
182
+ if item["type"] == "question":
183
+ st.write(f"πŸ§‘ You: {item['content']}")
184
+ else:
185
+ st.write(f"πŸ€– Bot: {item['content']}")