增加“重置”按钮,提交之后自动清空输入框
This commit is contained in:
parent
17c6524b8d
commit
1805f081d3
14
main.py
14
main.py
@ -51,7 +51,9 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|||||||
with gr.Column(scale=12):
|
with gr.Column(scale=12):
|
||||||
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
||||||
with gr.Column(scale=1):
|
with gr.Column(scale=1):
|
||||||
submitBtn = gr.Button("提交", variant="primary")
|
with gr.Row():
|
||||||
|
resetBtn = gr.Button("重置", variant="secondary")
|
||||||
|
submitBtn = gr.Button("提交", variant="primary")
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
from check_proxy import check_proxy
|
from check_proxy import check_proxy
|
||||||
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
|
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
|
||||||
@ -76,8 +78,14 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|||||||
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
||||||
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
||||||
|
|
||||||
txt.submit(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay])
|
predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, systemPromptTxt], outputs=[chatbot, history, statusDisplay], show_progress=True)
|
||||||
submitBtn.click(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay], show_progress=True)
|
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt])
|
||||||
|
|
||||||
|
txt.submit(**predict_args)
|
||||||
|
txt.submit(**empty_txt_args)
|
||||||
|
submitBtn.click(**predict_args)
|
||||||
|
submitBtn.click(**empty_txt_args)
|
||||||
|
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
|
||||||
for k in functional:
|
for k in functional:
|
||||||
functional[k]["Button"].click(predict,
|
functional[k]["Button"].click(predict,
|
||||||
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
||||||
|
@ -14,7 +14,7 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
|
|||||||
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
||||||
mutable = [None, '']
|
mutable = [None, '']
|
||||||
# multi-threading worker
|
# multi-threading worker
|
||||||
def mt(i_say, history):
|
def mt(i_say, history):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
mutable[0] = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
mutable[0] = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
||||||
@ -124,7 +124,7 @@ def format_io(self, y):
|
|||||||
"""
|
"""
|
||||||
将输入和输出解析为HTML格式。将y中最后一项的输入部分段落化,并将输出部分的Markdown和数学公式转换为HTML格式。
|
将输入和输出解析为HTML格式。将y中最后一项的输入部分段落化,并将输出部分的Markdown和数学公式转换为HTML格式。
|
||||||
"""
|
"""
|
||||||
if y is None: return []
|
if y is None or y == []: return []
|
||||||
i_ask, gpt_reply = y[-1]
|
i_ask, gpt_reply = y[-1]
|
||||||
i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
||||||
y[-1] = (
|
y[-1] = (
|
||||||
@ -144,7 +144,7 @@ def find_free_port():
|
|||||||
s.bind(('', 0))
|
s.bind(('', 0))
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
return s.getsockname()[1]
|
return s.getsockname()[1]
|
||||||
|
|
||||||
|
|
||||||
def extract_archive(file_path, dest_dir):
|
def extract_archive(file_path, dest_dir):
|
||||||
import zipfile
|
import zipfile
|
||||||
@ -165,7 +165,7 @@ def extract_archive(file_path, dest_dir):
|
|||||||
print("Successfully extracted tar archive to {}".format(dest_dir))
|
print("Successfully extracted tar archive to {}".format(dest_dir))
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
def find_recent_files(directory):
|
def find_recent_files(directory):
|
||||||
"""
|
"""
|
||||||
me: find files that is created with in one minutes under a directory with python, write a function
|
me: find files that is created with in one minutes under a directory with python, write a function
|
||||||
|
Loading…
x
Reference in New Issue
Block a user