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