Spaces:
Running
Running
Tuchuanhuhuhu
commited on
Commit
•
1805f08
1
Parent(s):
17c6524
增加“重置”按钮,提交之后自动清空输入框
Browse files- main.py +11 -3
- toolbox.py +4 -4
main.py
CHANGED
@@ -51,7 +51,9 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
51 |
with gr.Column(scale=12):
|
52 |
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
53 |
with gr.Column(scale=1):
|
54 |
-
|
|
|
|
|
55 |
with gr.Row():
|
56 |
from check_proxy import check_proxy
|
57 |
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:
|
|
76 |
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
77 |
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
78 |
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
for k in functional:
|
82 |
functional[k]["Button"].click(predict,
|
83 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
|
|
51 |
with gr.Column(scale=12):
|
52 |
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
53 |
with gr.Column(scale=1):
|
54 |
+
with gr.Row():
|
55 |
+
resetBtn = gr.Button("重置", variant="secondary")
|
56 |
+
submitBtn = gr.Button("提交", variant="primary")
|
57 |
with gr.Row():
|
58 |
from check_proxy import check_proxy
|
59 |
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
|
|
|
78 |
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
79 |
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
80 |
|
81 |
+
predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, systemPromptTxt], outputs=[chatbot, history, statusDisplay], show_progress=True)
|
82 |
+
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt])
|
83 |
+
|
84 |
+
txt.submit(**predict_args)
|
85 |
+
txt.submit(**empty_txt_args)
|
86 |
+
submitBtn.click(**predict_args)
|
87 |
+
submitBtn.click(**empty_txt_args)
|
88 |
+
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
|
89 |
for k in functional:
|
90 |
functional[k]["Button"].click(predict,
|
91 |
[txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
toolbox.py
CHANGED
@@ -14,7 +14,7 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
|
|
14 |
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
15 |
mutable = [None, '']
|
16 |
# multi-threading worker
|
17 |
-
def mt(i_say, history):
|
18 |
while True:
|
19 |
try:
|
20 |
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):
|
|
124 |
"""
|
125 |
将输入和输出解析为HTML格式。将y中最后一项的输入部分段落化,并将输出部分的Markdown和数学公式转换为HTML格式。
|
126 |
"""
|
127 |
-
if y is None: return []
|
128 |
i_ask, gpt_reply = y[-1]
|
129 |
i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
130 |
y[-1] = (
|
@@ -144,7 +144,7 @@ def find_free_port():
|
|
144 |
s.bind(('', 0))
|
145 |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
146 |
return s.getsockname()[1]
|
147 |
-
|
148 |
|
149 |
def extract_archive(file_path, dest_dir):
|
150 |
import zipfile
|
@@ -165,7 +165,7 @@ def extract_archive(file_path, dest_dir):
|
|
165 |
print("Successfully extracted tar archive to {}".format(dest_dir))
|
166 |
else:
|
167 |
return
|
168 |
-
|
169 |
def find_recent_files(directory):
|
170 |
"""
|
171 |
me: find files that is created with in one minutes under a directory with python, write a function
|
|
|
14 |
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
15 |
mutable = [None, '']
|
16 |
# multi-threading worker
|
17 |
+
def mt(i_say, history):
|
18 |
while True:
|
19 |
try:
|
20 |
mutable[0] = predict_no_ui(inputs=i_say, top_p=top_p, temperature=temperature, history=history)
|
|
|
124 |
"""
|
125 |
将输入和输出解析为HTML格式。将y中最后一项的输入部分段落化,并将输出部分的Markdown和数学公式转换为HTML格式。
|
126 |
"""
|
127 |
+
if y is None or y == []: return []
|
128 |
i_ask, gpt_reply = y[-1]
|
129 |
i_ask = text_divide_paragraph(i_ask) # 输入部分太自由,预处理一波
|
130 |
y[-1] = (
|
|
|
144 |
s.bind(('', 0))
|
145 |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
146 |
return s.getsockname()[1]
|
147 |
+
|
148 |
|
149 |
def extract_archive(file_path, dest_dir):
|
150 |
import zipfile
|
|
|
165 |
print("Successfully extracted tar archive to {}".format(dest_dir))
|
166 |
else:
|
167 |
return
|
168 |
+
|
169 |
def find_recent_files(directory):
|
170 |
"""
|
171 |
me: find files that is created with in one minutes under a directory with python, write a function
|