st.title("Chatbot Prototype")
# Initialize session state for query and answer
if 'query' not in st.session_state:
st.session_state.query = ""
if 'answer' not in st.session_state:
st.session_state.answer = None
query = st.text_input(label="Was möchtest Du wissen?")
if query and query != st.session_state.query:
st.session_state.query = query
with st.spinner('Antwort wird abgerufen...'):
answer = bot.answer(query)
st.session_state.answer = answer
if st.session_state.answer:
st.write(st.session_state.answer)
st.write("========")
# Displays URLs in an expander
with st.expander("URLs"):
for page in bot.websites:
st.write(page.metadata['source'])
# Displays documents in an expander
with st.expander("Dokumente"):
for document in bot.documents:
st.write(document['metadatas'][0]['pdf_name'])
# Saves bad answer to json
if st.button('👎 Antwort war nicht hilfreich'):
dict_to_json("bad_responses.json", {"date": get_time(), "query": query})
I have the following problem: When I click on the last st.button, the expanders disappear from the streamlit app which I want to avoid. How can I do that? This is probably a newb question but after unsuccessfully trying to find a solution for quite some time, I would highly appreciate any help. Thank you!
ou can add the option “expanded” in the expander with a st.session_state.
st.title("Chatbot Prototype")
# Initialize session state for query and answer
if 'query' not in st.session_state:
st.session_state.query = ""
if 'answer' not in st.session_state:
st.session_state.answer = None
if 'urls_expander' not in st.session_state:
st.session_state.urls_expander = False
if 'documents_expander' not in st.session_state:
st.session_state.documents_expander = False
query = st.text_input(label="Was möchtest Du wissen?")
if query and query != st.session_state.query:
st.session_state.query = query
with st.spinner('Antwort wird abgerufen...'):
answer = bot.answer(query)
st.session_state.answer = answer
if st.session_state.answer:
st.write(st.session_state.answer)
st.markdown("""---""") #It's prettier :D
# Displays URLs in an expander
with st.expander("URLs", expanded=st.session_state.urls_expander):
for page in bot.websites:
st.write(page.metadata['source'])
st.session_state.urls_expander = True
# Displays documents in an expander
with st.expander("Dokumente", expanded=st.session_state.documents_expander):
for document in bot.documents:
st.write(document['metadatas'][0]['pdf_name'])
st.session_state.documents_expander = True
# Saves bad answer to json
if st.button('👎 Antwort war nicht hilfreich'):
dict_to_json("bad_responses.json", {"date": get_time(), "query": query})
st.success("Danke für Dein Feedback!")
Thank you very much for your help! Unfortunately, your suggestion did not solve my problem. But it made me try again and finally I found a solution :
st.title("GRACE Chatbot Prototype")
# Initialize session state for query and answer
if 'query' not in st.session_state:
st.session_state.query = ""
if 'answer' not in st.session_state:
st.session_state.answer = None
if 'urls' not in st.session_state:
st.session_state.urls = []
if 'documents' not in st.session_state:
st.session_state.documents = []
query = st.text_input(label="Was möchtest Du wissen?")
if query and query != st.session_state.query:
st.session_state.urls = []
st.session_state.documents = []
st.session_state.query = query
with st.spinner('Antwort wird abgerufen...'):
answer = bot.answer(query)
st.session_state.answer = answer
for page in bot.websites:
st.session_state.urls.append(page.metadata['source'])
for document in bot.documents:
st.session_state.documents.append(document['metadatas'][0]['pdf_name'])
if st.session_state.answer:
st.write(st.session_state.answer)
st.markdown("""---""")
# Displays URLs in an expander
with st.expander("URLs"):
for page in st.session_state.urls:
st.write(page)
# Displays documents in an expander
with st.expander("Dokumente"):
for document in st.session_state.documents:
st.write(document)
# Saves bad answer to json
if st.button('👎 Antwort war nicht hilfreich'):
dict_to_json("bad_responses.json", {"date": get_time(),
"query": st.session_state.query,
"answer": st.session_state.answer})
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.