I am working on Cv seggregation app, using streamlit app.
It gets the files from user, process it and stores it to the specific directory, which is working fine on locally, but when I deployed it on streamlit, it stores the these processed files to the session storage of streamlit cloud, which is not directly accessible.
I added the download button, which will allow the user to download the processed files when the process is completed.
How can I add a stop button, that should allow the user to halt the process and provide the download button, so that the user should be able to download the files that is processed and stored in the streamlit storage?
Here is my code without the stopping functionality.
def main():
st.title("Resume Analysis")
uploaded_files = st.file_uploader("Upload CV files (PDF only)", type="pdf", accept_multiple_files=True)
user_required_Skills = st.text_input("Enter the required skills (comma-separated):")
user_required_experience_years = st.number_input("Enter the required experience (years):", min_value=0, value=0)
user_required_experience_months = st.number_input("Enter the required experience (months):", min_value=0, value=0)
output_dir = "filtered_cvs"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Create placeholders for buttons
start_analysis_placeholder = st.empty()
download_button_placeholder = st.empty()
if start_analysis_placeholder.button("Start Analysis"):
if uploaded_files:
filtered_files = []
for uploaded_file in uploaded_files:
file_name = uploaded_file.name
file_path = os.path.join(file_name)
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
filtered_file_path = process_file(file_path, user_required_Skills, user_required_experience_years, user_required_experience_months, output_dir)
if filtered_file_path:
filtered_files.append(filtered_file_path)
os.remove(file_path) # Clean up after processing
if filtered_files:
zip_file_path = os.path.join(output_dir, "filtered_cvs.zip")
with zipfile.ZipFile(zip_file_path, 'w') as zipf:
for file in filtered_files:
zipf.write(file, os.path.basename(file))
with open(zip_file_path, "rb") as f:
download_button_placeholder.download_button(
label="Download All Filtered CVs",
data=f,
file_name="filtered_cvs.zip",
mime="application/zip"
)
else:
st.error("No CVs met the required criteria.")
else:
st.error("Please upload at least one PDF file.")
if __name__ == "__main__":
main()