diff --git a/app.py b/app.py index e17fa61..b09c504 100644 --- a/app.py +++ b/app.py @@ -117,6 +117,11 @@ def main(): background-color: #262730 !important; border: 1px solid #4a4a4a !important; } + + /* Hide the form submit button */ + .stButton { + display: none; + } """, unsafe_allow_html=True) @@ -127,6 +132,10 @@ def main(): st.session_state.tracker = TrackingLookup() if 'file_processed' not in st.session_state: st.session_state.file_processed = False + if 'last_result' not in st.session_state: + st.session_state.last_result = None + if 'form_count' not in st.session_state: + st.session_state.form_count = 0 # File upload section if not st.session_state.file_processed: @@ -143,8 +152,9 @@ def main(): # Centered input with columns col1, col2, col3 = st.columns([1, 2, 1]) with col2: - # Create a form to handle the Enter key properly - with st.form(key='tracking_form'): + # Create a unique key for each form instance + form_key = f'tracking_form_{st.session_state.form_count}' + with st.form(key=form_key): tracking_input = st.text_input( "Tracking Number", label_visibility="collapsed", @@ -152,22 +162,39 @@ def main(): ) submit_button = st.form_submit_button(label='Search', type='primary') - # Process the form submission - if submit_button or tracking_input: # This will catch both button clicks and Enter key + if submit_button and tracking_input: mailbag_no, sequence_no = st.session_state.tracker.lookup_tracking(tracking_input) if mailbag_no: + st.session_state.last_result = { + "mailbag_no": mailbag_no, + "sequence_no": sequence_no, + "found": True + } + else: + st.session_state.last_result = { + "found": False, + "tracking": tracking_input + } + + # Increment form count to create a new form instance + st.session_state.form_count += 1 + st.rerun() + + # Display results if they exist + if st.session_state.last_result: + if st.session_state.last_result["found"]: st.markdown( f"""

Mail Bag No:

-

{mailbag_no}

+

{st.session_state.last_result["mailbag_no"]}

Sequence #:

-

{sequence_no}

+

{st.session_state.last_result["sequence_no"]}

""", unsafe_allow_html=True ) else: - st.warning("❌ Tracking number not found in the uploaded data") + st.warning(f"❌ Tracking number not found in the uploaded data") if __name__ == "__main__": main()