Hello I am currently building a chatbot but I encounter a small problem.
I have set the page config and set my own title and icon but whenever I refresh the page it shows the streamlit icon and title during the refresh.
Is there a way to fix this?
Here is my code:
import streamlit as st # type: ignore
from streamlit_feedback import streamlit_feedback # type: ignore
import uuid
st.set_page_config(
page_title="SICBERT | Siemens Chatbot",
page_icon="/media/data/AI/workbench/streamlit-frontend/siemens_logo.png",
layout="centered",
)
st.title("SICBERT Siemens-Chatbot")
# Select Version dropdown
version = st.selectbox(label="Select your system version", options=["1", "2", "3"], index=None, placeholder="Select your system version", key="version", label_visibility="collapsed")
if 'question_state' not in st.session_state:
st.session_state.question_state = False
if 'fbk' not in st.session_state:
st.session_state.fbk = str(uuid.uuid4())
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
def display_answer():
for entry in st.session_state.chat_history:
with st.chat_message("human"):
st.write(entry["question"])
with st.chat_message("ai", avatar='/media/data/AI/workbench/streamlit-frontend/huber.png'):
st.write(entry["answer"])
# Do not display the feedback field since
# we are still about to ask the user.
if 'feedback' not in entry:
continue
# If there is no feedback show N/A
if "feedback" in entry:
st.write(f"Feedback: {entry['feedback']}")
else:
st.write("Feedback: N/A")
def create_answer(question):
"""Add question/answer to history."""
# Do not save to history if question is None.
# We reach this because streamlit reruns to get the feedback.
if question is None:
return
message_id = len(st.session_state.chat_history)
st.session_state.chat_history.append({
"question": question,
"answer": f"{question}",
"message_id": message_id,
})
def fbcb(response):
# Create a new feedback by changing the key of feedback component.
print(response)
st.session_state.fbk = str(uuid.uuid4())
# Start message
if not st.session_state.question_state:
with st.chat_message("ai", avatar='/media/data/AI/workbench/streamlit-frontend/huber.png'):
st.write("Hello, how can I help you?")
# Starts here.
question = st.chat_input(placeholder="Chat with SICBERT!")
if question:
# We need this because of feedback. That question above
# is a stopper. If user hits the feedback button, streamlit
# reruns the code from top and we cannot enter back because
# of that chat_input.
st.session_state.question_state = True
# We are now free because st.session_state.question_state is True.
# But there are consequences. We will have to handle
# the double runs of create_answer() and display_answer()
# just to get the user feedback.
if st.session_state.question_state:
create_answer(question)
display_answer()
# Pressing a button in feedback reruns the code.
streamlit_feedback(
feedback_type="thumbs",
optional_text_label="Please, provide an explanation.",
align="flex-start",
key=st.session_state.fbk,
on_submit=fbcb
)