Spaces:
Sleeping
Sleeping
File size: 1,606 Bytes
f0947cd 73473a7 f0947cd 73473a7 f0947cd 1d61ad7 83d7e80 1d61ad7 e476748 f0947cd e476748 f0947cd 73473a7 f0947cd 1d61ad7 f0947cd 73473a7 f0947cd 73473a7 83d7e80 73473a7 f0947cd 83d7e80 f0947cd 83d7e80 f0947cd 83d7e80 f0947cd 73473a7 073b11e 83d7e80 f0947cd 9dc95a3 e476748 83d7e80 9dc95a3 e476748 73473a7 e476748 f0947cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
"""
Basic similarity search example.
"""
import os
import streamlit as st
from sentence_transformers import SentenceTransformer, util
# Write directly to the app
st.title("IRIS - User Experience: : Getting the end-user to choose a similar cached question ")
st.write(
"""Type your question!
System will display **most similar questions**
.
"""
)
st.text_input("Type your question here", key="userquery")
#model = SentenceTransformer("all-MiniLM-L6-v2")
model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
listofCachedItems = ["what was the revenue for FIFA 23", "what was the revenue for ApexLegends", "What was the revenue for FIFA 23 in Aug 2023", "What was the revenue for ApexLegends in Aug 2023"]
emb1 = model.encode(st.session_state.userquery )
maxscore = 0
bestmatch = ""
for i in listofCachedItems:
emb2 = model.encode(i)
cos_sim = util.cos_sim(emb1, emb2)
#print("Cosine-Similarity:" + str(cos_sim) + "\t\t Sentance " + str(i) )
if cos_sim > maxscore :
maxscore = cos_sim
bestmatch = i
#print("Final Result:-")
#print(bestmatch)
#print(maxscore)
#print(type(maxscore))
numericscore = maxscore[0].tolist()
numericscore = numericscore[0]
#print(numericscore)
listofanswer = []
if numericscore > 0.95:
# print(bestmatch)
# print(maxscore)
listofanswer.append(bestmatch)
st.write("Found a similar question that is already precomputed")
option = st.selectbox( 'We identified something similar. Try this?', listofanswer)
else:
st.write("That is a new question. There is no similar questions that is cached")
|