Spaces:
Runtime error
Runtime error
Commit
·
66d2fc7
1
Parent(s):
b8d3c04
Update app.py
Browse filesupdate DB loader func
app.py
CHANGED
@@ -119,6 +119,27 @@ def load_documents(source_dir: str, ignored_files: List[str] = []) -> List[Docum
|
|
119 |
|
120 |
return results
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
def process_documents(ignored_files: List[str] = []) -> List[Document]:
|
123 |
"""
|
124 |
Load documents and split in chunks
|
@@ -140,7 +161,7 @@ def process_documents_2(ignored_files: List[str] = []) -> List[Document]:
|
|
140 |
"""
|
141 |
print(f"Loading documents from {source_directory}")
|
142 |
print("File Path to start processing:", file_path)
|
143 |
-
documents =
|
144 |
if not documents:
|
145 |
print("No new documents to load")
|
146 |
exit(0)
|
@@ -328,20 +349,23 @@ def chathmi2(message, history):
|
|
328 |
def func_upload_file(files, chat_history):
|
329 |
file_path = files
|
330 |
print(file_path)
|
331 |
-
#
|
332 |
-
|
333 |
-
test_msg
|
|
|
|
|
|
|
334 |
chat_history.append(test_msg)
|
335 |
-
|
336 |
|
337 |
with gr.Blocks() as demo:
|
338 |
main = gr.ChatInterface(
|
339 |
chathmi2,
|
340 |
title="STLA BABY - YOUR FRIENDLY GUIDE",
|
341 |
description= "v0.3: Powered by MECH Core Team",
|
|
|
342 |
)
|
343 |
-
upload_button
|
344 |
-
upload_button.upload(func_upload_file, [upload_button, main.chatbot], main.chatbot)
|
345 |
|
346 |
# demo = gr.Interface(
|
347 |
# chathmi,
|
|
|
119 |
|
120 |
return results
|
121 |
|
122 |
+
def load_documents_2(all_files: List[str] = [], ignored_files: List[str] = []) -> List[Document]:
|
123 |
+
"""
|
124 |
+
Loads all documents from the source documents directory, ignoring specified files
|
125 |
+
"""
|
126 |
+
# all_files = []
|
127 |
+
# for ext in LOADER_MAPPING:
|
128 |
+
# all_files.extend(
|
129 |
+
# glob.glob(os.path.join(source_dir, f"**/*{ext}"), recursive=True)
|
130 |
+
# )
|
131 |
+
filtered_files = [file_path for file_path in all_files if file_path not in ignored_files]
|
132 |
+
|
133 |
+
with Pool(processes=os.cpu_count()) as pool:
|
134 |
+
results = []
|
135 |
+
with tqdm(total=len(filtered_files), desc='Loading new documents', ncols=80) as pbar:
|
136 |
+
for i, docs in enumerate(pool.imap_unordered(load_single_document, filtered_files)):
|
137 |
+
results.extend(docs)
|
138 |
+
pbar.update()
|
139 |
+
|
140 |
+
return results
|
141 |
+
|
142 |
+
|
143 |
def process_documents(ignored_files: List[str] = []) -> List[Document]:
|
144 |
"""
|
145 |
Load documents and split in chunks
|
|
|
161 |
"""
|
162 |
print(f"Loading documents from {source_directory}")
|
163 |
print("File Path to start processing:", file_path)
|
164 |
+
documents = load_documents_2(file_path, ignored_files)
|
165 |
if not documents:
|
166 |
print("No new documents to load")
|
167 |
exit(0)
|
|
|
349 |
def func_upload_file(files, chat_history):
|
350 |
file_path = files
|
351 |
print(file_path)
|
352 |
+
# print(chat_history)
|
353 |
+
test_msg = ["Request Upload File into DB", "Operation Ongoing...."]
|
354 |
+
chat_history.append(test_msg)
|
355 |
+
yield chat_history
|
356 |
+
UpdateDb()
|
357 |
+
test_msg = ["Request Upload File into DB", "Operation Finished"]
|
358 |
chat_history.append(test_msg)
|
359 |
+
yield chat_history
|
360 |
|
361 |
with gr.Blocks() as demo:
|
362 |
main = gr.ChatInterface(
|
363 |
chathmi2,
|
364 |
title="STLA BABY - YOUR FRIENDLY GUIDE",
|
365 |
description= "v0.3: Powered by MECH Core Team",
|
366 |
+
upload_button = gr.UploadButton("Upload File", file_count="multiple")
|
367 |
)
|
368 |
+
main.upload_button.upload(func_upload_file, [main.upload_button, main.chatbot], main.chatbot)
|
|
|
369 |
|
370 |
# demo = gr.Interface(
|
371 |
# chathmi,
|