Upload 5 files
Browse files- app_notes_ai.py +233 -0
- chat_histories.json +53 -0
- config.json +1 -0
- requirements.txt +12 -0
- vectorize_documents.py +86 -0
app_notes_ai.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 6 |
+
from langchain_chroma import Chroma
|
| 7 |
+
from langchain_groq import ChatGroq
|
| 8 |
+
from langchain.memory import ConversationBufferMemory
|
| 9 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
from vectorize_documents import embeddings
|
| 13 |
+
|
| 14 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
+
config_data = json.load(open(f"{working_dir}/config.json"))
|
| 16 |
+
GROQ_API_KEY = config_data["GROQ_API_KEY"]
|
| 17 |
+
os.environ["GROQ_API_KEY"]= GROQ_API_KEY
|
| 18 |
+
|
| 19 |
+
# Ensure the JSON file exists
|
| 20 |
+
chat_history_file = "chat_histories.json"
|
| 21 |
+
if not os.path.exists(chat_history_file):
|
| 22 |
+
with open(chat_history_file, "w") as f:
|
| 23 |
+
json.dump({}, f)
|
| 24 |
+
|
| 25 |
+
# Functions to handle chat history
|
| 26 |
+
def load_chat_history():
|
| 27 |
+
with open(chat_history_file, "r") as f:
|
| 28 |
+
return json.load(f)
|
| 29 |
+
|
| 30 |
+
def save_chat_history(chat_histories):
|
| 31 |
+
with open(chat_history_file, "w") as f:
|
| 32 |
+
json.dump(chat_histories, f, indent=4)
|
| 33 |
+
|
| 34 |
+
# Function to set up vectorstore
|
| 35 |
+
def setup_vectorstore():
|
| 36 |
+
embeddings = HuggingFaceEmbeddings()
|
| 37 |
+
vectorstore = Chroma(persist_directory="vector_db_dir_notes_ai",
|
| 38 |
+
embedding_function=embeddings)
|
| 39 |
+
return vectorstore
|
| 40 |
+
|
| 41 |
+
# Function to set up chatbot chain
|
| 42 |
+
def chat_chain(vectorstore):
|
| 43 |
+
llm = ChatGroq(
|
| 44 |
+
model="llama-3.1-70b-versatile",
|
| 45 |
+
temperature=0
|
| 46 |
+
)
|
| 47 |
+
retriever = vectorstore.as_retriever()
|
| 48 |
+
memory = ConversationBufferMemory(
|
| 49 |
+
llm=llm,
|
| 50 |
+
output_key="answer",
|
| 51 |
+
memory_key="chat_history",
|
| 52 |
+
return_messages=True
|
| 53 |
+
)
|
| 54 |
+
chain = ConversationalRetrievalChain.from_llm(
|
| 55 |
+
llm=llm,
|
| 56 |
+
retriever=retriever,
|
| 57 |
+
chain_type="stuff",
|
| 58 |
+
memory=memory,
|
| 59 |
+
verbose=True,
|
| 60 |
+
return_source_documents=True
|
| 61 |
+
)
|
| 62 |
+
return chain
|
| 63 |
+
|
| 64 |
+
# Streamlit UI
|
| 65 |
+
st.set_page_config(
|
| 66 |
+
page_title="Notes.AI",
|
| 67 |
+
page_icon="🤖AI",
|
| 68 |
+
layout="centered"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
st.title("🤖 Notes.AI")
|
| 72 |
+
st.subheader("Hey! Here you can search for notes of CSE 7th Sem! Read Notes, Read PYQ answers also!!")
|
| 73 |
+
|
| 74 |
+
# Step 1: Input user's name
|
| 75 |
+
if "username" not in st.session_state:
|
| 76 |
+
username = st.text_input("Enter your name to proceed:")
|
| 77 |
+
if username:
|
| 78 |
+
with st.spinner("Loading chatbot interface... Please wait."):
|
| 79 |
+
st.session_state.username = username
|
| 80 |
+
st.session_state.chat_history = [] # Initialize empty chat history
|
| 81 |
+
st.session_state.vectorstore = setup_vectorstore()
|
| 82 |
+
st.session_state.conversational_chain = chat_chain(st.session_state.vectorstore)
|
| 83 |
+
st.success(f"Welcome, {username}! The chatbot interface is ready.")
|
| 84 |
+
else:
|
| 85 |
+
username = st.session_state.username
|
| 86 |
+
|
| 87 |
+
# Step 2: Initialize components if not already set
|
| 88 |
+
if "conversational_chain" not in st.session_state:
|
| 89 |
+
st.session_state.vectorstore = setup_vectorstore()
|
| 90 |
+
st.session_state.conversational_chain = chat_chain(st.session_state.vectorstore)
|
| 91 |
+
|
| 92 |
+
# Step 3: Show chatbot interface
|
| 93 |
+
if "username" in st.session_state:
|
| 94 |
+
st.subheader(f"Hello {username}, start your query below!")
|
| 95 |
+
|
| 96 |
+
# Display existing chat history dynamically
|
| 97 |
+
for message in st.session_state.chat_history:
|
| 98 |
+
if message["role"] == "user":
|
| 99 |
+
with st.chat_message("user"):
|
| 100 |
+
st.markdown(message["content"])
|
| 101 |
+
elif message["role"] == "assistant":
|
| 102 |
+
with st.chat_message("assistant"):
|
| 103 |
+
st.markdown(message["content"])
|
| 104 |
+
|
| 105 |
+
# User input section
|
| 106 |
+
user_input = st.chat_input("Ask AI....")
|
| 107 |
+
if user_input:
|
| 108 |
+
with st.spinner("Processing your query... Please wait."):
|
| 109 |
+
# Save user input to session state
|
| 110 |
+
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
| 111 |
+
|
| 112 |
+
# Display user's message
|
| 113 |
+
with st.chat_message("user"):
|
| 114 |
+
st.markdown(user_input)
|
| 115 |
+
|
| 116 |
+
# Get assistant's response
|
| 117 |
+
with st.chat_message("assistant"):
|
| 118 |
+
response = st.session_state.conversational_chain({"question": user_input})
|
| 119 |
+
assistant_response = response["answer"]
|
| 120 |
+
st.markdown(assistant_response)
|
| 121 |
+
|
| 122 |
+
# Save assistant's response to session state
|
| 123 |
+
st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
| 124 |
+
|
| 125 |
+
# Save chat history to file with timestamp
|
| 126 |
+
chat_histories = load_chat_history()
|
| 127 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 128 |
+
if username not in chat_histories:
|
| 129 |
+
chat_histories[username] = []
|
| 130 |
+
chat_histories[username].append({
|
| 131 |
+
"timestamp": timestamp,
|
| 132 |
+
"user": user_input,
|
| 133 |
+
"assistant": assistant_response
|
| 134 |
+
})
|
| 135 |
+
save_chat_history(chat_histories)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
# import os
|
| 147 |
+
# import json
|
| 148 |
+
|
| 149 |
+
# import streamlit as st
|
| 150 |
+
# from langchain_huggingface import HuggingFaceEmbeddings
|
| 151 |
+
# from langchain_chroma import Chroma
|
| 152 |
+
# from langchain_groq import ChatGroq
|
| 153 |
+
# from langchain.memory import ConversationBufferMemory
|
| 154 |
+
# from langchain.chains import ConversationalRetrievalChain
|
| 155 |
+
|
| 156 |
+
# from vectorize_documents import embeddings
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# working_dir = os.path.dirname(os.path.abspath(__file__))
|
| 160 |
+
# config_data = json.load(open(f"{working_dir}/config.json"))
|
| 161 |
+
# GROQ_API_KEY = config_data["GROQ_API_KEY"]
|
| 162 |
+
# os.environ["GROQ_API_KEY"]= GROQ_API_KEY
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# def setup_vectorstore():
|
| 166 |
+
# persist_directory = f"{working_dir}/vector_db_dir_notes_ai"
|
| 167 |
+
# embeddings = HuggingFaceEmbeddings()
|
| 168 |
+
# vectorstore = Chroma(persist_directory=persist_directory,
|
| 169 |
+
# embedding_function=embeddings)
|
| 170 |
+
# return vectorstore
|
| 171 |
+
|
| 172 |
+
# def chat_chain(vectorstore):
|
| 173 |
+
# llm = ChatGroq(
|
| 174 |
+
# model = "llama-3.1-70b-versatile",
|
| 175 |
+
# temperature = 0
|
| 176 |
+
# )
|
| 177 |
+
# retriever = vectorstore.as_retriever()
|
| 178 |
+
# memory = ConversationBufferMemory(
|
| 179 |
+
# llm = llm,
|
| 180 |
+
# output_key = "answer",
|
| 181 |
+
# memory_key = "chat_history",
|
| 182 |
+
# return_messages = True
|
| 183 |
+
# )
|
| 184 |
+
# chain = ConversationalRetrievalChain.from_llm(
|
| 185 |
+
# llm=llm,
|
| 186 |
+
# retriever = retriever,
|
| 187 |
+
# chain_type = "stuff",
|
| 188 |
+
# memory = memory,
|
| 189 |
+
# verbose=True,
|
| 190 |
+
# return_source_documents= True
|
| 191 |
+
# )
|
| 192 |
+
# return chain
|
| 193 |
+
|
| 194 |
+
# st.set_page_config(
|
| 195 |
+
# page_title="Notes.AI",
|
| 196 |
+
# page_icon="🤖AI",
|
| 197 |
+
# layout="centered"
|
| 198 |
+
# )
|
| 199 |
+
|
| 200 |
+
# st.title("🤖 Notes.AI")
|
| 201 |
+
|
| 202 |
+
# # st.title("🤖 Hey! Here you can search for notes of CSE 7th Sem! Read Notes, Read PYQ answers also!!")
|
| 203 |
+
|
| 204 |
+
# st.subheader("Hey! Here you can search for notes of CSE 7th Sem! Read Notes, Read PYQ answers also!!")
|
| 205 |
+
|
| 206 |
+
# # Additional subheading
|
| 207 |
+
# st.subheader("Start your query below to get instant help!")
|
| 208 |
+
|
| 209 |
+
# if "chat_history" not in st.session_state:
|
| 210 |
+
# st.session_state.chat_history = []
|
| 211 |
+
|
| 212 |
+
# if "vectorstore" not in st.session_state:
|
| 213 |
+
# st.session_state.vectorstore = setup_vectorstore()
|
| 214 |
+
|
| 215 |
+
# if "conversational_chain" not in st.session_state:
|
| 216 |
+
# st.session_state.conversational_chain = chat_chain(st.session_state.vectorstore)
|
| 217 |
+
|
| 218 |
+
# for message in st.session_state.chat_history:
|
| 219 |
+
# with st.chat_message(message["role"]):
|
| 220 |
+
# st.markdown(message["content"])
|
| 221 |
+
# user_input = st.chat_input("Ask AI....")
|
| 222 |
+
|
| 223 |
+
# if user_input:
|
| 224 |
+
# st.session_state.chat_history.append({"role":"user", "content":user_input})
|
| 225 |
+
|
| 226 |
+
# with st.chat_message("user"):
|
| 227 |
+
# st.markdown(user_input)
|
| 228 |
+
|
| 229 |
+
# with st.chat_message("assistant"):
|
| 230 |
+
# response = st.session_state.conversational_chain({"question":user_input})
|
| 231 |
+
# assistant_response = response["answer"]
|
| 232 |
+
# st.markdown(assistant_response)
|
| 233 |
+
# st.session_state.chat_history.append({"role":"assistant","content": assistant_response})
|
chat_histories.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"Krishna": [
|
| 3 |
+
{
|
| 4 |
+
"question": {
|
| 5 |
+
"question": "what is computer graphics and what are the applications of it",
|
| 6 |
+
"day": "Sunday",
|
| 7 |
+
"time": "2024-11-17 21:19:38"
|
| 8 |
+
},
|
| 9 |
+
"answer": {
|
| 10 |
+
"answer": "Computer graphics is a field of study that deals with the creation, manipulation, and display of visual data using computers. It involves the use of algorithms, software, and hardware to generate and display images, 3D models, and animations.\n\nThe applications of computer graphics are diverse and widespread, and can be found in various fields, including:\n\n1. **Entertainment**: Computer graphics is used in the film and video game industries to create special effects, animations, and 3D models.\n2. **Architecture and Engineering**: Computer-aided design (CAD) software uses computer graphics to create 2D and 3D models of buildings, bridges, and other structures.\n3. **Medical Imaging**: Computer graphics is used in medical imaging to create 3D models of the body and to visualize medical data.\n4. **Scientific Visualization**: Computer graphics is used to visualize complex scientific data, such as weather patterns, molecular structures, and astronomical data.\n5. **Advertising and Marketing**: Computer graphics is used to create 3D models and animations for advertisements and marketing campaigns.\n6. **Education**: Computer graphics is used to create interactive educational materials, such as simulations and virtual labs.\n7. **Virtual Reality (VR) and Augmented Reality (AR)**: Computer graphics is used to create immersive and interactive experiences in VR and AR applications.\n8. **Computer-Aided Design (CAD)**: Computer graphics is used in CAD software to create 2D and 3D models of products and systems.\n9. **Geographic Information Systems (GIS)**: Computer graphics is used in GIS to create 2D and 3D maps and to visualize geographic data.\n10. **Art and Design**: Computer graphics is used by artists and designers to create digital art, illustrations, and designs.\n\nThese are just a few examples of the many applications of computer graphics. The field is constantly evolving, and new applications are being developed all the time.",
|
| 11 |
+
"day": "Sunday",
|
| 12 |
+
"time": "2024-11-17 21:19:38"
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
],
|
| 16 |
+
"krish": [
|
| 17 |
+
{
|
| 18 |
+
"timestamp": "2024-11-17 21:47:28",
|
| 19 |
+
"user": "hello",
|
| 20 |
+
"assistant": "Hello. How can I help you today? Do you have a question about the provided text on blockchain and Ethereum?"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"timestamp": "2024-11-17 21:47:52",
|
| 24 |
+
"user": "what is computer graphics",
|
| 25 |
+
"assistant": "The text doesn't explicitly define computer graphics, but based on the context, it appears to refer to the use of computers to create, display, and interact with visual information, including images, graphics, and other visual elements. This can include two-dimensional and three-dimensional applications, and can be used in a wide range of fields, such as art, design, engineering, and more."
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"timestamp": "2024-11-17 21:53:22",
|
| 29 |
+
"user": "what is computer graphics and its applications",
|
| 30 |
+
"assistant": "Computer graphics refers to the use of computer technology to create, manipulate, and display visual information, such as images, videos, and 3D models. It involves the use of algorithms, software, and hardware to generate and display graphical data.\n\nComputer graphics has a wide range of applications across various fields, including:\n\n1. **Computer-Aided Design (CAD)**: Computer graphics is used in CAD to create and manipulate 2D and 3D models of objects, such as buildings, machines, and products.\n2. **Video Games**: Computer graphics is used to create 3D models, animations, and special effects in video games.\n3. **Film and Animation**: Computer graphics is used to create special effects, animations, and 3D models in movies and television shows.\n4. **Medical Imaging**: Computer graphics is used to create 3D models of the human body and to visualize medical data, such as MRI and CT scans.\n5. **Scientific Visualization**: Computer graphics is used to visualize complex scientific data, such as weather patterns, ocean currents, and molecular structures.\n6. **Architecture and Urban Planning**: Computer graphics is used to create 3D models of buildings and cities, and to visualize urban planning projects.\n7. **Advertising and Marketing**: Computer graphics is used to create 3D models and animations for advertisements and marketing campaigns.\n8. **Education and Training**: Computer graphics is used to create interactive simulations and 3D models for educational purposes.\n9. **Virtual Reality (VR) and Augmented Reality (AR)**: Computer graphics is used to create immersive and interactive experiences in VR and AR applications.\n10. **Air Traffic Control and Simulation**: Computer graphics is used to create 3D models of airports and air traffic control systems, and to simulate flight scenarios.\n\nThese are just a few examples of the many applications of computer graphics. The field is constantly evolving, and new applications are emerging all the time."
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"timestamp": "2024-11-17 21:53:58",
|
| 34 |
+
"user": "what is cloud computing ",
|
| 35 |
+
"assistant": "According to the provided text, cloud computing means storing and accessing data and programs over the Internet from a remote location or computer instead of a local computer's hard drive. This allows users to access their data or programs from anywhere, at any time, and from any device with an internet connection."
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"timestamp": "2024-11-17 21:58:01",
|
| 39 |
+
"user": "what is blockchain fundamentals ",
|
| 40 |
+
"assistant": "Based on the provided context, blockchain fundamentals can be defined as follows:\n\n1. **Linked List**: A blockchain is a linked list, which is a set of blocks connected to each other by some kind of link.\n2. **Distributed Data Structure**: A blockchain is a distributed data structure, which means it is replicated at various nodes or computers.\n3. **Decentralized Consensus Mechanism**: A blockchain is a decentralized consensus mechanism, where no single authority is in charge of the database.\n4. **Disintermediation**: A blockchain allows for disintermediation, which means that no centrally trusted arbitrator is required for transactions.\n5. **Peer-to-Peer Transactions**: A blockchain enables peer-to-peer transactions, where peers can exchange value/e-cash without the need for a trusted third party.\n\nThese fundamentals highlight the core characteristics of a blockchain, including its structure, decentralization, and ability to facilitate peer-to-peer transactions without intermediaries."
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"timestamp": "2024-11-17 21:58:22",
|
| 44 |
+
"user": "what is computer graphics importance",
|
| 45 |
+
"assistant": "The text doesn't explicitly state the importance of computer graphics. However, based on the context, it can be inferred that computer graphics is important in various fields such as:\n\n1. Art and design (e.g., artist's painting programs)\n2. Business (e.g., business graphics packages)\n3. Medicine (e.g., medical imaging)\n4. Computer-aided design (CAD)\n5. Simulation (e.g., air traffic control)\n6. Scientific visualization\n\nThese fields likely rely on computer graphics to create visual representations of data, models, and simulations, which can aid in understanding, analysis, and decision-making. However, the text does not provide a direct answer to the importance of computer graphics."
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"timestamp": "2024-11-17 21:58:47",
|
| 49 |
+
"user": "give more details on importance",
|
| 50 |
+
"assistant": "The provided text does not explicitly discuss the importance of computer graphics. However, it does provide information on the different types of graphics software, output primitives, and picture-generation procedures, which suggests that computer graphics is a significant field with various applications.\n\nIf you're looking for information on the importance of computer graphics, I can provide some general information. Computer graphics is a crucial field that has numerous applications in various industries, including:\n\n1. Entertainment: Computer graphics is used in movies, video games, and other forms of digital media to create realistic and engaging visual effects.\n2. Education: Computer graphics is used in educational institutions to create interactive and immersive learning experiences.\n3. Architecture and Engineering: Computer graphics is used to create 3D models and simulations of buildings, bridges, and other structures to aid in design and construction.\n4. Medical Imaging: Computer graphics is used in medical imaging to create 3D models of the human body and to visualize medical data.\n5. Scientific Visualization: Computer graphics is used to visualize complex scientific data, such as weather patterns, ocean currents, and molecular structures.\n\nThese are just a few examples of the many applications of computer graphics. However, the provided text does not specifically discuss the importance of computer graphics."
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"GROQ_API_KEY": "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"}
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.38.0
|
| 2 |
+
langchain-community==0.2.16
|
| 3 |
+
langchain-text-splitters==0.2.4
|
| 4 |
+
langchain-chroma==0.1.3
|
| 5 |
+
langchain-huggingface==0.0.3
|
| 6 |
+
langchain-groq==0.1.9
|
| 7 |
+
unstructured==0.15.0
|
| 8 |
+
unstructured[pdf]==0.15.0
|
| 9 |
+
nltk==3.8.1
|
| 10 |
+
psycopg2-binary
|
| 11 |
+
pgvector
|
| 12 |
+
langchain_postgres
|
vectorize_documents.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_community.document_loaders import UnstructuredFileLoader
|
| 2 |
+
from langchain_community.document_loaders import DirectoryLoader
|
| 3 |
+
from langchain_text_splitters import CharacterTextSplitter
|
| 4 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 5 |
+
from langchain_chroma import Chroma
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# # Define a function to perform vectorization
|
| 9 |
+
def vectorize_documents():
|
| 10 |
+
embeddings = HuggingFaceEmbeddings()
|
| 11 |
+
|
| 12 |
+
loader = DirectoryLoader(
|
| 13 |
+
path="Data_1",
|
| 14 |
+
glob="./*.pdf",
|
| 15 |
+
loader_cls=UnstructuredFileLoader
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
documents = loader.load()
|
| 19 |
+
|
| 20 |
+
# Splitting the text and creating chunks of these documents.
|
| 21 |
+
text_splitter = CharacterTextSplitter(
|
| 22 |
+
chunk_size=2000,
|
| 23 |
+
chunk_overlap=500
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
text_chunks = text_splitter.split_documents(documents)
|
| 27 |
+
|
| 28 |
+
# Store in Chroma vector DB
|
| 29 |
+
vectordb = Chroma.from_documents(
|
| 30 |
+
documents=text_chunks,
|
| 31 |
+
embedding=embeddings,
|
| 32 |
+
persist_directory="vector_db_dir_notes_ai"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
print("Documents Vectorized and saved in VectorDB")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Expose embeddings if needed
|
| 40 |
+
embeddings = HuggingFaceEmbeddings()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Main guard to prevent execution on import
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
vectorize_documents()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# # Define a function to perform vectorization
|
| 50 |
+
# def vectorize_documents():
|
| 51 |
+
# # Loading the embedding model
|
| 52 |
+
# embeddings = HuggingFaceEmbeddings()
|
| 53 |
+
|
| 54 |
+
# loader = DirectoryLoader(
|
| 55 |
+
# path="Data",
|
| 56 |
+
# glob="./*.pdf",
|
| 57 |
+
# loader_cls=UnstructuredFileLoader
|
| 58 |
+
# )
|
| 59 |
+
|
| 60 |
+
# documents = loader.load()
|
| 61 |
+
|
| 62 |
+
# # Splitting the text and creating chunks of these documents.
|
| 63 |
+
# text_splitter = CharacterTextSplitter(
|
| 64 |
+
# chunk_size=2000,
|
| 65 |
+
# chunk_overlap=500
|
| 66 |
+
# )
|
| 67 |
+
|
| 68 |
+
# text_chunks = text_splitter.split_documents(documents)
|
| 69 |
+
|
| 70 |
+
# # Store in Chroma vector DB
|
| 71 |
+
# vectordb = Chroma.from_documents(
|
| 72 |
+
# documents=text_chunks,
|
| 73 |
+
# embedding=embeddings,
|
| 74 |
+
# persist_directory="vector_db_dir"
|
| 75 |
+
# )
|
| 76 |
+
|
| 77 |
+
# print("Documents Vectorized and saved in VectorDB")
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# # Expose embeddings if needed
|
| 81 |
+
# embeddings = HuggingFaceEmbeddings()
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# # Main guard to prevent execution on import
|
| 85 |
+
# if __name__ == "__main__":
|
| 86 |
+
# vectorize_documents()
|