Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jinchat-server
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
aigc-pioneer
jinchat-server
Commits
5c349791
提交
5c349791
authored
4月 14, 2023
作者:
imClumsyPanda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update webui.py
上级
1be430be
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
55 行增加
和
51 行删除
+55
-51
webui.py
webui.py
+55
-51
没有找到文件。
webui.py
浏览文件 @
5c349791
...
@@ -36,12 +36,10 @@ def get_answer(query, vs_path, history):
...
@@ -36,12 +36,10 @@ def get_answer(query, vs_path, history):
return
history
,
history
return
history
,
history
def
get_model_status
(
history
):
def
update_status
(
history
,
status
):
return
history
+
[[
None
,
"模型已完成加载,请选择要加载的文档"
]]
history
=
history
+
[[
None
,
status
]]
print
(
status
)
return
history
def
get_file_status
(
history
):
return
history
+
[[
None
,
"文档已完成加载,请开始提问"
]]
def
init_model
():
def
init_model
():
...
@@ -53,22 +51,28 @@ def init_model():
...
@@ -53,22 +51,28 @@ def init_model():
def
reinit_model
(
llm_model
,
embedding_model
,
llm_history_len
,
top_k
):
def
reinit_model
(
llm_model
,
embedding_model
,
llm_history_len
,
top_k
):
local_doc_qa
.
init_cfg
(
llm_model
=
llm_model
,
try
:
embedding_model
=
embedding_model
,
local_doc_qa
.
init_cfg
(
llm_model
=
llm_model
,
llm_history_len
=
llm_history_len
,
embedding_model
=
embedding_model
,
top_k
=
top_k
),
llm_history_len
=
llm_history_len
,
top_k
=
top_k
)
return
"""模型已成功重新加载,请选择文件后点击"加载文件"按钮"""
except
:
return
"""模型未成功重新加载,请重新选择后点击"加载模型"按钮"""
def
get_vector_store
(
filepath
):
def
get_vector_store
(
filepath
):
local_doc_qa
.
init_knowledge_vector_store
(
"content/"
+
filepath
)
vs_path
=
local_doc_qa
.
init_knowledge_vector_store
([
"content/"
+
filepath
])
if
vs_path
:
file_status
=
"文件已成功加载,请开始提问"
else
:
file_status
=
"文件未成功加载,请重新上传文件"
print
(
file_status
)
return
vs_path
,
file_status
model_status
=
gr
.
State
()
block_css
=
""".importantButton {
history
=
gr
.
State
([])
vs_path
=
gr
.
State
()
model_status
=
init_model
()
with
gr
.
Blocks
(
css
=
"""
.importantButton {
background: linear-gradient(45deg, #7e0570,#5d1c99, #6e00ff) !important;
background: linear-gradient(45deg, #7e0570,#5d1c99, #6e00ff) !important;
border: none !important;
border: none !important;
}
}
...
@@ -76,24 +80,31 @@ with gr.Blocks(css="""
...
@@ -76,24 +80,31 @@ with gr.Blocks(css="""
.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;
}
}
"""
"""
)
as
demo
:
webui_title
=
"""
gr
.
Markdown
(
f
"""
# 🎉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)
"""
)
"""
with
gr
.
Row
():
with
gr
.
Column
(
scale
=
2
):
init_message
=
"""欢迎使用 langchain-ChatGLM Web UI,开始提问前,请依次如下 3 个步骤:
chatbot
=
gr
.
Chatbot
([[
None
,
"""欢迎使用 langchain-ChatGLM Web UI,开始提问前,请依次如下 3 个步骤:
1. 选择语言模型、Embedding 模型及相关参数后点击"重新加载模型",并等待加载完成提示
1. 选择语言模型、Embedding 模型及相关参数后点击"重新加载模型",并等待加载完成提示
2. 上传或选择已有文件作为本地知识文档输入后点击"重新加载文档",并等待加载完成提示
2. 上传或选择已有文件作为本地知识文档输入后点击"重新加载文档",并等待加载完成提示
3. 输入要提交的问题后,点击回车提交 """
],
[
None
,
str
(
model_status
)]],
3. 输入要提交的问题后,点击回车提交 """
model_status
=
init_model
()
with
gr
.
Blocks
(
css
=
block_css
)
as
demo
:
vs_path
,
history
,
file_status
,
model_status
=
gr
.
State
(
""
),
gr
.
State
([]),
gr
.
State
(
""
),
gr
.
State
(
model_status
)
gr
.
Markdown
(
webui_title
)
with
gr
.
Row
():
with
gr
.
Column
(
scale
=
2
):
chatbot
=
gr
.
Chatbot
([[
None
,
init_message
],
[
None
,
model_status
.
value
]],
elem_id
=
"chat-box"
,
elem_id
=
"chat-box"
,
show_label
=
False
)
.
style
(
height
=
60
0
)
show_label
=
False
)
.
style
(
height
=
75
0
)
query
=
gr
.
Textbox
(
show_label
=
False
,
query
=
gr
.
Textbox
(
show_label
=
False
,
placeholder
=
"请提问"
,
placeholder
=
"请提问"
,
lines
=
1
,
lines
=
1
,
...
@@ -103,7 +114,7 @@ with gr.Blocks(css="""
...
@@ -103,7 +114,7 @@ with gr.Blocks(css="""
with
gr
.
Column
(
scale
=
1
):
with
gr
.
Column
(
scale
=
1
):
llm_model
=
gr
.
Radio
(
llm_model_dict_list
,
llm_model
=
gr
.
Radio
(
llm_model_dict_list
,
label
=
"LLM 模型"
,
label
=
"LLM 模型"
,
value
=
"chatglm-6b"
,
value
=
LLM_MODEL
,
interactive
=
True
)
interactive
=
True
)
llm_history_len
=
gr
.
Slider
(
0
,
llm_history_len
=
gr
.
Slider
(
0
,
10
,
10
,
...
@@ -113,7 +124,7 @@ with gr.Blocks(css="""
...
@@ -113,7 +124,7 @@ with gr.Blocks(css="""
interactive
=
True
)
interactive
=
True
)
embedding_model
=
gr
.
Radio
(
embedding_model_dict_list
,
embedding_model
=
gr
.
Radio
(
embedding_model_dict_list
,
label
=
"Embedding 模型"
,
label
=
"Embedding 模型"
,
value
=
"text2vec"
,
value
=
EMBEDDING_MODEL
,
interactive
=
True
)
interactive
=
True
)
top_k
=
gr
.
Slider
(
1
,
top_k
=
gr
.
Slider
(
1
,
20
,
20
,
...
@@ -133,34 +144,27 @@ with gr.Blocks(css="""
...
@@ -133,34 +144,27 @@ with gr.Blocks(css="""
file
=
gr
.
File
(
label
=
"content file"
,
file
=
gr
.
File
(
label
=
"content file"
,
file_types
=
[
'.txt'
,
'.md'
,
'.docx'
,
'.pdf'
]
file_types
=
[
'.txt'
,
'.md'
,
'.docx'
,
'.pdf'
]
)
# .style(height=100)
)
# .style(height=100)
load_button
=
gr
.
Button
(
"重新加载文件"
)
load_
file_
button
=
gr
.
Button
(
"重新加载文件"
)
load_model_button
.
click
(
reinit_model
,
load_model_button
.
click
(
reinit_model
,
show_progress
=
True
,
show_progress
=
True
,
api_name
=
"init_cfg"
,
inputs
=
[
llm_model
,
embedding_model
,
llm_history_len
,
top_k
],
inputs
=
[
llm_model
,
embedding_model
,
llm_history_len
,
top_k
]
outputs
=
model_status
)
.
then
(
)
.
then
(
update_status
,
[
chatbot
,
model_status
],
chatbot
)
get_model_status
,
chatbot
,
chatbot
)
# 将上传的文件保存到content文件夹下,并更新下拉框
# 将上传的文件保存到content文件夹下,并更新下拉框
file
.
upload
(
upload_file
,
file
.
upload
(
upload_file
,
inputs
=
file
,
inputs
=
file
,
outputs
=
selectFile
)
outputs
=
selectFile
)
load_button
.
click
(
get_vector_store
,
load_file_button
.
click
(
get_vector_store
,
show_progress
=
True
,
show_progress
=
True
,
api_name
=
"init_knowledge_vector_store"
,
inputs
=
selectFile
,
inputs
=
selectFile
,
outputs
=
[
vs_path
,
file_status
],
outputs
=
vs_path
)
.
then
(
)
#.then(
update_status
,
[
chatbot
,
file_status
],
chatbot
# get_file_status,
)
# chatbot,
query
.
submit
(
get_answer
,
# chatbot,
[
query
,
vs_path
,
chatbot
],
# show_progress=True,
[
chatbot
,
history
],
# )
)
# query.submit(get_answer,
# [query, vs_path, chatbot],
# [chatbot, history],
# api_name="get_knowledge_based_answer"
# )
demo
.
queue
(
concurrency_count
=
3
)
.
launch
(
demo
.
queue
(
concurrency_count
=
3
)
.
launch
(
server_name
=
'0.0.0.0'
,
share
=
False
,
inbrowser
=
False
)
server_name
=
'0.0.0.0'
,
share
=
False
,
inbrowser
=
False
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论