From 875dae64bfcffc5783e64d019940687aa130c59c Mon Sep 17 00:00:00 2001 From: zhoutongqing <128126751+zhoutongqing@users.noreply.github.com> Date: Tue, 30 May 2023 20:32:42 +0800 Subject: [PATCH] =?UTF-8?q?zhoutongqing:=E6=B7=BB=E5=8A=A0=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E6=9E=84=E5=BB=BA=E7=9F=A5=E8=AF=86=E5=BA=93=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20(#418)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: imClumsyPanda --- webui.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 5676dc2..799e08d 100644 --- a/webui.py +++ b/webui.py @@ -229,6 +229,22 @@ def add_vs_name(vs_name, chatbot): chatbot = chatbot + [[None, vs_status]] return gr.update(visible=True, choices=get_vs_list(), value=vs_name), gr.update( visible=False), gr.update(visible=False), gr.update(visible=True), chatbot + +# 自动化加载固定文件间中文件 +def init_set_vector_store(content_dir,vs_id,history): + try: + shutil.rmtree(VS_ROOT_PATH) + vs_path = os.path.join(VS_ROOT_PATH, vs_id) + sentence_size = gr.Number(value=SENTENCE_SIZE, precision=0, + label="文本入库分句长度限制", + interactive=True, visible=True) + vs_path, loaded_files = local_doc_qa.init_knowledge_vector_store(content_dir, vs_path, sentence_size) + model_status = """知识库构建成功""" + except Exception as e: + logger.error(e) + model_status = """知识库构建未成功""" + logger.info(model_status) + return history + [[None, model_status]] def refresh_vs_list(): @@ -470,7 +486,9 @@ with gr.Blocks(css=block_css, theme=gr.themes.Default(**default_theme_args)) as load_model_button.click(reinit_model, show_progress=True, inputs=[llm_model, embedding_model, llm_history_len, no_remote_model, use_ptuning_v2, use_lora, top_k, chatbot], outputs=chatbot) - + load_knowlege_button = gr.Button("重新构建知识库") + load_knowlege_button.click(init_set_vector_store, show_progress=True, + inputs=[UPLOAD_ROOT_PATH, select_vs,chatbot], outputs=chatbot) (demo .queue(concurrency_count=3) .launch(server_name='0.0.0.0',