Spaces:
Runtime error
Runtime error
Commit
·
13ee1ce
1
Parent(s):
591e68e
pop info in chat for doc upload
Browse files
app.py
CHANGED
@@ -134,20 +134,29 @@ def process_documents(ignored_files: List[str] = []) -> List[Document]:
|
|
134 |
print(f"Split into {len(texts)} chunks of text (max. {chunk_size} tokens each)")
|
135 |
return texts
|
136 |
|
137 |
-
def
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
documents =
|
144 |
if not documents:
|
145 |
print("No new documents to load")
|
146 |
exit(0)
|
147 |
print(f"Loaded {len(documents)} new documents from {source_directory}")
|
148 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
|
149 |
-
|
150 |
-
print(f"Split into {len(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
tt = len(split_docs)
|
152 |
print(split_docs[tt-1])
|
153 |
print(f"Creating embeddings. May take some minutes...")
|
@@ -316,18 +325,21 @@ def chathmi2(message, history):
|
|
316 |
# chatbot = gr.Chatbot().style(color_map =("blue", "pink"))
|
317 |
# chatbot = gr.Chatbot(color_map =("blue", "pink"))
|
318 |
|
319 |
-
def
|
320 |
-
|
321 |
-
|
|
|
|
|
322 |
|
323 |
with gr.Blocks() as demo:
|
324 |
-
gr.ChatInterface(
|
325 |
chathmi2,
|
326 |
-
|
327 |
-
|
|
|
328 |
)
|
329 |
upload_button = gr.UploadButton("Upload File", file_count="multiple")
|
330 |
-
upload_button.upload(
|
331 |
|
332 |
# demo = gr.Interface(
|
333 |
# chathmi,
|
|
|
134 |
print(f"Split into {len(texts)} chunks of text (max. {chunk_size} tokens each)")
|
135 |
return texts
|
136 |
|
137 |
+
def process_documents_2(ignored_files: List[str] = []) -> List[Document]:
|
138 |
+
"""
|
139 |
+
Load documents and split in chunks
|
140 |
+
"""
|
141 |
+
print(f"Loading documents from {source_directory}")
|
142 |
+
print("File Path to start processing:", file_path)
|
143 |
+
documents = load_documents(file_path, ignored_files)
|
144 |
if not documents:
|
145 |
print("No new documents to load")
|
146 |
exit(0)
|
147 |
print(f"Loaded {len(documents)} new documents from {source_directory}")
|
148 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap)
|
149 |
+
texts = text_splitter.split_documents(documents)
|
150 |
+
print(f"Split into {len(texts)} chunks of text (max. {chunk_size} tokens each)")
|
151 |
+
return texts
|
152 |
+
|
153 |
+
def UpdateDb():
|
154 |
+
global vectordb_p
|
155 |
+
# pinecone.Index(index_name).delete(delete_all=True, namespace='')
|
156 |
+
# collection = vectordb_p.get()
|
157 |
+
# split_docs = process_documents([metadata['source'] for metadata in collection['metadatas']])
|
158 |
+
# split_docs = process_documents()
|
159 |
+
split_docs = process_documents_2()
|
160 |
tt = len(split_docs)
|
161 |
print(split_docs[tt-1])
|
162 |
print(f"Creating embeddings. May take some minutes...")
|
|
|
325 |
# chatbot = gr.Chatbot().style(color_map =("blue", "pink"))
|
326 |
# chatbot = gr.Chatbot(color_map =("blue", "pink"))
|
327 |
|
328 |
+
def func_upload_file(files):
|
329 |
+
file_path = files
|
330 |
+
print(file_path)
|
331 |
+
# UpdateDb()
|
332 |
+
return("Test Upload")
|
333 |
|
334 |
with gr.Blocks() as demo:
|
335 |
+
main = gr.ChatInterface(
|
336 |
chathmi2,
|
337 |
+
examples=["What is PDP?"],
|
338 |
+
title="STLA BABY - YOUR FRIENDLY GUIDE",
|
339 |
+
description= "v0.3: Powered by MECH Core Team",
|
340 |
)
|
341 |
upload_button = gr.UploadButton("Upload File", file_count="multiple")
|
342 |
+
upload_button.upload(func_upload_file, upload_button, main)
|
343 |
|
344 |
# demo = gr.Interface(
|
345 |
# chathmi,
|