Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
4 |
+
from langchain.vectorstores import FAISS
|
5 |
+
|
6 |
+
sample_words = ['apple', 'orange', 'rose', 'chocolate', 'pen', 'school', 'book', 'computer']
|
7 |
+
|
8 |
+
#Define the HuggingFaceEmbeddings model
|
9 |
+
model_path = 'sentence-transformers/all-MiniLM-l6-v2'
|
10 |
+
|
11 |
+
embeddings = HuggingFaceEmbeddings(
|
12 |
+
model_name= model_path,
|
13 |
+
model_kwargs={'device':'cpu'},
|
14 |
+
encode_kwargs={'normalize_embeddings': False}
|
15 |
+
)
|
16 |
+
|
17 |
+
|
18 |
+
db = FAISS.from_texts(sample_words, embeddings)
|
19 |
+
|
20 |
+
# UI
|
21 |
+
st.header('Ask me a question, and I'll provide similar words!')
|
22 |
+
|
23 |
+
input_word = st.text_input("You: ", key= input)
|
24 |
+
|
25 |
+
if input_word:
|
26 |
+
submit = st.button('Show me similar words')
|
27 |
+
|
28 |
+
if submit:
|
29 |
+
results = db.similarity_search(input_word)
|
30 |
+
st.subheader("Top Words:")
|
31 |
+
st.text(docs[0].page_content)
|
32 |
+
st.text(docs[1].page_content)
|
33 |
+
|