Update utills.py
Browse files
utills.py
CHANGED
@@ -33,7 +33,7 @@ def get_session_history(session_id: str):
|
|
33 |
|
34 |
|
35 |
@st.cache_resource
|
36 |
-
def
|
37 |
try:
|
38 |
document_loader = PyPDFDirectoryLoader(data_path)
|
39 |
return document_loader.load()
|
@@ -42,6 +42,15 @@ def load_documents(data_path):
|
|
42 |
return None # or handle the error in an appropriate manner
|
43 |
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
@st.cache_resource
|
46 |
def split_docs(documents, chunk_size, chunk_overlap):
|
47 |
try:
|
@@ -55,6 +64,14 @@ def split_docs(documents, chunk_size, chunk_overlap):
|
|
55 |
print(f"Error splitting documents: {e}")
|
56 |
return [] # or handle the error in an appropriate manner
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
@st.cache_resource
|
59 |
def chroma_db(docs, embeddings):
|
60 |
try:
|
|
|
33 |
|
34 |
|
35 |
@st.cache_resource
|
36 |
+
def load_pdf_documents(data_path):
|
37 |
try:
|
38 |
document_loader = PyPDFDirectoryLoader(data_path)
|
39 |
return document_loader.load()
|
|
|
42 |
return None # or handle the error in an appropriate manner
|
43 |
|
44 |
|
45 |
+
@st.cache_data
|
46 |
+
def load_txt_documents(data_path):
|
47 |
+
documents = []
|
48 |
+
for filename in os.listdir(data_path):
|
49 |
+
if filename.endswith('.txt'):
|
50 |
+
file_path = os.path.join(data_path, filename)
|
51 |
+
documents.extend(TextLoader(file_path).load())
|
52 |
+
return documents
|
53 |
+
|
54 |
@st.cache_resource
|
55 |
def split_docs(documents, chunk_size, chunk_overlap):
|
56 |
try:
|
|
|
64 |
print(f"Error splitting documents: {e}")
|
65 |
return [] # or handle the error in an appropriate manner
|
66 |
|
67 |
+
@st.cache_data
|
68 |
+
def load_uploaded_documents(uploaded_files):
|
69 |
+
documents = []
|
70 |
+
for uploaded_file in uploaded_files:
|
71 |
+
content = uploaded_file.read().decode("utf-8")
|
72 |
+
documents.append({"content": content, "filename": uploaded_file.name})
|
73 |
+
return documents
|
74 |
+
|
75 |
@st.cache_resource
|
76 |
def chroma_db(docs, embeddings):
|
77 |
try:
|