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)