Spaces:
Runtime error
Runtime error
Commit
·
dd10a48
1
Parent(s):
19bc884
add summary
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ from langchain.memory import ConversationBufferWindowMemory
|
|
22 |
from langchain.agents import ZeroShotAgent, AgentExecutor
|
23 |
from langchain.agents import OpenAIMultiFunctionsAgent
|
24 |
from langchain.prompts import MessagesPlaceholder
|
|
|
25 |
from langchain.schema.messages import (
|
26 |
AIMessage,
|
27 |
BaseMessage,
|
@@ -223,6 +224,26 @@ def UpdateDb():
|
|
223 |
print("Pinecone Updated Done")
|
224 |
print(index.describe_index_stats())
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
class DB_Search(BaseTool):
|
228 |
name = "Vector_Database_Search"
|
@@ -690,6 +711,28 @@ def func_upload_file(files, chat_history2):
|
|
690 |
chat_history2.append(test_msg)
|
691 |
yield chat_history2
|
692 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
693 |
class Logger:
|
694 |
def __init__(self, filename):
|
695 |
self.terminal = sys.stdout
|
@@ -994,7 +1037,7 @@ with gr.Blocks() as demo:
|
|
994 |
|
995 |
with gr.Column() as main2:
|
996 |
title = gr.Markdown("""# <center> STLA BABY - YOUR FRIENDLY GUIDE
|
997 |
-
<center> v0.
|
998 |
chatbot = gr.Chatbot()
|
999 |
with gr.Row():
|
1000 |
inputtext = gr.Textbox(
|
@@ -1030,7 +1073,7 @@ with gr.Blocks() as demo:
|
|
1030 |
label= "OUTPUT",
|
1031 |
)
|
1032 |
upload_button = gr.UploadButton("✡️ INGEST DB", file_count="multiple", scale= 0, variant="secondary")
|
1033 |
-
upload_file_button = gr.UploadButton("📁
|
1034 |
retry_button = gr.Button("RETRY")
|
1035 |
clear_button = gr.Button("CLEAR")
|
1036 |
with gr.Accordion(
|
|
|
22 |
from langchain.agents import ZeroShotAgent, AgentExecutor
|
23 |
from langchain.agents import OpenAIMultiFunctionsAgent
|
24 |
from langchain.prompts import MessagesPlaceholder
|
25 |
+
from langchain.chains.summarize import load_summarize_chain
|
26 |
from langchain.schema.messages import (
|
27 |
AIMessage,
|
28 |
BaseMessage,
|
|
|
224 |
print("Pinecone Updated Done")
|
225 |
print(index.describe_index_stats())
|
226 |
|
227 |
+
def SummarizeDoc():
|
228 |
+
global vectordb_p
|
229 |
+
# pinecone.Index(index_name).delete(delete_all=True, namespace='')
|
230 |
+
# collection = vectordb_p.get()
|
231 |
+
# split_docs = process_documents([metadata['source'] for metadata in collection['metadatas']])
|
232 |
+
# split_docs = process_documents()
|
233 |
+
split_docs = process_documents_2()
|
234 |
+
tt = len(split_docs)
|
235 |
+
print(split_docs[tt-1])
|
236 |
+
|
237 |
+
try:
|
238 |
+
sum_chain = load_summarize_chain(llm, chain_type='refine', verbose=True)
|
239 |
+
sum_text = sum_chain.run(split_docs)
|
240 |
+
except Exception as e:
|
241 |
+
print("SummarizeDoc error:", e)
|
242 |
+
|
243 |
+
# sum_text = "test sum"
|
244 |
+
return sum_text
|
245 |
+
|
246 |
+
|
247 |
|
248 |
class DB_Search(BaseTool):
|
249 |
name = "Vector_Database_Search"
|
|
|
711 |
chat_history2.append(test_msg)
|
712 |
yield chat_history2
|
713 |
|
714 |
+
|
715 |
+
def Summary_upload_file(files, chat_history2):
|
716 |
+
global file_list_loaded
|
717 |
+
file_list_loaded = []
|
718 |
+
for unit in files:
|
719 |
+
file_list_loaded.append(unit.name)
|
720 |
+
# file_list_loaded = files
|
721 |
+
print(file_list_loaded)
|
722 |
+
# print(chat_history)
|
723 |
+
# test_msg = ["Request Upload File into DB", "Operation Ongoing...."]
|
724 |
+
|
725 |
+
# chat_history.append(test_msg)
|
726 |
+
for file in files:
|
727 |
+
chat_history2 = chat_history2 + [((file.name,), None)]
|
728 |
+
yield chat_history2
|
729 |
+
if os.environ["SYS_Upload_Enable"] == "1":
|
730 |
+
sumtext = SummarizeDoc()
|
731 |
+
test_msg = [None, sumtext]
|
732 |
+
chat_history2.append(test_msg)
|
733 |
+
yield chat_history2
|
734 |
+
|
735 |
+
|
736 |
class Logger:
|
737 |
def __init__(self, filename):
|
738 |
self.terminal = sys.stdout
|
|
|
1037 |
|
1038 |
with gr.Column() as main2:
|
1039 |
title = gr.Markdown("""# <center> STLA BABY - YOUR FRIENDLY GUIDE
|
1040 |
+
<center> v0.5: Powered by MECH Core Team"""),
|
1041 |
chatbot = gr.Chatbot()
|
1042 |
with gr.Row():
|
1043 |
inputtext = gr.Textbox(
|
|
|
1073 |
label= "OUTPUT",
|
1074 |
)
|
1075 |
upload_button = gr.UploadButton("✡️ INGEST DB", file_count="multiple", scale= 0, variant="secondary")
|
1076 |
+
upload_file_button = gr.UploadButton("📁 MAKE DOC SUMMARY", file_count="single", scale= 0, variant="secondary")
|
1077 |
retry_button = gr.Button("RETRY")
|
1078 |
clear_button = gr.Button("CLEAR")
|
1079 |
with gr.Accordion(
|