|
import streamlit as st |
|
import torch |
|
from sentence_transformers import SentenceTransformer, util |
|
|
|
|
|
model = SentenceTransformer('all-MiniLM-L6-v2') |
|
|
|
|
|
def mapping_code(user_input): |
|
emb1 = model.encode(user_input.lower()) |
|
similarities = [] |
|
for sentence_embed in sentences['embeds']: |
|
similarity = util.cos_sim(sentence_embed, emb1) |
|
similarities.append(similarity) |
|
|
|
|
|
result = list(zip(sentences['SBS Code'], sentences['Long Description'], similarities)) |
|
|
|
|
|
result.sort(key=lambda x: x[2], reverse=True) |
|
|
|
|
|
top_5_results = [] |
|
for i in range(5): |
|
code, description, similarity_score = result[i] |
|
top_5_results.append({"Code": code, "Description": description, "Similarity Score": similarity_score}) |
|
return top_5_results |
|
|
|
|
|
def main(): |
|
st.title("CPT Description Mapping") |
|
|
|
|
|
user_input = st.text_input("Enter CPT description:") |
|
|
|
|
|
if st.button("Map"): |
|
if user_input: |
|
st.write("Please wait for a moment .... ") |
|
|
|
|
|
mapping_results = mapping_code(user_input) |
|
|
|
|
|
st.write("Top 5 similar sentences:") |
|
for i, result in enumerate(mapping_results, 1): |
|
st.write(f"{i}. Code: {result['Code']}, Description: {result['Description']}, Similarity Score: {result['Similarity Score']:.4f}") |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |