解决下拉插件不适配ipaddr的问题
This commit is contained in:
30
__main__.py
30
__main__.py
@ -108,7 +108,6 @@ class ChatBot(ChatBotFrame):
|
|||||||
with gr.Row():
|
with gr.Row():
|
||||||
self.pro_name_txt = gr.Textbox(show_label=False, placeholder='prompt功能名', ).style(
|
self.pro_name_txt = gr.Textbox(show_label=False, placeholder='prompt功能名', ).style(
|
||||||
container=False)
|
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')
|
self.pro_new_btn = gr.Button("保存Prompt", variant="primary").style(size='sm')
|
||||||
|
|
||||||
def signals_prompt_edit(self):
|
def signals_prompt_edit(self):
|
||||||
@ -135,9 +134,11 @@ class ChatBot(ChatBotFrame):
|
|||||||
with gr.Row():
|
with gr.Row():
|
||||||
self.submitBtn = gr.Button("提交", variant="primary")
|
self.submitBtn = gr.Button("提交", variant="primary")
|
||||||
with gr.Row():
|
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")
|
self.stopBtn = gr.Button("停止", variant="secondary").style(size="sm")
|
||||||
|
|
||||||
|
|
||||||
def draw_function_chat(self):
|
def draw_function_chat(self):
|
||||||
prompt_list, devs_document = get_conf('prompt_list', 'devs_document')
|
prompt_list, devs_document = get_conf('prompt_list', 'devs_document')
|
||||||
with gr.Tab('Function'):
|
with gr.Tab('Function'):
|
||||||
@ -190,8 +191,13 @@ class ChatBot(ChatBotFrame):
|
|||||||
not crazy_fns[k].get("AsButton", True)]
|
not crazy_fns[k].get("AsButton", True)]
|
||||||
self.dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(
|
self.dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(
|
||||||
container=False)
|
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")
|
self.switchy_bt = gr.Button(r"请先从插件列表中选择", variant="secondary")
|
||||||
|
|
||||||
|
|
||||||
def draw_setting_chat(self):
|
def draw_setting_chat(self):
|
||||||
switch_model = get_conf('switch_model')[0]
|
switch_model = get_conf('switch_model')[0]
|
||||||
with gr.Tab('Setting'):
|
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.txt.submit(**self.predict_args))
|
||||||
self.cancel_handles.append(self.submitBtn.click(**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):
|
def signals_function(self):
|
||||||
# 基础功能区的回调函数注册
|
# 基础功能区的回调函数注册
|
||||||
@ -277,15 +283,23 @@ class ChatBot(ChatBotFrame):
|
|||||||
|
|
||||||
# 函数插件-下拉菜单与随变按钮的互动
|
# 函数插件-下拉菜单与随变按钮的互动
|
||||||
def on_dropdown_changed(k):
|
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"
|
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])
|
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
|
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 = 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])
|
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"如果浏览器没有自动打开,请复制并转到以下URL:")
|
||||||
print(f"\t(亮色主题): http://localhost:{PORT}")
|
print(f"\t(亮色主题): http://localhost:{PORT}")
|
||||||
print(f"\t(暗色主题): {self.__url}/?__dark-theme=true")
|
print(f"\t(暗色主题): {self.__url}/?__theme=dark")
|
||||||
|
|
||||||
def open():
|
def open():
|
||||||
time.sleep(2) # 打开浏览器
|
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=open, name="open-browser", daemon=True).start()
|
||||||
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
||||||
|
|||||||
@ -50,7 +50,7 @@ def get_crazy_functions():
|
|||||||
},
|
},
|
||||||
"[测试功能] 解析Jupyter Notebook文件": {
|
"[测试功能] 解析Jupyter Notebook文件": {
|
||||||
"Color": "stop",
|
"Color": "stop",
|
||||||
"AsButton":False,
|
"AsButton": False,
|
||||||
"Function": HotReload(解析ipynb文件),
|
"Function": HotReload(解析ipynb文件),
|
||||||
"AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
|
"AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
|
||||||
"ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示
|
"ArgsReminder": "若输入0,则不解析notebook中的Markdown块", # 高级参数输入区的显示提示
|
||||||
@ -96,6 +96,7 @@ def get_crazy_functions():
|
|||||||
},
|
},
|
||||||
"读Tex论文写摘要": {
|
"读Tex论文写摘要": {
|
||||||
"Color": "stop", # 按钮颜色
|
"Color": "stop", # 按钮颜色
|
||||||
|
"AsButton": False, # 加入下拉菜单中
|
||||||
"Function": HotReload(读文章写摘要)
|
"Function": HotReload(读文章写摘要)
|
||||||
},
|
},
|
||||||
"Markdown/Readme英译中": {
|
"Markdown/Readme英译中": {
|
||||||
@ -249,7 +250,7 @@ def get_crazy_functions():
|
|||||||
function_plugins.update({
|
function_plugins.update({
|
||||||
"图片生成(先切换模型到openai或api2d)": {
|
"图片生成(先切换模型到openai或api2d)": {
|
||||||
"Color": "stop",
|
"Color": "stop",
|
||||||
"AsButton": False,
|
"AsButton": True,
|
||||||
"AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
|
"AdvancedArgs": True, # 调用时,唤起高级参数输入区(默认False)
|
||||||
"ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示
|
"ArgsReminder": "在这里输入分辨率, 如256x256(默认)", # 高级参数输入区的显示提示
|
||||||
"Function": HotReload(图片生成)
|
"Function": HotReload(图片生成)
|
||||||
|
|||||||
@ -51,8 +51,6 @@ def ArgsGeneralWrapper(f):
|
|||||||
chatbot, history, system_prompt, models, ipaddr: gr.Request, *args):
|
chatbot, history, system_prompt, models, ipaddr: gr.Request, *args):
|
||||||
""""""
|
""""""
|
||||||
# 引入一个有cookie的chatbot
|
# 引入一个有cookie的chatbot
|
||||||
if ipaddr: ipaddr = ipaddr.client.host
|
|
||||||
else: ipaddr = '127.0.0.1'
|
|
||||||
cookies.update({
|
cookies.update({
|
||||||
'top_p':top_p,
|
'top_p':top_p,
|
||||||
'temperature':temperature,
|
'temperature':temperature,
|
||||||
@ -63,7 +61,7 @@ def ArgsGeneralWrapper(f):
|
|||||||
'top_p':top_p,
|
'top_p':top_p,
|
||||||
'max_length': max_length,
|
'max_length': max_length,
|
||||||
'temperature': temperature,
|
'temperature': temperature,
|
||||||
'ipaddr': ipaddr
|
'ipaddr': ipaddr.client.host
|
||||||
}
|
}
|
||||||
plugin_kwargs = {
|
plugin_kwargs = {
|
||||||
# "advanced_arg": plugin_advanced_arg, 意义不明的功能,后续再解决冲突
|
# "advanced_arg": plugin_advanced_arg, 意义不明的功能,后续再解决冲突
|
||||||
@ -72,9 +70,9 @@ def ArgsGeneralWrapper(f):
|
|||||||
private_key = get_conf('private_key')[0]
|
private_key = get_conf('private_key')[0]
|
||||||
if private in models:
|
if private in models:
|
||||||
if chatbot == []:
|
if chatbot == []:
|
||||||
chatbot.append([f'隐私模式, 你的对话记录无法被他人检索 <p style="display:none;">\n{private_key}\n{ipaddr}\n</p>', None])
|
chatbot.append([f'隐私模式, 你的对话记录无法被他人检索 <p style="display:none;">\n{private_key}\n{ipaddr.client.host}\n</p>', None])
|
||||||
else:
|
else:
|
||||||
chatbot[0] = [f'隐私模式, 你的对话记录无法被他人检索 <p style="display:none;">\n{private_key}\n{ipaddr}\n</p>', None]
|
chatbot[0] = [f'隐私模式, 你的对话记录无法被他人检索 <p style="display:none;">\n{private_key}\n{ipaddr.client.host}\n</p>', None]
|
||||||
else:
|
else:
|
||||||
if chatbot == []:
|
if chatbot == []:
|
||||||
chatbot.append(['正常对话模式, 你接来下的对话将会被记录并且可以被所有人检索', None])
|
chatbot.append(['正常对话模式, 你接来下的对话将会被记录并且可以被所有人检索', None])
|
||||||
@ -84,6 +82,7 @@ def ArgsGeneralWrapper(f):
|
|||||||
chatbot_with_cookie.write_list(chatbot)
|
chatbot_with_cookie.write_list(chatbot)
|
||||||
txt_passon = txt
|
txt_passon = txt
|
||||||
if encrypt in models: txt_passon = func_box.encryption_str(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:
|
if txt_passon == '' and txt_passon == ' ' and len(args) > 1:
|
||||||
msgs = f'### {args[1]} Warning 输入框为空\n' \
|
msgs = f'### {args[1]} Warning 输入框为空\n' \
|
||||||
'tips: 使用基础功能时,请在输入区输入需要处理的文本内容'
|
'tips: 使用基础功能时,请在输入区输入需要处理的文本内容'
|
||||||
|
|||||||
Reference in New Issue
Block a user