Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
jinchat-server
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
aigc-pioneer
jinchat-server
Commits
0a4dd198
提交
0a4dd198
authored
5月 06, 2023
作者:
imClumsyPanda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update webui.py
上级
63453f23
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
12 行删除
+21
-12
webui.py
webui.py
+21
-12
没有找到文件。
webui.py
浏览文件 @
0a4dd198
...
@@ -8,17 +8,19 @@ import uuid
...
@@ -8,17 +8,19 @@ 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
):
return
lst_default
return
lst_default
lst
=
os
.
listdir
(
VS_ROOT_PATH
)
lst
=
os
.
listdir
(
VS_ROOT_PATH
)
if
not
lst
:
if
not
lst
:
return
lst_default
return
lst_default
lst
.
sort
(
reverse
=
True
)
lst
.
sort
(
reverse
=
True
)
return
lst
+
lst_default
return
lst
+
lst_default
vs_list
=
get_vs_list
()
vs_list
=
get_vs_list
()
embedding_model_dict_list
=
list
(
embedding_model_dict
.
keys
())
embedding_model_dict_list
=
list
(
embedding_model_dict
.
keys
())
...
@@ -29,6 +31,7 @@ local_doc_qa = LocalDocQA()
...
@@ -29,6 +31,7 @@ local_doc_qa = LocalDocQA()
logger
=
gr
.
CSVLogger
()
logger
=
gr
.
CSVLogger
()
username
=
uuid
.
uuid4
()
.
hex
username
=
uuid
.
uuid4
()
.
hex
def
get_answer
(
query
,
vs_path
,
history
,
mode
,
def
get_answer
(
query
,
vs_path
,
history
,
mode
,
streaming
:
bool
=
STREAMING
):
streaming
:
bool
=
STREAMING
):
if
mode
==
"知识库问答"
and
vs_path
:
if
mode
==
"知识库问答"
and
vs_path
:
...
@@ -52,7 +55,8 @@ def get_answer(query, vs_path, history, mode,
...
@@ -52,7 +55,8 @@ def get_answer(query, vs_path, history, mode,
history
[
-
1
][
-
1
]
=
resp
+
(
history
[
-
1
][
-
1
]
=
resp
+
(
"
\n\n
当前知识库为空,如需基于知识库进行问答,请先加载知识库后,再进行提问。"
if
mode
==
"知识库问答"
else
""
)
"
\n\n
当前知识库为空,如需基于知识库进行问答,请先加载知识库后,再进行提问。"
if
mode
==
"知识库问答"
else
""
)
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
:
...
@@ -78,8 +82,8 @@ def reinit_model(llm_model, embedding_model, llm_history_len, use_ptuning_v2, us
...
@@ -78,8 +82,8 @@ def reinit_model(llm_model, embedding_model, llm_history_len, use_ptuning_v2, us
embedding_model
=
embedding_model
,
embedding_model
=
embedding_model
,
llm_history_len
=
llm_history_len
,
llm_history_len
=
llm_history_len
,
use_ptuning_v2
=
use_ptuning_v2
,
use_ptuning_v2
=
use_ptuning_v2
,
use_lora
=
use_lora
,
use_lora
=
use_lora
,
top_k
=
top_k
,)
top_k
=
top_k
,
)
model_status
=
"""模型已成功重新加载,可以开始对话,或从右侧选择模式后开始对话"""
model_status
=
"""模型已成功重新加载,可以开始对话,或从右侧选择模式后开始对话"""
print
(
model_status
)
print
(
model_status
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -111,12 +115,14 @@ def get_vector_store(vs_id, files, history):
...
@@ -111,12 +115,14 @@ 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
else
:
else
:
file_status
=
f
"已加载知识库{vs_id},请开始提问"
file_status
=
f
"已加载知识库{vs_id},请开始提问"
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
True
),
os
.
path
.
join
(
VS_ROOT_PATH
,
vs_id
),
history
+
[[
None
,
file_status
]]
return
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
False
),
gr
.
update
(
visible
=
True
),
os
.
path
.
join
(
VS_ROOT_PATH
,
vs_id
),
history
+
[
[
None
,
file_status
]]
def
change_mode
(
mode
):
def
change_mode
(
mode
):
...
@@ -136,6 +142,7 @@ def add_vs_name(vs_name, vs_list, chatbot):
...
@@ -136,6 +142,7 @@ def add_vs_name(vs_name, vs_list, chatbot):
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_list
+
[
vs_name
],
value
=
vs_name
),
vs_list
+
[
vs_name
],
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;
...
@@ -166,7 +173,8 @@ model_status = init_model()
...
@@ -166,7 +173,8 @@ model_status = init_model()
default_path
=
os
.
path
.
join
(
VS_ROOT_PATH
,
vs_list
[
0
])
if
len
(
vs_list
)
>
1
else
""
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
(
model_status
),
gr
.
State
(
vs_list
)
vs_path
,
file_status
,
model_status
,
vs_list
=
gr
.
State
(
default_path
),
gr
.
State
(
""
),
gr
.
State
(
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
():
...
@@ -218,7 +226,7 @@ with gr.Blocks(css=block_css) as demo:
...
@@ -218,7 +226,7 @@ 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=)
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
])
# 将上传的文件保存到content文件夹下,并更新下拉框
# 将上传的文件保存到content文件夹下,并更新下拉框
load_file_button
.
click
(
get_vector_store
,
load_file_button
.
click
(
get_vector_store
,
...
@@ -265,7 +273,8 @@ with gr.Blocks(css=block_css) as demo:
...
@@ -265,7 +273,8 @@ with gr.Blocks(css=block_css) as demo:
load_model_button
=
gr
.
Button
(
"重新加载模型"
)
load_model_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
,
use_ptuning_v2
,
use_lora
,
top_k
,
chatbot
],
inputs
=
[
llm_model
,
embedding_model
,
llm_history_len
,
use_ptuning_v2
,
use_lora
,
top_k
,
chatbot
],
outputs
=
chatbot
outputs
=
chatbot
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论