Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
from sentence_transformers import SentenceTransformer, util
|
4 |
-
from spellchecker import SpellChecker
|
5 |
import pickle
|
6 |
|
7 |
# Load the pre-trained SentenceTransformer model
|
@@ -12,23 +12,12 @@ with open("embeddings_1.pkl", "rb") as fIn:
|
|
12 |
stored_data = pickle.load(fIn)
|
13 |
stored_embeddings = stored_data["embeddings"]
|
14 |
|
15 |
-
spell = SpellChecker()
|
16 |
|
17 |
-
# Define a function to check for misspelled words
|
18 |
-
def check_misspelled_words(user_input):
|
19 |
-
# Tokenize the input into words
|
20 |
-
words = user_input.split()
|
21 |
-
|
22 |
-
# Get a list of misspelled words excluding words containing only numbers
|
23 |
-
misspelled = [word for word in words if word.isalpha() and not word.isdigit() and not spell.correction(word.lower()) == word.lower()]
|
24 |
-
|
25 |
-
return misspelled
|
26 |
|
27 |
# Define the function for mapping code
|
28 |
# Define the function for mapping code
|
29 |
def mapping_code(user_input,user_slider_input_number):
|
30 |
-
|
31 |
-
raise ValueError("Input sentence should be at least 5 words long.")
|
32 |
emb1 = model.encode(user_input.lower())
|
33 |
similarities = []
|
34 |
for sentence in stored_embeddings:
|
@@ -57,8 +46,10 @@ def mapping_code(user_input,user_slider_input_number):
|
|
57 |
# Streamlit frontend interface
|
58 |
def main():
|
59 |
st.title("CPT Description Mapping")
|
|
|
60 |
|
61 |
-
st.markdown("
|
|
|
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 |
|
@@ -72,16 +63,11 @@ def main():
|
|
72 |
st.write("Please wait for a moment .... ")
|
73 |
# Call backend function to get mapping results
|
74 |
try:
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
mapping_results = mapping_code(user_input,user_slider_input_number)
|
81 |
-
# Display top 5 similar sentences
|
82 |
-
st.write("Top 5 similar sentences:")
|
83 |
-
for i, result in enumerate(mapping_results, 1):
|
84 |
-
st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {float(result['Similarity Score']):.4f}")
|
85 |
except ValueError as e:
|
86 |
st.error(str(e))
|
87 |
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
from sentence_transformers import SentenceTransformer, util
|
4 |
+
#from spellchecker import SpellChecker
|
5 |
import pickle
|
6 |
|
7 |
# Load the pre-trained SentenceTransformer model
|
|
|
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 |
+
|
|
|
21 |
emb1 = model.encode(user_input.lower())
|
22 |
similarities = []
|
23 |
for sentence in stored_embeddings:
|
|
|
46 |
# Streamlit frontend interface
|
47 |
def main():
|
48 |
st.title("CPT Description Mapping")
|
49 |
+
st.markdown("<font color='red'>**⚠️ Ensure that you input the accurate spellings.**</font>", unsafe_allow_html=True)
|
50 |
|
51 |
+
st.markdown("<font color='blue'>**💡 Note:** Similarity scores are not absolute and should be further confirmed manually for accuracy.</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 |
|
|
|
63 |
st.write("Please wait for a moment .... ")
|
64 |
# Call backend function to get mapping results
|
65 |
try:
|
66 |
+
mapping_results = mapping_code(user_input,user_slider_input_number)
|
67 |
+
# Display top 5 similar sentences
|
68 |
+
st.write("Top 5 similar sentences:")
|
69 |
+
for i, result in enumerate(mapping_results, 1):
|
70 |
+
st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {float(result['Similarity Score']):.4f}")
|
|
|
|
|
|
|
|
|
|
|
71 |
except ValueError as e:
|
72 |
st.error(str(e))
|
73 |
|