-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (47 loc) · 1.61 KB
/
app.py
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
51
52
53
54
55
import streamlit as st
from prompt import prompt
from persist import persist_data
def stick_header():
# make header sticky.
st.markdown(
"""
<div class='fixed-header'/>
<style>
div[data-testid="stVerticalBlock"] div:has(div.fixed-header) {
position: sticky;
top: 2.875rem;
background-color: #2D3748;
z-index: 999;
}
.fixed-header {
border-bottom: 2px solid white;
}
</style>
""",
unsafe_allow_html=True
)
container = st.container()
with container:
st.markdown("# WikiSpeaks")
stick_header()
# Initialize chat history
if "wikimsg" not in st.session_state:
st.session_state.wikimsg = []
# Display chat messages from history on app rerun
for message in st.session_state.wikimsg:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if question := st.chat_input("Post your query!"):
# Display user message in chat message container
st.chat_message("human").markdown(question)
# Add user message to chat history
st.session_state.wikimsg.append({"role": "human", "content": question})
with st.spinner("Please wait..."):
persist_data(question)
answer = prompt(question)
# Display assistant response in chat message container
with st.chat_message("ai"):
response = st.write_stream(answer)
# Add assistant response to chat history
st.session_state.wikimsg.append({"role": "ai", "content": response})