From 61dc6f296facf833709cc5c9566bfd320a96f9fe Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Sun, 14 May 2023 21:23:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=8B=E6=8B=89=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E9=80=82=E9=85=8Dipaddr=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __main__.py | 30 ++++++++++++++++++++++-------- crazy_functional.py | 5 +++-- toolbox.py | 9 ++++----- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/__main__.py b/__main__.py index 756c9cf..2c400a9 100644 --- a/__main__.py +++ b/__main__.py @@ -108,7 +108,6 @@ class ChatBot(ChatBotFrame): with gr.Row(): self.pro_name_txt = gr.Textbox(show_label=False, placeholder='prompt功能名', ).style( container=False) - self.pro_clear_btn = gr.Button("重置Result", variant="primary").style(size='sm') self.pro_new_btn = gr.Button("保存Prompt", variant="primary").style(size='sm') def signals_prompt_edit(self): @@ -135,9 +134,11 @@ class ChatBot(ChatBotFrame): with gr.Row(): self.submitBtn = gr.Button("提交", variant="primary") with gr.Row(): - self.resetBtn = gr.Button("复制回答", variant="secondary").style(size="sm") + self.cpopyBtn = gr.Button("复制回答", variant="secondary").style(size="sm") + # self.resetBtn = gr.Button("重置", variant="secondary").style(size="sm") self.stopBtn = gr.Button("停止", variant="secondary").style(size="sm") + def draw_function_chat(self): prompt_list, devs_document = get_conf('prompt_list', 'devs_document') with gr.Tab('Function'): @@ -190,8 +191,13 @@ class ChatBot(ChatBotFrame): not crazy_fns[k].get("AsButton", True)] self.dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style( container=False) + with gr.Row(): + self.plugin_advanced_arg = gr.Textbox(show_label=True, label="高级参数输入区", visible=False, + placeholder="这里是特殊函数插件的高级参数输入区").style( + container=False) self.switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary") + def draw_setting_chat(self): switch_model = get_conf('switch_model')[0] with gr.Tab('Setting'): @@ -250,7 +256,7 @@ class ChatBot(ChatBotFrame): # 提交按钮、重置按钮 self.cancel_handles.append(self.txt.submit(**self.predict_args)) self.cancel_handles.append(self.submitBtn.click(**self.predict_args)) - self.resetBtn.click(fn=func_box.copy_result, inputs=[self.history], outputs=[self.status]) + self.cpopyBtn.click(fn=func_box.copy_result, inputs=[self.history], outputs=[self.status]) def signals_function(self): # 基础功能区的回调函数注册 @@ -277,15 +283,23 @@ class ChatBot(ChatBotFrame): # 函数插件-下拉菜单与随变按钮的互动 def on_dropdown_changed(k): + # variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary" + # return {self.switchy_bt: gr.update(value=k, variant=variant)} + variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary" - return {self.switchy_bt: gr.update(value=k, variant=variant)} + ret = {self.switchy_bt: gr.update(value=k, variant=variant)} + if crazy_fns[k].get("AdvancedArgs", False): # 是否唤起高级插件参数区 + ret.update({self.plugin_advanced_arg: gr.update(visible=True, label=f"插件[{k}]的高级参数说明:" + crazy_fns[k].get("ArgsReminder", [f"没有提供高级参数功能说明"]))}) + else: + ret.update({self.plugin_advanced_arg: gr.update(visible=False, label=f"插件[{k}]不需要高级参数。")}) + return ret self.dropdown.select(on_dropdown_changed, [self.dropdown], [self.switchy_bt]) # 随变按钮的回调函数注册 - def route(k, *args, **kwargs): + def route(k, ipaddr: gr.Request, *args, **kwargs): if k in [r"打开插件列表", r"请先从插件列表中选择"]: return - yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(*args, **kwargs) + yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(ipaddr=ipaddr, *args, **kwargs) self.click_handle = self.switchy_bt.click(route, [self.switchy_bt, *self.input_combo], self.output_combo) self.click_handle.then(on_report_generated, [self.file_upload, self.chatbot], [self.file_upload, self.chatbot]) @@ -313,11 +327,11 @@ class ChatBot(ChatBotFrame): print(f"如果浏览器没有自动打开,请复制并转到以下URL:") print(f"\t(亮色主题): http://localhost:{PORT}") - print(f"\t(暗色主题): {self.__url}/?__dark-theme=true") + print(f"\t(暗色主题): {self.__url}/?__theme=dark") def open(): time.sleep(2) # 打开浏览器 - webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true") + webbrowser.open_new_tab(f"http://localhost:{PORT}/?__theme=dark") threading.Thread(target=open, name="open-browser", daemon=True).start() threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start() diff --git a/crazy_functional.py b/crazy_functional.py index 91ac438..6d23012 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -50,7 +50,7 @@ def get_crazy_functions(): }, "[测试功能] 解析Jupyter Notebook文件": { "Color": "stop", - "AsButton":False, + "AsButton": False, "Function": HotReload(解析ipynb文件), "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) "ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示 @@ -96,6 +96,7 @@ def get_crazy_functions(): }, "读Tex论文写摘要": { "Color": "stop", # 按钮颜色 + "AsButton": False, # 加入下拉菜单中 "Function": HotReload(读文章写摘要) }, "Markdown/Readme英译中": { @@ -249,7 +250,7 @@ def get_crazy_functions(): function_plugins.update({ "图片生成(先切换模型到openai或api2d)": { "Color": "stop", - "AsButton": False, + "AsButton": True, "AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False) "ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示 "Function": HotReload(图片生成) diff --git a/toolbox.py b/toolbox.py index 782ae3c..53e052c 100644 --- a/toolbox.py +++ b/toolbox.py @@ -51,8 +51,6 @@ def ArgsGeneralWrapper(f): chatbot, history, system_prompt, models, ipaddr: gr.Request, *args): """""" # 引入一个有cookie的chatbot - if ipaddr: ipaddr = ipaddr.client.host - else: ipaddr = '127.0.0.1' cookies.update({ 'top_p':top_p, 'temperature':temperature, @@ -63,7 +61,7 @@ def ArgsGeneralWrapper(f): 'top_p':top_p, 'max_length': max_length, 'temperature': temperature, - 'ipaddr': ipaddr + 'ipaddr': ipaddr.client.host } plugin_kwargs = { # "advanced_arg": plugin_advanced_arg, 意义不明的功能,后续再解决冲突 @@ -72,9 +70,9 @@ def ArgsGeneralWrapper(f): private_key = get_conf('private_key')[0] if private in models: if chatbot == []: - chatbot.append([f'隐私模式, 你的对话记录无法被他人检索

\n{private_key}\n{ipaddr}\n

', None]) + chatbot.append([f'隐私模式, 你的对话记录无法被他人检索

\n{private_key}\n{ipaddr.client.host}\n

', None]) else: - chatbot[0] = [f'隐私模式, 你的对话记录无法被他人检索

\n{private_key}\n{ipaddr}\n

', None] + chatbot[0] = [f'隐私模式, 你的对话记录无法被他人检索

\n{private_key}\n{ipaddr.client.host}\n

', None] else: if chatbot == []: chatbot.append(['正常对话模式, 你接来下的对话将会被记录并且可以被所有人检索', None]) @@ -84,6 +82,7 @@ def ArgsGeneralWrapper(f): chatbot_with_cookie.write_list(chatbot) txt_passon = txt if encrypt in models: txt_passon = func_box.encryption_str(txt) + if args == (): args = (ipaddr.client.port, ) if txt_passon == '' and txt_passon == ' ' and len(args) > 1: msgs = f'### {args[1]} Warning 输入框为空\n' \ 'tips: 使用基础功能时,请在输入区输入需要处理的文本内容'