Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -150,4 +150,46 @@ def main():
|
|
150 |
st.sidebar.markdown("### Select Large Language Model (LLM)")
|
151 |
llm_option = st.sidebar.radio("Available LLMs", list_llm_simple)
|
152 |
|
153 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
st.sidebar.markdown("### Select Large Language Model (LLM)")
|
151 |
llm_option = st.sidebar.radio("Available LLMs", list_llm_simple)
|
152 |
|
153 |
+
if st.sidebar.button("Initialize Question Answering Chatbot"):
|
154 |
+
with st.spinner("Initializing QA chatbot..."):
|
155 |
+
qa_chain, llm_message = initialize_LLM(list_llm_simple.index(llm_option), st.session_state['vector_db'])
|
156 |
+
st.session_state['qa_chain'] = qa_chain
|
157 |
+
st.sidebar.success(llm_message)
|
158 |
+
|
159 |
+
st.title("Chat with your Document")
|
160 |
+
|
161 |
+
if st.session_state['qa_chain']:
|
162 |
+
st.markdown("### Chatbot Response")
|
163 |
+
|
164 |
+
# Display the chat history in a chat-like interface
|
165 |
+
for i, (user_msg, bot_msg) in enumerate(st.session_state['chat_history']):
|
166 |
+
st.markdown(f"**User:** {user_msg}")
|
167 |
+
st.markdown(f"**Assistant:** {bot_msg}")
|
168 |
+
|
169 |
+
st.markdown("### Relevant context from the source document")
|
170 |
+
|
171 |
+
with st.expander("Relevant context from the source document"):
|
172 |
+
if 'sources' in st.session_state:
|
173 |
+
for i, source in enumerate(st.session_state['sources']):
|
174 |
+
st.text_area(f"Source {i + 1} - Page {source['page']}", value=source["content"], height=100)
|
175 |
+
|
176 |
+
message = st.text_input("Ask a question", key="message")
|
177 |
+
if st.button("Submit"):
|
178 |
+
if message:
|
179 |
+
with st.spinner("Generating response..."):
|
180 |
+
qa_chain, chat_history, response_answer, sources = conversation(st.session_state['qa_chain'], message, st.session_state['chat_history'])
|
181 |
+
st.session_state['qa_chain'] = qa_chain
|
182 |
+
st.session_state['chat_history'] = chat_history
|
183 |
+
st.session_state['sources'] = sources
|
184 |
+
|
185 |
+
# Display the new response immediately
|
186 |
+
st.markdown(f"**User:** {message}")
|
187 |
+
st.markdown(f"**Assistant:** {response_answer}")
|
188 |
+
|
189 |
+
st.markdown("### Relevant context from the source document")
|
190 |
+
with st.expander("Relevant context from the source document"):
|
191 |
+
for i, source in enumerate(sources):
|
192 |
+
st.text_area(f"Source {i + 1} - Page {source['page']}", value=source["content"], height=100)
|
193 |
+
|
194 |
+
if __name__ == "__main__":
|
195 |
+
main()
|