Summary
I have created a feedback button in the chatbot-like interface built using the chat elements.
But the checkboxes are not holding the values so that I can store them in the database.
Steps to reproduce
import streamlit as st
from streamlit_extras.add_vertical_space import add_vertical_space
import random
from PIL import Image
from streamlit_chat import message
random_resp_optns = [‘Hello’, ‘How are you’, ‘What are you doing’, ‘I hope you are doing well’, ‘Hi’, ‘Hye’]
#print(random_resp_optns[random.choice(range(0,6))])
def streamlit_asthetics():
with st.sidebar:
"""
```
Steps:
1. Ask your question in the
chat box & press Enter.
2. Please wait a minute for
the models to run and
generate insights.
3. Please review the answer
and provide the feedback
by clicking Thumbs-up or
Thumbs-down.
4. Place your next query once
the previous query has run
completely.
5. The results are AI generated
and should be consumed with
human oversight.
```
"""
intro = """
```
Welcome
```
"""
if "chat" not in st.session_state:
st.session_state["chat"] = [{"role": "assistant",
"content": intro}]
for qst in st.session_state.chat:
st.chat_message(qst['role']).write(qst["content"])
if prompt := st.chat_input(key="input",
placeholder="AI assistant here! Ask me anything from the provided documents ...",):
st.session_state.chat.append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
resp = random_resp_optns[random.choice(range(0,6))]
st.session_state.chat.append({"role": "assistant", "content":resp})
st.chat_message("assistant").write(resp)
if 'a' not in st.session_state:
st.session_state.a = 0
st.session_state.b = 0
def ChangeA():
st.session_state.a, st.session_state.b = 1,0
def ChangeB():
st.session_state.a, st.session_state.b = 0,1
col1, col2, _ = st.columns([1,1,10])
with col1:
like = st.checkbox('👍', value = st.session_state.a, on_change = ChangeA)
with col2:
dislike = st.checkbox('👎', value = st.session_state.b, on_change = ChangeB)
if like or dislike:
st.write('You selected',st.session_state.a*'👍',st.session_state.b*'👎')
else:
st.write('No selection')
#st.session_state.a = 0
#st.session_state.b = 0
if name == “main”:
# app run------
st. set_page_config(layout=“wide”)
st.session_state.a = 0
st.session_state.b = 0
streamlit_asthetics()
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
When I click on the like or dislike button, it should hold that value.
Actual behavior:
feedback buttons are not holding the value