Update app.py
Browse files
app.py
CHANGED
@@ -12,9 +12,16 @@ with open("embeddings_1.pkl", "rb") as fIn:
|
|
12 |
stored_data = pickle.load(fIn)
|
13 |
stored_embeddings = stored_data["embeddings"]
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
# Define the function for mapping code
|
18 |
# Define the function for mapping code
|
19 |
def mapping_code(user_input,user_slider_input_number):
|
20 |
|
@@ -51,25 +58,28 @@ def main():
|
|
51 |
st.markdown("<font color='blue'>**💡 Note:** Please note that the similarity scores provided are not indicative of accuracy . Top 5 code description provided should be verified with CPT description by User.</font>", unsafe_allow_html=True)
|
52 |
|
53 |
|
54 |
-
user_slider_input_number = st.sidebar.slider('Select similarity threshold', 0.0, 1.0, 0.7, 0.01, key='slider1', help='Adjust the similarity threshold')
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
main()
|
|
|
12 |
stored_data = pickle.load(fIn)
|
13 |
stored_embeddings = stored_data["embeddings"]
|
14 |
|
15 |
+
def validate_input(input_string):
|
16 |
+
# Regular expression pattern to match letters and numbers, or letters only
|
17 |
+
pattern = r'^[a-zA-Z0-9]+$|^[a-zA-Z]+$'
|
18 |
+
|
19 |
+
# Check if input contains at least one non-numeric character
|
20 |
+
if re.match(pattern, input_string):
|
21 |
+
return True
|
22 |
+
else:
|
23 |
+
return False
|
24 |
|
|
|
|
|
25 |
# Define the function for mapping code
|
26 |
def mapping_code(user_input,user_slider_input_number):
|
27 |
|
|
|
58 |
st.markdown("<font color='blue'>**💡 Note:** Please note that the similarity scores provided are not indicative of accuracy . Top 5 code description provided should be verified with CPT description by User.</font>", unsafe_allow_html=True)
|
59 |
|
60 |
|
61 |
+
#user_slider_input_number = st.sidebar.slider('Select similarity threshold', 0.0, 1.0, 0.7, 0.01, key='slider1', help='Adjust the similarity threshold')
|
62 |
+
|
63 |
+
# Input text box for user input
|
64 |
+
user_input = st.text_input("Enter CPT description:", placeholder="Please enter a full description for better search results.")
|
65 |
+
|
66 |
+
# Button to trigger mapping
|
67 |
+
if st.button("Map"):
|
68 |
+
if not user_input.strip(): # Check if input is empty or contains only whitespace
|
69 |
+
st.error("Input box cannot be empty.")
|
70 |
+
elif not validate_input(user_input):
|
71 |
+
st.warning("Please input correct description containing only letters and numbers, or letters only.")
|
72 |
+
else:
|
73 |
+
st.write("Please wait for a moment .... ")
|
74 |
+
# Call backend function to get mapping results
|
75 |
+
try:
|
76 |
+
mapping_results = mapping_code(user_input#user_slider_input_number)
|
77 |
+
# Display top 5 similar sentences
|
78 |
+
st.write("Top 5 similar sentences:")
|
79 |
+
for i, result in enumerate(mapping_results, 1):
|
80 |
+
st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {float(result['Similarity Score']):.4f}")
|
81 |
+
except ValueError as e:
|
82 |
+
st.error(str(e))
|
83 |
|
84 |
if __name__ == "__main__":
|
85 |
main()
|