File size: 812 Bytes
f4e8421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
affc041
f4e8421
 
 
e9a3a0c
f4e8421
e9a3a0c
 
 
 
 
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
import streamlit as st

from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS

sample_words = ['apple', 'orange', 'rose', 'chocolate', 'pen', 'school', 'book', 'computer']

#Define the HuggingFaceEmbeddings model
model_path = 'sentence-transformers/all-MiniLM-l6-v2'

embeddings = HuggingFaceEmbeddings(
    model_name= model_path,
    model_kwargs={'device':'cpu'},
    encode_kwargs={'normalize_embeddings': False}
)

db = FAISS.from_texts(sample_words, embeddings)

# UI 
st.header("Similar Word Search App")

input_word = st.text_input("You: ", key= input)

submit = st.button('Show me similar words')

if submit:
    results = db.similarity_search(input_word)
    st.subheader("Top Words:")
    st.text(results[0].page_content)
    st.text(results[1].page_content)