I’m encountering an issue in my Streamlit app where the feedback buttons (thumbs up and thumbs down) conflict with the download button. Here’s a brief overview of the problem:
Description:
I have implemented feedback buttons (thumbs up and thumbs down) for each chat answer in my Streamlit app, along with a download button for downloading extracted text from the answer. However, when I give feedback (click on a thumbs up or thumbs down button), the download button disappears, and vice versa.
heres a sample snippet
col1, col2, col3, col4 = st.columns([3, 3, 0.5, 0.5])
with col3:
if st.button(":thumbsup:", on_click = like_button_clicked):
pass
with col4:
if st.button(":thumbsdown:", on_click = unlike_button_clicked):
pass
if '<NONE>' not in res.split("[/INST]")[-1].strip().split(':')[-1].strip():
with open('exec.txt') as f:
st.download_button('Download script', f, 'exec.txt')
It tries to ensure that the elements are always present in the design, but are conditionally enabled or disabled depending on the state of the application. Perhaps by using the session state
import streamlit as st
# Define feedback button click handlers
def like_button_clicked():
st.write("Like button clicked")
def unlike_button_clicked():
st.write("Unlike button clicked")
# Define a sample value for res (replace this with your actual value)
res = "Sample text"
# Display feedback buttons
if st.button(":thumbsup:", on_click=like_button_clicked):
pass
if st.button(":thumbsdown:", on_click=unlike_button_clicked):
pass
# Conditionally display download button based on certain conditions
try:
with open('exec.txt') as f:
# Provide a placeholder file object for download_button, since you're using a file object
placeholder = st.empty()
# Display the download button
placeholder.download_button('Download script', f, 'exec.txt')
except FileNotFoundError:
st.error("The file 'exec.txt' does not exist. Please make sure the file exists in the correct location.")
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.