import streamlit as st import pandas as pd def search_application(df): user_input = st.text_input("Enter your Application Number (including IRL if applicable):") if user_input: # Validate input if "irl" in user_input.lower(): try: application_number = int("".join(filter(str.isdigit, user_input.lower().split("irl")[-1]))) if len(str(application_number)) < 8: st.warning("Please enter a valid application number with at least 8 digits after IRL.") return except ValueError: st.error("Invalid input after IRL. Please enter only digits.") return else: if not user_input.isdigit() or len(user_input) < 8: st.warning("Please enter at least 8 digits for your VISA application number.") return elif len(user_input) > 8: st.warning("The application number cannot exceed 8 digits. Please correct your input.") return application_number = int(user_input) # Check for the application number in the DataFrame result = df[df['Application Number'] == str(application_number)] if not result.empty: decision = result.iloc[0]['Decision'] if decision.lower() == 'refused': st.error(f"Application Number: {application_number}\n\nDecision: **Refused**") elif decision.lower() == 'approved': st.success(f"Application Number: {application_number}\n\nDecision: **Approved**") else: st.info(f"Application Number: {application_number}\n\nDecision: **{decision}**") else: st.warning(f"No record found for Application Number: {application_number}.") # Find nearest application numbers df['Application Number'] = df['Application Number'].astype(int) df['Difference'] = abs(df['Application Number'] - application_number) nearest_records = df.nsmallest(2, 'Difference') if not nearest_records.empty: st.subheader("Nearest Application Numbers") nearest_records['Nearest Application'] = ['Before', 'After'] st.table(nearest_records[['Nearest Application', 'Application Number', 'Decision', 'Difference']]) else: st.info("No nearest application numbers found.")