vsubu1 commited on
Commit
213d9cd
·
1 Parent(s): 5686de0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Allows you to use Streamlit, a framework for building interactive web applications.
2
+ #It provides functions for creating UIs, displaying data, and handling user inputs.
3
+ import streamlit as st
4
+
5
+
6
+ #This module provides a way to interact with the operating system, such as accessing environment variables, working with files
7
+ #and directories, executing shell commands, etc
8
+ import os
9
+
10
+ #Helps us generate embeddings
11
+ #An embedding is a vector (list) of floating point numbers. The distance between two vectors measures their relatedness.
12
+ #Small distances suggest high relatedness and large distances suggest low relatedness.
13
+ from langchain.embeddings import OpenAIEmbeddings
14
+
15
+
16
+ #FAISS is an open-source library developed by Facebook AI Research for efficient similarity search and clustering of large-scale datasets, particularly with high-dimensional vectors.
17
+ #It provides optimized indexing structures and algorithms for tasks like nearest neighbor search and recommendation systems.
18
+ from langchain.vectorstores import FAISS
19
+
20
+ #By using st.set_page_config(), you can customize the appearance of your Streamlit application's web page
21
+ st.set_page_config(page_title="Educate Kids", page_icon=":robot:")
22
+ st.header("Hey, Ask me something & I will give out similar things")
23
+
24
+ #Initialize the OpenAIEmbeddings object
25
+ embeddings = OpenAIEmbeddings()
26
+
27
+ #The below snippet helps us to import CSV file data for our tasks
28
+ from langchain.document_loaders.csv_loader import CSVLoader
29
+ loader = CSVLoader(file_path='myData.csv', csv_args={
30
+ 'delimiter': ',',
31
+ 'quotechar': '"',
32
+ 'fieldnames': ['Words']
33
+ })
34
+
35
+ #Assigning the data inside the csv to our variable here
36
+ data = loader.load()
37
+
38
+ #Display the data
39
+ print(data)
40
+
41
+ db = FAISS.from_documents(data, embeddings)
42
+
43
+ #Function to receive input from user and store it in a variable
44
+ def get_text():
45
+ input_text = st.text_input("You: ", key= input)
46
+ return input_text
47
+
48
+
49
+ user_input=get_text()
50
+ submit = st.button('Find similar Things')
51
+
52
+ if submit:
53
+
54
+ #If the button is clicked, the below snippet will fetch us the similar text
55
+ docs = db.similarity_search(user_input)
56
+ print(docs)
57
+ st.subheader("Top Matches:")
58
+ st.text(docs[0])
59
+ st.text(docs[1].page_content)
60
+