Jayavathsan commited on
Commit
b573534
·
1 Parent(s): becc5d0

Create app.py

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