Spaces:
Sleeping
Sleeping
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("Ask me a question, and I'll provide similar words!") | |
input_word = st.text_input("You: ", key= input) | |
if input_word: | |
submit = st.button('Show me similar words') | |
if submit: | |
results = db.similarity_search(input_word) | |
st.subheader("Top Words:") | |
st.text(docs[0].page_content) | |
st.text(docs[1].page_content) | |