Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +46 -0
- mydata.csv +13 -0
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
4 |
+
from langchain_community.vectorstores import FAISS
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
st.set_page_config(page_title="Educate Kids", page_icon=":robot:")
|
9 |
+
st.header("Hey, Ask me something & I will give out similar things")
|
10 |
+
|
11 |
+
|
12 |
+
embeddings=HuggingFaceEmbeddings()
|
13 |
+
|
14 |
+
from langchain.document_loaders.csv_loader import CSVLoader
|
15 |
+
loader = CSVLoader(file_path='mydata.csv', csv_args={
|
16 |
+
'delimiter': ',',
|
17 |
+
'quotechar': '"',
|
18 |
+
'fieldnames': ['Words']
|
19 |
+
})
|
20 |
+
|
21 |
+
data = loader.load()
|
22 |
+
|
23 |
+
print(data)
|
24 |
+
|
25 |
+
db = FAISS.from_documents(data, embeddings)
|
26 |
+
|
27 |
+
|
28 |
+
def get_text():
|
29 |
+
input_text = st.text_input("You: ", key= input)
|
30 |
+
return input_text
|
31 |
+
|
32 |
+
|
33 |
+
user_input=get_text()
|
34 |
+
submit = st.button('Find similar Things')
|
35 |
+
|
36 |
+
if submit:
|
37 |
+
|
38 |
+
docs = db.similarity_search(user_input)
|
39 |
+
st.subheader("Top Matches:")
|
40 |
+
if docs:
|
41 |
+
for item in docs[1:]:
|
42 |
+
st.write(item.page_content)
|
43 |
+
else:
|
44 |
+
st.write("No similar things found")
|
45 |
+
|
46 |
+
|
mydata.csv
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
words
|
2 |
+
lion
|
3 |
+
elephant
|
4 |
+
dog
|
5 |
+
cricket
|
6 |
+
football
|
7 |
+
tennis
|
8 |
+
basketball
|
9 |
+
apple
|
10 |
+
orange
|
11 |
+
banana
|
12 |
+
cat
|
13 |
+
tiger
|