ceejaytheanalyst commited on
Commit
46210e1
·
verified ·
1 Parent(s): d5e7365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -13,6 +13,10 @@ with open("embeddings_1.pkl", "rb") as fIn:
13
  stored_data = pickle.load(fIn)
14
  stored_embeddings = stored_data["embeddings"]
15
 
 
 
 
 
16
  def validate_input(input_string):
17
  # Regular expression pattern to match letters and numbers, or letters only
18
  pattern = r'^[a-zA-Z0-9]+$|^[a-zA-Z]+$'
@@ -24,7 +28,17 @@ def validate_input(input_string):
24
  return False
25
 
26
  # Define the function for mapping code
27
- def mapping_code(user_input):
 
 
 
 
 
 
 
 
 
 
28
 
29
  emb1 = model.encode(user_input.lower())
30
  similarities = []
@@ -33,7 +47,7 @@ def mapping_code(user_input):
33
  similarities.append(similarity)
34
 
35
  # Filter results with similarity scores above 0.70
36
- result = [(code, desc, sim) for (code, desc, sim) in zip(stored_data["SBS_code"], stored_data["Description"], similarities)]
37
 
38
  # Sort results by similarity scores
39
  result.sort(key=lambda x: x[2], reverse=True)
@@ -55,29 +69,34 @@ def mapping_code(user_input):
55
  import streamlit as st
56
 
57
  def main():
58
- st.title("CPT Description Mapping")
59
- st.markdown("<font color='blue'>**💡 Please enter the input CPT description with specific available details in correct spelling for best results.**</font>", unsafe_allow_html=True)
60
 
61
- st.markdown("<font color='blue'>**💡 Note:** Please note that the similarity scores of each code are the calculated based on language module matching and the top 5 codes descriptions results should be verified with CPT description by the user.</font>", unsafe_allow_html=True)
 
62
 
63
- # 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')
 
 
 
 
 
64
 
65
  # Input text box for user input
66
- user_input = st.text_input("Enter CPT description:", placeholder="Please enter the input CPT description with specific available details for best results.")
67
 
68
  # Button to trigger mapping
69
  if st.button("Map"):
70
  if not user_input.strip(): # Check if input is empty or contains only whitespace
71
  st.error("Input box cannot be empty.")
72
  elif validate_input(user_input):
73
- st.warning("Please input correct description .")
74
  else:
75
- st.write("Please wait for a moment .... ")
76
  # Call backend function to get mapping results
77
  try:
78
- mapping_results = mapping_code(user_input) # user_slider_input_number
79
  # Display top 5 similar sentences
80
- st.write("Top 5 similar sentences:")
81
  for i, result in enumerate(mapping_results, 1):
82
  st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {float(result['Similarity Score']):.4f}")
83
  except ValueError as e:
 
13
  stored_data = pickle.load(fIn)
14
  stored_embeddings = stored_data["embeddings"]
15
 
16
+ with open("embeddings_2.pkl", "rb") as fIn:
17
+ stored_data_cpt = pickle.load(fIn)
18
+ stored_embeddings_cpt = stored_data_cpt["embeddings"]
19
+
20
  def validate_input(input_string):
21
  # Regular expression pattern to match letters and numbers, or letters only
22
  pattern = r'^[a-zA-Z0-9]+$|^[a-zA-Z]+$'
 
28
  return False
29
 
30
  # Define the function for mapping code
31
+ def mapping_code(user_input, mode):
32
+ if mode == "CPT_to_SBS":
33
+ stored_embeddings = stored_embeddings_cpt
34
+ stored_data = stored_data_cpt
35
+ code_column = stored_data["CPT_CODE"]
36
+ description_column = stored_data["FULL_DESCRIPTION"]
37
+ elif mode == "SBS_to_CPT":
38
+ stored_embeddings = stored_embeddings_sbs
39
+ stored_data = stored_data_sbs
40
+ code_column = stored_data["SBS_code"]
41
+ description_column = stored_data["Description"]
42
 
43
  emb1 = model.encode(user_input.lower())
44
  similarities = []
 
47
  similarities.append(similarity)
48
 
49
  # Filter results with similarity scores above 0.70
50
+ result = [(code, desc, sim) for (code, desc, sim) in zip(code_column, description_column, similarities)]
51
 
52
  # Sort results by similarity scores
53
  result.sort(key=lambda x: x[2], reverse=True)
 
69
  import streamlit as st
70
 
71
  def main():
72
+ st.title("CPT-SBS Code Mapping")
 
73
 
74
+ # Dropdown for user to choose mapping direction
75
+ mapping_mode = st.selectbox("Choose mapping direction:", ("CPT description to SBS code", "SBS description to CPT code"))
76
 
77
+ if mapping_mode == "CPT description to SBS code":
78
+ user_input_label = "Enter CPT description:"
79
+ mode = "CPT_to_SBS"
80
+ else:
81
+ user_input_label = "Enter SBS description:"
82
+ mode = "SBS_to_CPT"
83
 
84
  # Input text box for user input
85
+ user_input = st.text_input(user_input_label, placeholder="Enter description here...")
86
 
87
  # Button to trigger mapping
88
  if st.button("Map"):
89
  if not user_input.strip(): # Check if input is empty or contains only whitespace
90
  st.error("Input box cannot be empty.")
91
  elif validate_input(user_input):
92
+ st.warning("Please input correct description.")
93
  else:
94
+ st.write("Please wait for a moment ...")
95
  # Call backend function to get mapping results
96
  try:
97
+ mapping_results = mapping_code(user_input, mode)
98
  # Display top 5 similar sentences
99
+ st.write("Top 5 similar entries:")
100
  for i, result in enumerate(mapping_results, 1):
101
  st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {float(result['Similarity Score']):.4f}")
102
  except ValueError as e: