@@ -45,23 +45,23 @@ def main():
4545 proxy_info = check_proxy (proxies )
4646
4747 gr_L1 = lambda : gr .Row ().style ()
48- gr_L2 = lambda scale : gr .Column (scale = scale )
48+ gr_L2 = lambda scale , elem_id : gr .Column (scale = scale , elem_id = elem_id )
4949 if LAYOUT == "TOP-DOWN" :
5050 gr_L1 = lambda : DummyWith ()
51- gr_L2 = lambda scale : gr .Row ()
51+ gr_L2 = lambda scale , elem_id : gr .Row ()
5252 CHATBOT_HEIGHT /= 2
5353
5454 cancel_handles = []
5555 with gr .Blocks (title = "ChatGPT 学术优化" , theme = set_theme , analytics_enabled = False , css = advanced_css ) as demo :
5656 gr .HTML (title_html )
5757 cookies = gr .State (load_chat_cookies ())
5858 with gr_L1 ():
59- with gr_L2 (scale = 2 ):
60- chatbot = gr .Chatbot (label = f"当前模型:{ LLM_MODEL } " )
61- chatbot .style (height = CHATBOT_HEIGHT )
59+ with gr_L2 (scale = 2 , elem_id = "gpt-chat" ):
60+ chatbot = gr .Chatbot (label = f"当前模型:{ LLM_MODEL } " , elem_id = "gpt-chatbot" )
61+ if LAYOUT == "TOP-DOWN" : chatbot .style (height = CHATBOT_HEIGHT )
6262 history = gr .State ([])
63- with gr_L2 (scale = 1 ):
64- with gr .Accordion ("输入区" , open = True ) as area_input_primary :
63+ with gr_L2 (scale = 1 , elem_id = "gpt-panel" ):
64+ with gr .Accordion ("输入区" , open = True , elem_id = "input-panel" ) as area_input_primary :
6565 with gr .Row ():
6666 txt = gr .Textbox (show_label = False , placeholder = "Input question here." ).style (container = False )
6767 with gr .Row ():
@@ -71,14 +71,14 @@ def main():
7171 stopBtn = gr .Button ("停止" , variant = "secondary" ); stopBtn .style (size = "sm" )
7272 clearBtn = gr .Button ("清除" , variant = "secondary" , visible = False ); clearBtn .style (size = "sm" )
7373 with gr .Row ():
74- status = gr .Markdown (f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: { LLM_MODEL } \n { proxy_info } " )
75- with gr .Accordion ("基础功能区" , open = True ) as area_basic_fn :
74+ status = gr .Markdown (f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: { LLM_MODEL } \n { proxy_info } " , elem_id = "state-panel" )
75+ with gr .Accordion ("基础功能区" , open = True , elem_id = "basic-panel" ) as area_basic_fn :
7676 with gr .Row ():
7777 for k in functional :
7878 if ("Visible" in functional [k ]) and (not functional [k ]["Visible" ]): continue
7979 variant = functional [k ]["Color" ] if "Color" in functional [k ] else "secondary"
8080 functional [k ]["Button" ] = gr .Button (k , variant = variant )
81- with gr .Accordion ("函数插件区" , open = True ) as area_crazy_fn :
81+ with gr .Accordion ("函数插件区" , open = True , elem_id = "plugin-panel" ) as area_crazy_fn :
8282 with gr .Row ():
8383 gr .Markdown ("注意:以下“红颜色”标识的函数插件需从输入区读取路径作为参数." )
8484 with gr .Row ():
@@ -100,7 +100,7 @@ def main():
100100 with gr .Row ():
101101 with gr .Accordion ("点击展开“文件上传区”。上传本地文件可供红色函数插件调用。" , open = False ) as area_file_up :
102102 file_upload = gr .Files (label = "任何文件, 但推荐上传压缩文件(zip, tar)" , file_count = "multiple" )
103- with gr .Accordion ("更换模型 & SysPrompt & 交互界面布局" , open = (LAYOUT == "TOP-DOWN" )):
103+ with gr .Accordion ("更换模型 & SysPrompt & 交互界面布局" , open = (LAYOUT == "TOP-DOWN" ), elem_id = "interact-panel" ):
104104 system_prompt = gr .Textbox (show_label = True , placeholder = f"System Prompt" , label = "System prompt" , value = initial_prompt )
105105 top_p = gr .Slider (minimum = - 0 , maximum = 1.0 , value = 1.0 , step = 0.01 ,interactive = True , label = "Top-p (nucleus sampling)" ,)
106106 temperature = gr .Slider (minimum = - 0 , maximum = 2.0 , value = 1.0 , step = 0.01 , interactive = True , label = "Temperature" ,)
@@ -109,7 +109,7 @@ def main():
109109 md_dropdown = gr .Dropdown (AVAIL_LLM_MODELS , value = LLM_MODEL , label = "更换LLM模型/请求源" ).style (container = False )
110110
111111 gr .Markdown (description )
112- with gr .Accordion ("备选输入区" , open = True , visible = False ) as area_input_secondary :
112+ with gr .Accordion ("备选输入区" , open = True , visible = False , elem_id = "input-panel2" ) as area_input_secondary :
113113 with gr .Row ():
114114 txt2 = gr .Textbox (show_label = False , placeholder = "Input question here." , label = "输入区2" ).style (container = False )
115115 with gr .Row ():
@@ -176,16 +176,17 @@ def on_md_dropdown_changed(k):
176176 return {chatbot : gr .update (label = "当前模型:" + k )}
177177 md_dropdown .select (on_md_dropdown_changed , [md_dropdown ], [chatbot ] )
178178 # 随变按钮的回调函数注册
179- def route (k , * args , ** kwargs ):
179+ def route (request : gr . Request , k , * args , ** kwargs ):
180180 if k in [r"打开插件列表" , r"请先从插件列表中选择" ]: return
181- yield from ArgsGeneralWrapper (crazy_fns [k ]["Function" ])(* args , ** kwargs )
181+ yield from ArgsGeneralWrapper (crazy_fns [k ]["Function" ])(request , * args , ** kwargs )
182182 click_handle = switchy_bt .click (route ,[switchy_bt , * input_combo , gr .State (PORT )], output_combo )
183183 click_handle .then (on_report_generated , [cookies , file_upload , chatbot ], [cookies , file_upload , chatbot ])
184184 cancel_handles .append (click_handle )
185185 # 终止按钮的回调函数注册
186186 stopBtn .click (fn = None , inputs = None , outputs = None , cancels = cancel_handles )
187187 stopBtn2 .click (fn = None , inputs = None , outputs = None , cancels = cancel_handles )
188-
188+ demo .load (lambda : 0 , inputs = None , outputs = None , _js = '()=>{ChatBotHeight();}' )
189+
189190 # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
190191 def auto_opentab_delay ():
191192 import threading , webbrowser , time
0 commit comments