Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
6bb9d92
1
Parent(s):
0bfc663
解决发送后文本框里的字不立刻消失的问题
Browse files- ChuanhuChatbot.py +20 -15
- modules/utils.py +1 -0
ChuanhuChatbot.py
CHANGED
|
@@ -124,6 +124,7 @@ with gr.Blocks(
|
|
| 124 |
token_count = gr.State([])
|
| 125 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
| 126 |
user_api_key = gr.State(my_api_key)
|
|
|
|
| 127 |
outputing = gr.State(False)
|
| 128 |
topic = gr.State("未命名对话历史记录")
|
| 129 |
|
|
@@ -173,8 +174,8 @@ with gr.Blocks(
|
|
| 173 |
label="选择回复语言(针对搜索&索引功能)",
|
| 174 |
choices=REPLY_LANGUAGES,
|
| 175 |
multiselect=False,
|
| 176 |
-
value=REPLY_LANGUAGES[0]
|
| 177 |
-
|
| 178 |
index_files = gr.Files(label="上传索引文件", type="file", multiple=True)
|
| 179 |
|
| 180 |
with gr.Tab(label="Prompt"):
|
|
@@ -286,7 +287,7 @@ with gr.Blocks(
|
|
| 286 |
user_api_key,
|
| 287 |
systemPromptTxt,
|
| 288 |
history,
|
| 289 |
-
|
| 290 |
chatbot,
|
| 291 |
token_count,
|
| 292 |
top_p,
|
|
@@ -302,7 +303,10 @@ with gr.Blocks(
|
|
| 302 |
)
|
| 303 |
|
| 304 |
start_outputing_args = dict(
|
| 305 |
-
fn=start_outputing,
|
|
|
|
|
|
|
|
|
|
| 306 |
)
|
| 307 |
|
| 308 |
end_outputing_args = dict(
|
|
@@ -310,7 +314,11 @@ with gr.Blocks(
|
|
| 310 |
)
|
| 311 |
|
| 312 |
reset_textbox_args = dict(
|
| 313 |
-
fn=reset_textbox, inputs=[], outputs=[user_input]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
)
|
| 315 |
|
| 316 |
keyTxt.submit(submit_key, keyTxt, [user_api_key, status_display])
|
|
@@ -318,16 +326,13 @@ with gr.Blocks(
|
|
| 318 |
# Chatbot
|
| 319 |
cancelBtn.click(cancel_outputing, [], [])
|
| 320 |
|
| 321 |
-
user_input.submit(**
|
| 322 |
-
**
|
| 323 |
-
).then(**
|
| 324 |
-
|
| 325 |
-
)
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
).then(**reset_textbox_args).then(
|
| 329 |
-
**end_outputing_args
|
| 330 |
-
)
|
| 331 |
|
| 332 |
emptyBtn.click(
|
| 333 |
reset_state,
|
|
|
|
| 124 |
token_count = gr.State([])
|
| 125 |
promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
|
| 126 |
user_api_key = gr.State(my_api_key)
|
| 127 |
+
user_question = gr.State("")
|
| 128 |
outputing = gr.State(False)
|
| 129 |
topic = gr.State("未命名对话历史记录")
|
| 130 |
|
|
|
|
| 174 |
label="选择回复语言(针对搜索&索引功能)",
|
| 175 |
choices=REPLY_LANGUAGES,
|
| 176 |
multiselect=False,
|
| 177 |
+
value=REPLY_LANGUAGES[0],
|
| 178 |
+
)
|
| 179 |
index_files = gr.Files(label="上传索引文件", type="file", multiple=True)
|
| 180 |
|
| 181 |
with gr.Tab(label="Prompt"):
|
|
|
|
| 287 |
user_api_key,
|
| 288 |
systemPromptTxt,
|
| 289 |
history,
|
| 290 |
+
user_question,
|
| 291 |
chatbot,
|
| 292 |
token_count,
|
| 293 |
top_p,
|
|
|
|
| 303 |
)
|
| 304 |
|
| 305 |
start_outputing_args = dict(
|
| 306 |
+
fn=start_outputing,
|
| 307 |
+
inputs=[],
|
| 308 |
+
outputs=[submitBtn, cancelBtn],
|
| 309 |
+
show_progress=True,
|
| 310 |
)
|
| 311 |
|
| 312 |
end_outputing_args = dict(
|
|
|
|
| 314 |
)
|
| 315 |
|
| 316 |
reset_textbox_args = dict(
|
| 317 |
+
fn=reset_textbox, inputs=[], outputs=[user_input]
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
transfer_input_args = dict(
|
| 321 |
+
fn=lambda x: x, inputs=[user_input], outputs=[user_question], show_progress=True
|
| 322 |
)
|
| 323 |
|
| 324 |
keyTxt.submit(submit_key, keyTxt, [user_api_key, status_display])
|
|
|
|
| 326 |
# Chatbot
|
| 327 |
cancelBtn.click(cancel_outputing, [], [])
|
| 328 |
|
| 329 |
+
user_input.submit(**transfer_input_args).then(**reset_textbox_args).then(
|
| 330 |
+
**start_outputing_args
|
| 331 |
+
).then(**chatgpt_predict_args).then(**end_outputing_args)
|
| 332 |
+
|
| 333 |
+
submitBtn.click(**transfer_input_args).then(**reset_textbox_args).then(
|
| 334 |
+
**start_outputing_args
|
| 335 |
+
).then(**chatgpt_predict_args).then(**end_outputing_args)
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
emptyBtn.click(
|
| 338 |
reset_state,
|
modules/utils.py
CHANGED
|
@@ -398,6 +398,7 @@ def start_outputing():
|
|
| 398 |
logging.debug("显示取消按钮,隐藏发送按钮")
|
| 399 |
return gr.Button.update(visible=False), gr.Button.update(visible=True)
|
| 400 |
|
|
|
|
| 401 |
def end_outputing():
|
| 402 |
return (
|
| 403 |
gr.Button.update(visible=True),
|
|
|
|
| 398 |
logging.debug("显示取消按钮,隐藏发送按钮")
|
| 399 |
return gr.Button.update(visible=False), gr.Button.update(visible=True)
|
| 400 |
|
| 401 |
+
|
| 402 |
def end_outputing():
|
| 403 |
return (
|
| 404 |
gr.Button.update(visible=True),
|