SR05 commited on
Commit
4c02c97
·
verified ·
1 Parent(s): aa0cd67

Create search.py

Browse files
Files changed (1) hide show
  1. search.py +51 -0
search.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ def search_application(df):
5
+ user_input = st.text_input("Enter your Application Number (including IRL if applicable):")
6
+
7
+ if user_input:
8
+ # Validate input
9
+ if "irl" in user_input.lower():
10
+ try:
11
+ application_number = int("".join(filter(str.isdigit, user_input.lower().split("irl")[-1])))
12
+ if len(str(application_number)) < 8:
13
+ st.warning("Please enter a valid application number with at least 8 digits after IRL.")
14
+ return
15
+ except ValueError:
16
+ st.error("Invalid input after IRL. Please enter only digits.")
17
+ return
18
+ else:
19
+ if not user_input.isdigit() or len(user_input) < 8:
20
+ st.warning("Please enter at least 8 digits for your VISA application number.")
21
+ return
22
+ elif len(user_input) > 8:
23
+ st.warning("The application number cannot exceed 8 digits. Please correct your input.")
24
+ return
25
+ application_number = int(user_input)
26
+
27
+ # Check for the application number in the DataFrame
28
+ result = df[df['Application Number'] == str(application_number)]
29
+
30
+ if not result.empty:
31
+ decision = result.iloc[0]['Decision']
32
+ if decision.lower() == 'refused':
33
+ st.error(f"Application Number: {application_number}\n\nDecision: **Refused**")
34
+ elif decision.lower() == 'approved':
35
+ st.success(f"Application Number: {application_number}\n\nDecision: **Approved**")
36
+ else:
37
+ st.info(f"Application Number: {application_number}\n\nDecision: **{decision}**")
38
+ else:
39
+ st.warning(f"No record found for Application Number: {application_number}.")
40
+
41
+ # Find nearest application numbers
42
+ df['Application Number'] = df['Application Number'].astype(int)
43
+ df['Difference'] = abs(df['Application Number'] - application_number)
44
+ nearest_records = df.nsmallest(2, 'Difference')
45
+
46
+ if not nearest_records.empty:
47
+ st.subheader("Nearest Application Numbers")
48
+ nearest_records['Nearest Application'] = ['Before', 'After']
49
+ st.table(nearest_records[['Nearest Application', 'Application Number', 'Decision', 'Difference']])
50
+ else:
51
+ st.info("No nearest application numbers found.")