Skip to content

Commit

Permalink
enh: conditionally show upload reset or example
Browse files Browse the repository at this point in the history
  • Loading branch information
munterfi committed Oct 7, 2024
1 parent f183ce8 commit 86c88b1
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions rssched/app/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,41 @@ def handle_file_upload() -> Optional[Tuple[BytesIO, BytesIO]]:
"""
)

st.subheader("Upload Data")

# Initialize session state to store file uploads
if "request_file" not in st.session_state:
st.session_state.request_file = None
if "response_file" not in st.session_state:
st.session_state.response_file = None

# Handle file uploads
uploaded_files = handle_file_upload()

if uploaded_files:
request_file, response_file = uploaded_files
set_file_in_session_state(request_file, response_file)
# Check if files have been uploaded
files_uploaded = (
st.session_state.request_file is not None
and st.session_state.response_file is not None
)

# Reset button to clear the uploaded files and session state
if st.button("Reset"):
st.session_state.request_file = None
st.session_state.response_file = None
st.session_state.request_data = None
st.session_state.response_data = None
st.rerun()

# Load example files when the "Load Example" button is clicked
if st.button("Load Example"):
example_request_file, example_response_file = load_example_files()
set_file_in_session_state(example_request_file, example_response_file)
# Display file uploaders and "Load Example" button only if no files have been uploaded
if not files_uploaded:
st.subheader("Upload Data")
uploaded_files = handle_file_upload()
if uploaded_files:
request_file, response_file = uploaded_files
set_file_in_session_state(request_file, response_file)
st.rerun()

if st.button("Load Example"):
example_request_file, example_response_file = load_example_files()
set_file_in_session_state(example_request_file, example_response_file)
st.rerun()


# Show the reset button only if files have been uploaded
if files_uploaded:
st.subheader("Uploaded Data")
st.write(f"**Request File:** {st.session_state.request_file.name}")
st.write(f"**Response File:** {st.session_state.response_file.name}")
if st.button("Reset"):
st.session_state.request_file = None
st.session_state.response_file = None
st.session_state.request_data = None
st.session_state.response_data = None
st.rerun()

0 comments on commit 86c88b1

Please sign in to comment.