Fix: 将gradio版本升级至3.28.3,修复知识库下拉框change事件获取值不是当前选中值的bug。 (#261)
* webui优化:解决每次页面刷新后都需要重新选择知识库的问题,增加Flagging收集问答效果。 * Fix: 将gradio版本升级至3.28.3,修复知识库下拉框change事件获取值不是当前选中值的bug。 * solve webui confict --------- Co-authored-by: Bob Chang <bob.chang@amway.com> Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
This commit is contained in:
parent
12fa4a2bb7
commit
3111fb56bd
|
|
@ -9,7 +9,7 @@ icetk
|
||||||
cpm_kernels
|
cpm_kernels
|
||||||
faiss-cpu
|
faiss-cpu
|
||||||
accelerate
|
accelerate
|
||||||
gradio==3.24.1
|
gradio==3.28.3
|
||||||
fastapi
|
fastapi
|
||||||
uvicorn
|
uvicorn
|
||||||
peft
|
peft
|
||||||
|
|
|
||||||
28
webui.py
28
webui.py
|
|
@ -8,7 +8,6 @@ import uuid
|
||||||
|
|
||||||
nltk.data.path = [NLTK_DATA_PATH] + nltk.data.path
|
nltk.data.path = [NLTK_DATA_PATH] + nltk.data.path
|
||||||
|
|
||||||
|
|
||||||
def get_vs_list():
|
def get_vs_list():
|
||||||
lst_default = ["新建知识库"]
|
lst_default = ["新建知识库"]
|
||||||
if not os.path.exists(VS_ROOT_PATH):
|
if not os.path.exists(VS_ROOT_PATH):
|
||||||
|
|
@ -57,7 +56,6 @@ def get_answer(query, vs_path, history, mode,
|
||||||
yield history, ""
|
yield history, ""
|
||||||
logger.flag([query, vs_path, history, mode], username=username)
|
logger.flag([query, vs_path, history, mode], username=username)
|
||||||
|
|
||||||
|
|
||||||
def init_model():
|
def init_model():
|
||||||
try:
|
try:
|
||||||
local_doc_qa.init_cfg()
|
local_doc_qa.init_cfg()
|
||||||
|
|
@ -115,6 +113,7 @@ def get_vector_store(vs_id, files, history):
|
||||||
return vs_path, None, history + [[None, file_status]]
|
return vs_path, None, history + [[None, file_status]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def change_vs_name_input(vs_id, history):
|
def change_vs_name_input(vs_id, history):
|
||||||
if vs_id == "新建知识库":
|
if vs_id == "新建知识库":
|
||||||
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), None, history
|
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), None, history
|
||||||
|
|
@ -136,18 +135,16 @@ def add_vs_name(vs_name, vs_list, chatbot):
|
||||||
if vs_name in vs_list:
|
if vs_name in vs_list:
|
||||||
vs_status = "与已有知识库名称冲突,请重新选择其他名称后提交"
|
vs_status = "与已有知识库名称冲突,请重新选择其他名称后提交"
|
||||||
chatbot = chatbot + [[None, vs_status]]
|
chatbot = chatbot + [[None, vs_status]]
|
||||||
return gr.update(visible=True), vs_list, chatbot
|
return gr.update(visible=True), vs_list,gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), chatbot
|
||||||
else:
|
else:
|
||||||
vs_status = f"""已新增知识库"{vs_name}",将在上传文件并载入成功后进行存储。请在开始对话前,先完成文件上传。 """
|
vs_status = f"""已新增知识库"{vs_name}",将在上传文件并载入成功后进行存储。请在开始对话前,先完成文件上传。 """
|
||||||
chatbot = chatbot + [[None, vs_status]]
|
chatbot = chatbot + [[None, vs_status]]
|
||||||
return gr.update(visible=True, choices=vs_list + [vs_name], value=vs_name), vs_list + [vs_name], chatbot
|
return gr.update(visible=True, choices= [vs_name] + vs_list, value=vs_name), [vs_name]+vs_list, gr.update(visible=False), gr.update(visible=False), gr.update(visible=True),chatbot
|
||||||
|
|
||||||
|
|
||||||
block_css = """.importantButton {
|
block_css = """.importantButton {
|
||||||
background: linear-gradient(45deg, #7e0570,#5d1c99, #6e00ff) !important;
|
background: linear-gradient(45deg, #7e0570,#5d1c99, #6e00ff) !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.importantButton:hover {
|
.importantButton:hover {
|
||||||
background: linear-gradient(45deg, #ff00e0,#8500ff, #6e00ff) !important;
|
background: linear-gradient(45deg, #ff00e0,#8500ff, #6e00ff) !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
|
|
@ -155,9 +152,7 @@ block_css = """.importantButton {
|
||||||
|
|
||||||
webui_title = """
|
webui_title = """
|
||||||
# 🎉langchain-ChatGLM WebUI🎉
|
# 🎉langchain-ChatGLM WebUI🎉
|
||||||
|
|
||||||
👍 [https://github.com/imClumsyPanda/langchain-ChatGLM](https://github.com/imClumsyPanda/langchain-ChatGLM)
|
👍 [https://github.com/imClumsyPanda/langchain-ChatGLM](https://github.com/imClumsyPanda/langchain-ChatGLM)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
default_vs = vs_list[0] if len(vs_list) > 1 else "为空"
|
default_vs = vs_list[0] if len(vs_list) > 1 else "为空"
|
||||||
init_message = f"""欢迎使用 langchain-ChatGLM Web UI!
|
init_message = f"""欢迎使用 langchain-ChatGLM Web UI!
|
||||||
|
|
@ -175,6 +170,7 @@ default_path = os.path.join(VS_ROOT_PATH, vs_list[0]) if len(vs_list) > 1 else "
|
||||||
with gr.Blocks(css=block_css) as demo:
|
with gr.Blocks(css=block_css) as demo:
|
||||||
vs_path, file_status, model_status, vs_list = gr.State(default_path), gr.State(""), gr.State(
|
vs_path, file_status, model_status, vs_list = gr.State(default_path), gr.State(""), gr.State(
|
||||||
model_status), gr.State(vs_list)
|
model_status), gr.State(vs_list)
|
||||||
|
|
||||||
gr.Markdown(webui_title)
|
gr.Markdown(webui_title)
|
||||||
with gr.Tab("对话"):
|
with gr.Tab("对话"):
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
|
|
@ -200,13 +196,10 @@ with gr.Blocks(css=block_css) as demo:
|
||||||
)
|
)
|
||||||
vs_name = gr.Textbox(label="请输入新建知识库名称",
|
vs_name = gr.Textbox(label="请输入新建知识库名称",
|
||||||
lines=1,
|
lines=1,
|
||||||
interactive=True)
|
interactive=True,
|
||||||
vs_add = gr.Button(value="添加至知识库选项")
|
visible=True if default_path=="" else False)
|
||||||
vs_add.click(fn=add_vs_name,
|
vs_add = gr.Button(value="添加至知识库选项", visible=True if default_path=="" else False)
|
||||||
inputs=[vs_name, vs_list, chatbot],
|
file2vs = gr.Column(visible=False if default_path=="" else True)
|
||||||
outputs=[select_vs, vs_list, chatbot])
|
|
||||||
|
|
||||||
file2vs = gr.Column(visible=False)
|
|
||||||
with file2vs:
|
with file2vs:
|
||||||
# load_vs = gr.Button("加载知识库")
|
# load_vs = gr.Button("加载知识库")
|
||||||
gr.Markdown("向知识库中添加文件")
|
gr.Markdown("向知识库中添加文件")
|
||||||
|
|
@ -225,6 +218,9 @@ with gr.Blocks(css=block_css) as demo:
|
||||||
)
|
)
|
||||||
load_folder_button = gr.Button("上传文件夹并加载知识库")
|
load_folder_button = gr.Button("上传文件夹并加载知识库")
|
||||||
# load_vs.click(fn=)
|
# load_vs.click(fn=)
|
||||||
|
vs_add.click(fn=add_vs_name,
|
||||||
|
inputs=[vs_name, vs_list, chatbot],
|
||||||
|
outputs=[select_vs, vs_list,vs_name,vs_add, file2vs,chatbot])
|
||||||
select_vs.change(fn=change_vs_name_input,
|
select_vs.change(fn=change_vs_name_input,
|
||||||
inputs=[select_vs, chatbot],
|
inputs=[select_vs, chatbot],
|
||||||
outputs=[vs_name, vs_add, file2vs, vs_path, chatbot])
|
outputs=[vs_name, vs_add, file2vs, vs_path, chatbot])
|
||||||
|
|
@ -284,4 +280,4 @@ with gr.Blocks(css=block_css) as demo:
|
||||||
server_port=7860,
|
server_port=7860,
|
||||||
show_api=False,
|
show_api=False,
|
||||||
share=False,
|
share=False,
|
||||||
inbrowser=False))
|
inbrowser=False))
|
||||||
Loading…
Reference in New Issue