Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jinchat-server
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
aigc-pioneer
jinchat-server
Commits
12f54583
提交
12f54583
authored
4月 14, 2023
作者:
imClumsyPanda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update webui.py
上级
6bb9dccc
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
27 行删除
+32
-27
webui.py
webui.py
+32
-27
没有找到文件。
webui.py
浏览文件 @
12f54583
...
@@ -31,9 +31,12 @@ def upload_file(file):
...
@@ -31,9 +31,12 @@ def upload_file(file):
def
get_answer
(
query
,
vs_path
,
history
):
def
get_answer
(
query
,
vs_path
,
history
):
resp
,
history
=
local_doc_qa
.
get_knowledge_based_answer
(
if
vs_path
:
query
=
query
,
vs_path
=
vs_path
,
chat_history
=
history
)
resp
,
history
=
local_doc_qa
.
get_knowledge_based_answer
(
return
history
,
history
query
=
query
,
vs_path
=
vs_path
,
chat_history
=
history
)
else
:
history
=
history
+
[[
None
,
"请先加载文件后,再进行提问。"
]]
return
history
def
update_status
(
history
,
status
):
def
update_status
(
history
,
status
):
...
@@ -50,26 +53,30 @@ def init_model():
...
@@ -50,26 +53,30 @@ def init_model():
return
"""模型未成功加载,请重新选择后点击"加载模型"按钮"""
return
"""模型未成功加载,请重新选择后点击"加载模型"按钮"""
def
reinit_model
(
llm_model
,
embedding_model
,
llm_history_len
,
top_k
):
def
reinit_model
(
llm_model
,
embedding_model
,
llm_history_len
,
top_k
,
history
):
try
:
try
:
local_doc_qa
.
init_cfg
(
llm_model
=
llm_model
,
local_doc_qa
.
init_cfg
(
llm_model
=
llm_model
,
embedding_model
=
embedding_model
,
embedding_model
=
embedding_model
,
llm_history_len
=
llm_history_len
,
llm_history_len
=
llm_history_len
,
top_k
=
top_k
)
top_k
=
top_k
)
return
"""模型已成功重新加载,请选择文件后点击"加载文件"按钮"""
model_status
=
"""模型已成功重新加载,请选择文件后点击"加载文件"按钮"""
except
:
except
:
return
"""模型未成功重新加载,请重新选择后点击"加载模型"按钮"""
model_status
=
"""模型未成功重新加载,请重新选择后点击"加载模型"按钮"""
return
history
+
[[
None
,
model_status
]]
def
get_vector_store
(
filepath
):
def
get_vector_store
(
filepath
,
history
):
vs_path
=
local_doc_qa
.
init_knowledge_vector_store
([
"content/"
+
filepath
])
if
local_doc_qa
.
llm
and
local_doc_qa
.
llm
:
if
vs_path
:
vs_path
=
local_doc_qa
.
init_knowledge_vector_store
([
"content/"
+
filepath
])
file_status
=
"文件已成功加载,请开始提问"
if
vs_path
:
file_status
=
"文件已成功加载,请开始提问"
else
:
file_status
=
"文件未成功加载,请重新上传文件"
else
:
else
:
file_status
=
"
文件未成功加载,请重新上传
文件"
file_status
=
"
模型未完成加载,请先在加载模型后再导入
文件"
print
(
file_status
)
vs_path
=
None
return
vs_path
,
file_status
return
vs_path
,
history
+
[[
None
,
file_status
]]
block_css
=
""".importantButton {
block_css
=
""".importantButton {
...
@@ -98,7 +105,7 @@ init_message = """欢迎使用 langchain-ChatGLM Web UI,开始提问前,请
...
@@ -98,7 +105,7 @@ init_message = """欢迎使用 langchain-ChatGLM Web UI,开始提问前,请
model_status
=
init_model
()
model_status
=
init_model
()
with
gr
.
Blocks
(
css
=
block_css
)
as
demo
:
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
)
vs_path
,
file_status
,
model_status
=
gr
.
State
(
""
),
gr
.
State
(
""
),
gr
.
State
(
model_status
)
gr
.
Markdown
(
webui_title
)
gr
.
Markdown
(
webui_title
)
with
gr
.
Row
():
with
gr
.
Row
():
with
gr
.
Column
(
scale
=
2
):
with
gr
.
Column
(
scale
=
2
):
...
@@ -106,9 +113,9 @@ with gr.Blocks(css=block_css) as demo:
...
@@ -106,9 +113,9 @@ with gr.Blocks(css=block_css) as demo:
elem_id
=
"chat-box"
,
elem_id
=
"chat-box"
,
show_label
=
False
)
.
style
(
height
=
750
)
show_label
=
False
)
.
style
(
height
=
750
)
query
=
gr
.
Textbox
(
show_label
=
False
,
query
=
gr
.
Textbox
(
show_label
=
False
,
placeholder
=
"请
提问
"
,
placeholder
=
"请
输入提问内容,按回车进行提交
"
,
lines
=
1
,
#
lines=1,
value
=
"用200字总结一下"
#
value="用200字总结一下"
)
.
style
(
container
=
False
)
)
.
style
(
container
=
False
)
with
gr
.
Column
(
scale
=
1
):
with
gr
.
Column
(
scale
=
1
):
...
@@ -144,26 +151,24 @@ with gr.Blocks(css=block_css) as demo:
...
@@ -144,26 +151,24 @@ with gr.Blocks(css=block_css) as demo:
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_file_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
,
inputs
=
[
llm_model
,
embedding_model
,
llm_history_len
,
top_k
],
inputs
=
[
llm_model
,
embedding_model
,
llm_history_len
,
top_k
,
chatbot
],
outputs
=
model_status
outputs
=
chatbot
)
.
then
(
update_status
,
[
chatbot
,
model_status
],
chatbot
)
)
# 将上传的文件保存到content文件夹下,并更新下拉框
# 将上传的文件保存到content文件夹下,并更新下拉框
file
.
upload
(
upload_file
,
file
.
upload
(
upload_file
,
inputs
=
file
,
inputs
=
file
,
outputs
=
selectFile
)
outputs
=
selectFile
)
load_file_button
.
click
(
get_vector_store
,
load_file_button
.
click
(
get_vector_store
,
show_progress
=
True
,
show_progress
=
True
,
inputs
=
selectFile
,
inputs
=
[
selectFile
,
chatbot
],
outputs
=
[
vs_path
,
file_status
],
outputs
=
[
vs_path
,
chatbot
],
)
.
then
(
)
update_status
,
[
chatbot
,
file_status
],
chatbot
)
query
.
submit
(
get_answer
,
query
.
submit
(
get_answer
,
[
query
,
vs_path
,
chatbot
],
[
query
,
vs_path
,
chatbot
],
[
chatbot
,
history
],
[
chatbot
],
)
)
demo
.
queue
(
concurrency_count
=
3
)
.
launch
(
demo
.
queue
(
concurrency_count
=
3
)
.
launch
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论