3v324v23 commited on
Commit
753f9d5
1 Parent(s): 8c3a8a2

更清朗些的UI

Browse files
Files changed (1) hide show
  1. main.py +21 -20
main.py CHANGED
@@ -10,7 +10,7 @@ proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = \
10
 
11
  # 如果WEB_PORT是-1, 则随机选取WEB端口
12
  PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
13
- AUTHENTICATION = None if AUTHENTICATION == [] else AUTHENTICATION
14
 
15
  initial_prompt = "Serve me as a writing and programming assistant."
16
  title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
@@ -57,25 +57,27 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
57
  with gr.Row():
58
  from check_proxy import check_proxy
59
  statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
60
- with gr.Row():
61
- for k in functional:
62
- variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
63
- functional[k]["Button"] = gr.Button(k, variant=variant)
64
- with gr.Row():
65
- gr.Markdown("注意:以下“红颜色”标识的函数插件需从input区读取路径作为参数.")
66
- with gr.Row():
67
- for k in crazy_functional:
68
- variant = crazy_functional[k]["Color"] if "Color" in crazy_functional[k] else "secondary"
69
- crazy_functional[k]["Button"] = gr.Button(k, variant=variant)
70
- with gr.Row():
71
- gr.Markdown("上传本地文件,供上面的函数插件调用.")
72
- with gr.Row():
73
- file_upload = gr.Files(label='任何文件, 但推荐上传压缩文件(zip, tar)', file_count="multiple")
74
- system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt).style(container=True)
75
- with gr.Accordion("arguments", open=False):
 
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
  predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
80
  empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
81
 
@@ -105,8 +107,7 @@ def auto_opentab_delay():
105
  def open():
106
  time.sleep(2)
107
  webbrowser.open_new_tab(f'http://localhost:{PORT}')
108
- t = threading.Thread(target=open)
109
- t.daemon = True; t.start()
110
 
111
  auto_opentab_delay()
112
  demo.title = "ChatGPT 学术优化"
 
10
 
11
  # 如果WEB_PORT是-1, 则随机选取WEB端口
12
  PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
13
+ if not AUTHENTICATION: AUTHENTICATION = None
14
 
15
  initial_prompt = "Serve me as a writing and programming assistant."
16
  title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
 
57
  with gr.Row():
58
  from check_proxy import check_proxy
59
  statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行。当前模型: {LLM_MODEL} \n {check_proxy(proxies)}")
60
+ with gr.Accordion("基础功能区", open=True):
61
+ with gr.Row():
62
+ for k in functional:
63
+ variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
64
+ functional[k]["Button"] = gr.Button(k, variant=variant)
65
+ with gr.Accordion("函数插件区", open=True):
66
+ with gr.Row():
67
+ gr.Markdown("注意:以下“红颜色”标识的函数插件需从input区读取路径作为参数.")
68
+ with gr.Row():
69
+ for k in crazy_functional:
70
+ variant = crazy_functional[k]["Color"] if "Color" in crazy_functional[k] else "secondary"
71
+ crazy_functional[k]["Button"] = gr.Button(k, variant=variant)
72
+ with gr.Row():
73
+ with gr.Accordion("展开“文件上传区”。上传本地文件供“红颜色”的函数插件调用。", open=False):
74
+ file_upload = gr.Files(label='任何文件, 但推荐上传压缩文件(zip, tar)', file_count="multiple")
75
+ with gr.Accordion("展开SysPrompt & GPT参数 & 交互界面布局", open=False):
76
+ system_prompt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt)
77
  top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01,interactive=True, label="Top-p (nucleus sampling)",)
78
  temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
79
+ checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "文件上传区"], value=["USA", "Japan", "Pakistan"],
80
+ label="显示功能区")
81
  predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
82
  empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
83
 
 
107
  def open():
108
  time.sleep(2)
109
  webbrowser.open_new_tab(f'http://localhost:{PORT}')
110
+ threading.Thread(target=open, name="open-browser", daemon=True).start()
 
111
 
112
  auto_opentab_delay()
113
  demo.title = "ChatGPT 学术优化"