Keldos commited on
Commit
98d8027
1 Parent(s): afdec9a

feat: 增加亮暗色切换按钮

Browse files
ChuanhuChatbot.py CHANGED
@@ -78,9 +78,9 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
78
  label="API-Key",
79
  )
80
  if multi_api_key:
81
- usageTxt = gr.Markdown("多账号模式已开启,无需输入key,可直接开始对话", elem_id="usage_display")
82
  else:
83
- usageTxt = gr.Markdown("**发送消息** 或 **提交key** 以显示额度", elem_id="usage_display")
84
  model_select_dropdown = gr.Dropdown(
85
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
86
  )
@@ -161,7 +161,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
161
  with gr.Tab(label="高级"):
162
  gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
163
  default_btn = gr.Button("🔙 恢复默认设置")
164
-
165
  with gr.Accordion("参数", open=False):
166
  top_p = gr.Slider(
167
  minimum=-0,
 
78
  label="API-Key",
79
  )
80
  if multi_api_key:
81
+ usageTxt = gr.Markdown("多账号模式已开启,无需输入key,可直接开始对话", elem_id="usage_display", elem_classes="insert_block")
82
  else:
83
+ usageTxt = gr.Markdown("**发送消息** 或 **提交key** 以显示额度", elem_id="usage_display", elem_classes="insert_block")
84
  model_select_dropdown = gr.Dropdown(
85
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
86
  )
 
161
  with gr.Tab(label="高级"):
162
  gr.Markdown("# ⚠️ 务必谨慎更改 ⚠️\n\n如果无法使用请恢复默认设置")
163
  default_btn = gr.Button("🔙 恢复默认设置")
164
+ gr.HTML(appearance_switcher, elem_classes="insert_block")
165
  with gr.Accordion("参数", open=False):
166
  top_p = gr.Slider(
167
  minimum=-0,
assets/custom.css CHANGED
@@ -73,9 +73,10 @@ footer {
73
  }
74
 
75
  /* usage_display */
76
- #usage_display {
77
  position: relative;
78
  margin: 0;
 
79
  box-shadow: var(--block-shadow);
80
  border-width: var(--block-border-width);
81
  border-color: var(--block-border-color);
@@ -87,7 +88,6 @@ footer {
87
  }
88
  #usage_display p, #usage_display span {
89
  margin: 0;
90
- padding: .5em 1em;
91
  font-size: .85em;
92
  color: var(--body-text-color-subdued);
93
  }
@@ -114,6 +114,44 @@ footer {
114
  line-height: 20px;
115
  }
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  #submit_btn, #cancel_btn {
118
  height: 42px !important;
119
  }
 
73
  }
74
 
75
  /* usage_display */
76
+ .insert_block {
77
  position: relative;
78
  margin: 0;
79
+ padding: .5em 1em;
80
  box-shadow: var(--block-shadow);
81
  border-width: var(--block-border-width);
82
  border-color: var(--block-border-color);
 
88
  }
89
  #usage_display p, #usage_display span {
90
  margin: 0;
 
91
  font-size: .85em;
92
  color: var(--body-text-color-subdued);
93
  }
 
114
  line-height: 20px;
115
  }
116
 
117
+ .apSwitch {
118
+ top: 2px;
119
+ display: inline-block;
120
+ height: 24px;
121
+ position: relative;
122
+ width: 48px;
123
+ border-radius: 12px;
124
+ }
125
+ .apSwitch input {
126
+ display: none !important;
127
+ }
128
+ .apSlider {
129
+ background-color: var(--block-label-background-fill);
130
+ bottom: 0;
131
+ cursor: pointer;
132
+ left: 0;
133
+ position: absolute;
134
+ right: 0;
135
+ top: 0;
136
+ transition: .4s;
137
+ font-size: 18px;
138
+ border-radius: 12px;
139
+ }
140
+ .apSlider::before {
141
+ bottom: -1.5px;
142
+ left: 1px;
143
+ position: absolute;
144
+ transition: .4s;
145
+ content: "🌞";
146
+ }
147
+ input:checked + .apSlider {
148
+ background-color: var(--block-label-background-fill);
149
+ }
150
+ input:checked + .apSlider::before {
151
+ transform: translateX(23px);
152
+ content:"🌚";
153
+ }
154
+
155
  #submit_btn, #cancel_btn {
156
  height: 42px !important;
157
  }
assets/custom.js CHANGED
@@ -13,6 +13,7 @@ var user_input_tb = null;
13
  var userInfoDiv = null;
14
  var appTitleDiv = null;
15
  var chatbot = null;
 
16
 
17
  var ga = document.getElementsByTagName("gradio-app");
18
  var targetNode = ga[0];
@@ -27,8 +28,9 @@ function gradioLoaded(mutations) {
27
  userInfoDiv = document.getElementById("user_info");
28
  appTitleDiv = document.getElementById("app_title");
29
  chatbot = document.querySelector('#chuanhu_chatbot');
 
30
 
31
- if (gradioContainer) { // gradioCainter 加载出来了没?
32
  adjustDarkMode();
33
  }
34
  if (user_input_tb) { // user_input_tb 加载出来了没?
@@ -158,7 +160,6 @@ function showOrHideUserInfo() {
158
  }
159
 
160
  function toggleDarkMode(isEnabled) {
161
- gradioContainer = document.querySelector(".gradio-container");
162
  if (isEnabled) {
163
  gradioContainer.classList.add("dark");
164
  document.body.style.setProperty("background-color", "var(--neutral-950)", "important");
@@ -169,12 +170,17 @@ function toggleDarkMode(isEnabled) {
169
  }
170
  function adjustDarkMode() {
171
  const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
 
172
  // 根据当前颜色模式设置初始状态
173
  toggleDarkMode(darkModeQuery.matches);
174
  // 监听颜色模式变化
175
  darkModeQuery.addEventListener("change", (e) => {
176
  toggleDarkMode(e.matches);
177
  });
 
 
 
 
178
  }
179
 
180
  function setChatbotHeight() {
 
13
  var userInfoDiv = null;
14
  var appTitleDiv = null;
15
  var chatbot = null;
16
+ var apSwitch = null;
17
 
18
  var ga = document.getElementsByTagName("gradio-app");
19
  var targetNode = ga[0];
 
28
  userInfoDiv = document.getElementById("user_info");
29
  appTitleDiv = document.getElementById("app_title");
30
  chatbot = document.querySelector('#chuanhu_chatbot');
31
+ apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
32
 
33
+ if (gradioContainer && apSwitch) { // gradioCainter 加载出来了没?
34
  adjustDarkMode();
35
  }
36
  if (user_input_tb) { // user_input_tb 加载出来了没?
 
160
  }
161
 
162
  function toggleDarkMode(isEnabled) {
 
163
  if (isEnabled) {
164
  gradioContainer.classList.add("dark");
165
  document.body.style.setProperty("background-color", "var(--neutral-950)", "important");
 
170
  }
171
  function adjustDarkMode() {
172
  const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
173
+
174
  // 根据当前颜色模式设置初始状态
175
  toggleDarkMode(darkModeQuery.matches);
176
  // 监听颜色模式变化
177
  darkModeQuery.addEventListener("change", (e) => {
178
  toggleDarkMode(e.matches);
179
  });
180
+ // apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
181
+ apSwitch.addEventListener("change", (e) => {
182
+ toggleDarkMode(e.target.checked);
183
+ });
184
  }
185
 
186
  function setChatbotHeight() {
modules/presets.py CHANGED
@@ -44,6 +44,15 @@ description = """\
44
 
45
  footer = """<div class="versions">{versions}</div>"""
46
 
 
 
 
 
 
 
 
 
 
47
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
48
 
49
  MODELS = [
 
44
 
45
  footer = """<div class="versions">{versions}</div>"""
46
 
47
+ appearance_switcher = """
48
+ <div style="display: flex; justify-content: space-between;">
49
+ <span style="margin-top: 4px !important;">切换亮暗色主题</span>
50
+ <span><label class="apSwitch" for="checkbox">
51
+ <input type="checkbox" id="checkbox">
52
+ <div class="apSlider"></div>
53
+ </label></span>
54
+ </div>
55
+ """
56
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
57
 
58
  MODELS = [