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