File size: 1,501 Bytes
8d810fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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)