srf_chatbot_v2 / streamlit_app.py
nadaaaita's picture
added authentication
8d810fe
raw
history blame
1.5 kB
import streamlit as st
# Initialize chat history
if 'chat_history' not in st.session_state:
st.session_state.chat_history = []
# Function to simulate chatbot response
def chatbot_respond(query):
# Example response with clickable links to passages
response = (
f"Here are some related passages:\n"
f"- [Passage 1](#passage-1)\n"
f"- [Passage 2](#passage-2)\n"
f"- [Passage 3](#passage-3)\n"
)
# Append user query and chatbot response to history
st.session_state.chat_history.append(("User", query))
st.session_state.chat_history.append(("Assistant", response))
# Display chat history
st.markdown("### Chatbot")
for sender, message in st.session_state.chat_history:
if sender == "User":
st.markdown(f"**{sender}:** {message}")
else:
st.markdown(f"**{sender}:** {message}")
# Input box for user query
query = st.text_input("Type your question:")
# On submission of query
if st.button("Submit"):
if query:
chatbot_respond(query)
st.experimental_rerun() # Re-run the app to update the chat history
# Separate passage section to simulate the linked passage content
st.markdown("---")
st.markdown("### Passages")
st.markdown("""
<a name="passage-1"></a> **Passage 1**: This is the full text of Passage 1.
---
<a name="passage-2"></a> **Passage 2**: This is the full text of Passage 2.
---
<a name="passage-3"></a> **Passage 3**: This is the full text of Passage 3.
""", unsafe_allow_html=True)