if 'key' not in st.session_state: st.session_state.key = str(randint(1000, 100000000))
… upload_files = st.file_uploader("Choose files", accept_multiple_files=True, type=['pdf'], key=st.session_state.key, help="Rerun if cache error")
… if st.button('Clear Uploaded File(s)', help='click twice to clear ALL'): for key in st.session_state.keys(): del st.session_state[key]
When I press the Clear… button, have to press twice to clear the uploaded listed files to be removed. And when I try adding new files, initial upload fails but repeat holds. Would love to get this fix if someone could tell me how.
import streamlit as st
if st.button('Clear Uploaded File(s)') and 'key' in st.session_state.keys():
st.session_state.pop('key')
st.experimental_rerun()
You’re awesome! It works flawless. Could I ask you one additional related code matter–I added a progress bar but it’s not real time when parsing is performed.
if st.button ("Analyze") and len(upload_files) > 0:
latest_iteration = st.text('hang on...')
my_bar = st.progress(0)
for percent_complete in range(100):
time.sleep(0.05)
latest_iteration.text(f'{percent_complete + 1}%')
my_bar.progress(percent_complete + 1)
for file in upload_files:
with pf.open(file) as pdf:
page = pdf.pages[0]
text = page.chars[0]
text_data = page.extract_text()
comlex_fail = re.compile(r'Fail\s\d{2}/\d{2}/\d{4}')
usmle_fail = re.compile(r'\d{2}/\d{2}/\d{4}\s+\bFail\b')
if "COMLEX-USA" in text_data:
ctext_list = text_data.split('COMLEX-USA')
#print(text_list[0])
cfail_list = comlex_fail.findall(text_data)
if cfail_list:
df = df.append({'Applicant ID': ctext_list[0], 'Total COMLEX Fails': len(cfail_list)}, ignore_index=True)
elif "USMLE" in text_data:
utext_list = text_data.split('USMLE')
ufail_list = usmle_fail.findall(text_data)
if ufail_list:
df = df.append({'Applicant ID': utext_list[0], 'Total USMLE Fails': len(ufail_list)}, ignore_index=True)
else:
status.append(str(file))
As per session_state and Download button, how do I use the key to make sure the button does not clear/disappear after clicked or is there additional method in the download_button.
if 'key' not in st.session_state:
st.session_state.key = str(randint(1000, 100000000))
st.download_button(
label='Download CSV file',
data = csv,
mime='text/csv',
file_name ='failed_applicants.csv'
)
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.