Spaces:
Runtime error
Runtime error
清除按键
Browse files
main.py
CHANGED
@@ -68,6 +68,7 @@ def main():
|
|
68 |
with gr.Row():
|
69 |
resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
70 |
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
|
|
71 |
with gr.Row():
|
72 |
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}")
|
73 |
with gr.Accordion("基础功能区", open=True) as area_basic_fn:
|
@@ -99,7 +100,7 @@ def main():
|
|
99 |
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
100 |
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
101 |
max_length_sl = gr.Slider(minimum=256, maximum=4096, value=512, step=1, interactive=True, label="MaxLength",)
|
102 |
-
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
103 |
md_dropdown = gr.Dropdown(["gpt-3.5-turbo", "chatglm"], value=LLM_MODEL, label="").style(container=False)
|
104 |
|
105 |
gr.Markdown(description)
|
@@ -111,6 +112,7 @@ def main():
|
|
111 |
with gr.Row():
|
112 |
resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
113 |
stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
|
|
114 |
# 功能区显示开关与功能区的互动
|
115 |
def fn_area_visibility(a):
|
116 |
ret = {}
|
@@ -118,9 +120,11 @@ def main():
|
|
118 |
ret.update({area_crazy_fn: gr.update(visible=("函数插件区" in a))})
|
119 |
ret.update({area_input_primary: gr.update(visible=("底部输入区" not in a))})
|
120 |
ret.update({area_input_secondary: gr.update(visible=("底部输入区" in a))})
|
|
|
|
|
121 |
if "底部输入区" in a: ret.update({txt: gr.update(value="")})
|
122 |
return ret
|
123 |
-
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2] )
|
124 |
# 整理反复出现的控件句柄组合
|
125 |
input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt]
|
126 |
output_combo = [cookies, chatbot, history, status]
|
@@ -132,6 +136,8 @@ def main():
|
|
132 |
cancel_handles.append(submitBtn2.click(**predict_args))
|
133 |
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
134 |
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
|
|
|
|
135 |
# 基础功能区的回调函数注册
|
136 |
for k in functional:
|
137 |
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(k)], outputs=output_combo)
|
|
|
68 |
with gr.Row():
|
69 |
resetBtn = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
70 |
stopBtn = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
71 |
+
clearBtn = gr.Button("清除", variant="secondary", visible=False); clearBtn.style(size="sm")
|
72 |
with gr.Row():
|
73 |
status = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {proxy_info}")
|
74 |
with gr.Accordion("基础功能区", open=True) as area_basic_fn:
|
|
|
100 |
top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
|
101 |
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
102 |
max_length_sl = gr.Slider(minimum=256, maximum=4096, value=512, step=1, interactive=True, label="MaxLength",)
|
103 |
+
checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
|
104 |
md_dropdown = gr.Dropdown(["gpt-3.5-turbo", "chatglm"], value=LLM_MODEL, label="").style(container=False)
|
105 |
|
106 |
gr.Markdown(description)
|
|
|
112 |
with gr.Row():
|
113 |
resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn.style(size="sm")
|
114 |
stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn.style(size="sm")
|
115 |
+
clearBtn2 = gr.Button("清除", variant="secondary", visible=False); clearBtn.style(size="sm")
|
116 |
# 功能区显示开关与功能区的互动
|
117 |
def fn_area_visibility(a):
|
118 |
ret = {}
|
|
|
120 |
ret.update({area_crazy_fn: gr.update(visible=("函数插件区" in a))})
|
121 |
ret.update({area_input_primary: gr.update(visible=("底部输入区" not in a))})
|
122 |
ret.update({area_input_secondary: gr.update(visible=("底部输入区" in a))})
|
123 |
+
ret.update({clearBtn: gr.update(visible=("输入清除键" in a))})
|
124 |
+
ret.update({clearBtn2: gr.update(visible=("输入清除键" in a))})
|
125 |
if "底部输入区" in a: ret.update({txt: gr.update(value="")})
|
126 |
return ret
|
127 |
+
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2] )
|
128 |
# 整理反复出现的控件句柄组合
|
129 |
input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt]
|
130 |
output_combo = [cookies, chatbot, history, status]
|
|
|
136 |
cancel_handles.append(submitBtn2.click(**predict_args))
|
137 |
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
138 |
resetBtn2.click(lambda: ([], [], "已重置"), None, [chatbot, history, status])
|
139 |
+
clearBtn.click(lambda: ("",""), None, [txt, txt2])
|
140 |
+
clearBtn2.click(lambda: ("",""), None, [txt, txt2])
|
141 |
# 基础功能区的回调函数注册
|
142 |
for k in functional:
|
143 |
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(k)], outputs=output_combo)
|