Tuchuanhuhuhu commited on
Commit
6c11728
·
1 Parent(s): f4e0fdd

调整UI,现在聊天框可以占据尽可能多的屏幕空间

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +27 -27
  2. custom.css +4 -0
  3. utils.py +8 -4
ChuanhuChatbot.py CHANGED
@@ -68,9 +68,7 @@ with gr.Blocks(css=customCSS) as demo:
68
  with gr.Row(scale=1).style(equal_height=True):
69
  with gr.Column(scale=5):
70
  with gr.Row(scale=1):
71
- chatbot = gr.Chatbot().style(
72
- height=600
73
- ) # .style(color_map=("#1D51EE", "#585A5B"))
74
  with gr.Row(scale=1):
75
  with gr.Column(scale=12):
76
  user_input = gr.Textbox(
@@ -100,27 +98,11 @@ with gr.Blocks(css=customCSS) as demo:
100
  model_select_dropdown = gr.Dropdown(
101
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
102
  )
103
- with gr.Accordion("参数", open=False):
104
- top_p = gr.Slider(
105
- minimum=-0,
106
- maximum=1.0,
107
- value=1.0,
108
- step=0.05,
109
- interactive=True,
110
- label="Top-p (nucleus sampling)",
111
- )
112
- temperature = gr.Slider(
113
- minimum=-0,
114
- maximum=2.0,
115
- value=1.0,
116
- step=0.1,
117
- interactive=True,
118
- label="Temperature",
119
- )
120
  use_streaming_checkbox = gr.Checkbox(
121
  label="实时传输回答", value=True, visible=enable_streaming_option
122
  )
123
  use_websearch_checkbox = gr.Checkbox(label="使用在线搜索", value=False)
 
124
 
125
  with gr.Tab(label="Prompt"):
126
  systemPromptTxt = gr.Textbox(
@@ -183,11 +165,29 @@ with gr.Blocks(css=customCSS) as demo:
183
  with gr.Row():
184
  with gr.Column():
185
  downloadFile = gr.File(interactive=True)
186
-
187
  with gr.Tab(label="高级"):
188
  default_btn = gr.Button("🔙 恢复默认设置")
189
  gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
190
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  apiurlTxt = gr.Textbox(
192
  show_label=True,
193
  placeholder=f"在这里输入API地址...",
@@ -337,27 +337,27 @@ with gr.Blocks(css=customCSS) as demo:
337
  [downloadFile, systemPromptTxt, history, chatbot],
338
  [saveFileName, systemPromptTxt, history, chatbot],
339
  )
340
-
341
  # Advanced
342
  default_btn.click(
343
  reset_default,
344
  [],
345
- [apiurlTxt, proxyTxt],
346
  show_progress=True
347
  )
348
  changeAPIURLBtn.click(
349
  change_api_url,
350
  [apiurlTxt],
351
- [],
352
  show_progress=True,
353
  )
354
  changeProxyBtn.click(
355
  change_proxy,
356
  [proxyTxt],
357
- [],
358
  show_progress=True,
359
  )
360
-
361
  logging.info(
362
  colorama.Back.GREEN
363
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
 
68
  with gr.Row(scale=1).style(equal_height=True):
69
  with gr.Column(scale=5):
70
  with gr.Row(scale=1):
71
+ chatbot = gr.Chatbot(elem_id="chuanhu_chatbot")
 
 
72
  with gr.Row(scale=1):
73
  with gr.Column(scale=12):
74
  user_input = gr.Textbox(
 
98
  model_select_dropdown = gr.Dropdown(
99
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
100
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  use_streaming_checkbox = gr.Checkbox(
102
  label="实时传输回答", value=True, visible=enable_streaming_option
103
  )
104
  use_websearch_checkbox = gr.Checkbox(label="使用在线搜索", value=False)
105
+ index_files = gr.File(label="上传索引文件", type="file", multiple=True)
106
 
107
  with gr.Tab(label="Prompt"):
108
  systemPromptTxt = gr.Textbox(
 
165
  with gr.Row():
166
  with gr.Column():
167
  downloadFile = gr.File(interactive=True)
168
+
169
  with gr.Tab(label="高级"):
170
  default_btn = gr.Button("🔙 恢复默认设置")
171
  gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
172
+
173
+ with gr.Accordion("参数", open=False):
174
+ top_p = gr.Slider(
175
+ minimum=-0,
176
+ maximum=1.0,
177
+ value=1.0,
178
+ step=0.05,
179
+ interactive=True,
180
+ label="Top-p (nucleus sampling)",
181
+ )
182
+ temperature = gr.Slider(
183
+ minimum=-0,
184
+ maximum=2.0,
185
+ value=1.0,
186
+ step=0.1,
187
+ interactive=True,
188
+ label="Temperature",
189
+ )
190
+
191
  apiurlTxt = gr.Textbox(
192
  show_label=True,
193
  placeholder=f"在这里输入API地址...",
 
337
  [downloadFile, systemPromptTxt, history, chatbot],
338
  [saveFileName, systemPromptTxt, history, chatbot],
339
  )
340
+
341
  # Advanced
342
  default_btn.click(
343
  reset_default,
344
  [],
345
+ [apiurlTxt, proxyTxt, status_display],
346
  show_progress=True
347
  )
348
  changeAPIURLBtn.click(
349
  change_api_url,
350
  [apiurlTxt],
351
+ [status_display],
352
  show_progress=True,
353
  )
354
  changeProxyBtn.click(
355
  change_proxy,
356
  [proxyTxt],
357
+ [status_display],
358
  show_progress=True,
359
  )
360
+
361
  logging.info(
362
  colorama.Back.GREEN
363
  + "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
custom.css CHANGED
@@ -131,3 +131,7 @@ pre code {
131
  * {
132
  transition: all 0.6s;
133
  }
 
 
 
 
 
131
  * {
132
  transition: all 0.6s;
133
  }
134
+
135
+ #chuanhu_chatbot {
136
+ height: 75vh;
137
+ }
utils.py CHANGED
@@ -648,13 +648,17 @@ def reset_default():
648
  API_URL = "https://api.openai.com/v1/chat/completions"
649
  os.environ.pop("HTTPS_PROXY", None)
650
  os.environ.pop("https_proxy", None)
651
- return gr.update(value=API_URL), gr.update(value="")
652
 
653
  def change_api_url(url):
654
- global API_URL
655
  API_URL = url
656
- logging.info(f"更改API地址为{url}")
 
 
657
 
658
  def change_proxy(proxy):
659
  os.environ["HTTPS_PROXY"] = proxy
660
- logging.info(f"更改代理为{proxy}")
 
 
 
648
  API_URL = "https://api.openai.com/v1/chat/completions"
649
  os.environ.pop("HTTPS_PROXY", None)
650
  os.environ.pop("https_proxy", None)
651
+ return gr.update(value=API_URL), gr.update(value=""), "API URL 和代理已重置"
652
 
653
  def change_api_url(url):
654
+ global API_URL
655
  API_URL = url
656
+ msg = f"API地址更改为了{url}"
657
+ logging.info(msg)
658
+ return msg
659
 
660
  def change_proxy(proxy):
661
  os.environ["HTTPS_PROXY"] = proxy
662
+ msg = f"代理更改为了{proxy}"
663
+ logging.info(msg)
664
+ return msg