JohnSmith9982 commited on
Commit
593e272
1 Parent(s): 44846b2

更新“删除最旧”按钮,适配暗色模式

Browse files
Files changed (4) hide show
  1. app.py +8 -1
  2. assets/custom.css +27 -8
  3. modules/llama_func.py +4 -2
  4. modules/utils.py +10 -0
app.py CHANGED
@@ -92,7 +92,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
92
  "🧹 新的对话",
93
  )
94
  retryBtn = gr.Button("🔄 重新生成")
95
- delLastBtn = gr.Button("🗑️ 删除一条对话")
 
96
  reduceTokenBtn = gr.Button("♻️ 总结对话")
97
 
98
  with gr.Column():
@@ -306,6 +307,12 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
306
  )
307
  retryBtn.click(**get_usage_args)
308
 
 
 
 
 
 
 
309
  delLastBtn.click(
310
  delete_last_conversation,
311
  [chatbot, history, token_count],
 
92
  "🧹 新的对话",
93
  )
94
  retryBtn = gr.Button("🔄 重新生成")
95
+ delFirstBtn = gr.Button("🗑️ 删除最旧对话")
96
+ delLastBtn = gr.Button("🗑️ 删除最新对话")
97
  reduceTokenBtn = gr.Button("♻️ 总结对话")
98
 
99
  with gr.Column():
 
307
  )
308
  retryBtn.click(**get_usage_args)
309
 
310
+ delFirstBtn.click(
311
+ delete_first_conversation,
312
+ [history, token_count],
313
+ [history, token_count, status_display],
314
+ )
315
+
316
  delLastBtn.click(
317
  delete_last_conversation,
318
  [chatbot, history, token_count],
assets/custom.css CHANGED
@@ -36,14 +36,33 @@ ol:not(.options), ul:not(.options) {
36
  }
37
 
38
  /* 亮色 */
39
- #chuanhu_chatbot {
40
- background-color: var(--chatbot-color-light) !important;
41
- }
42
- [data-testid = "bot"] {
43
- background-color: #FFFFFF !important;
44
- }
45
- [data-testid = "user"] {
46
- background-color: #95EC69 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
  /* 对话气泡 */
49
  [class *= "message"] {
 
36
  }
37
 
38
  /* 亮色 */
39
+ @media (prefers-color-scheme: light) {
40
+ #chuanhu_chatbot {
41
+ background-color: var(--chatbot-color-light) !important;
42
+ color: #000000 !important;
43
+ }
44
+ [data-testid = "bot"] {
45
+ background-color: #FFFFFF !important;
46
+ }
47
+ [data-testid = "user"] {
48
+ background-color: #95EC69 !important;
49
+ }
50
+ }
51
+ /* 暗色 */
52
+ @media (prefers-color-scheme: dark) {
53
+ #chuanhu_chatbot {
54
+ background-color: var(--chatbot-color-dark) !important;
55
+ color: #FFFFFF !important;
56
+ }
57
+ [data-testid = "bot"] {
58
+ background-color: #2C2C2C !important;
59
+ }
60
+ [data-testid = "user"] {
61
+ background-color: #26B561 !important;
62
+ }
63
+ body {
64
+ background-color: var(--neutral-950) !important;
65
+ }
66
  }
67
  /* 对话气泡 */
68
  [class *= "message"] {
modules/llama_func.py CHANGED
@@ -17,9 +17,11 @@ from modules.presets import *
17
  from modules.utils import *
18
 
19
  def get_index_name(file_src):
20
- index_name = ""
21
  for file in file_src:
22
- index_name += os.path.basename(file.name)
 
 
23
  index_name = sha1sum(index_name)
24
  return index_name
25
 
 
17
  from modules.utils import *
18
 
19
  def get_index_name(file_src):
20
+ index_name = []
21
  for file in file_src:
22
+ index_name.append(os.path.basename(file.name))
23
+ index_name = sorted(index_name)
24
+ index_name = "".join(index_name)
25
  index_name = sha1sum(index_name)
26
  return index_name
27
 
modules/utils.py CHANGED
@@ -153,6 +153,16 @@ def construct_assistant(text):
153
  def construct_token_message(token, stream=False):
154
  return f"Token 计数: {token}"
155
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  def delete_last_conversation(chatbot, history, previous_token_count):
158
  if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]:
 
153
  def construct_token_message(token, stream=False):
154
  return f"Token 计数: {token}"
155
 
156
+ def delete_first_conversation(history, previous_token_count):
157
+ if history:
158
+ del history[:2]
159
+ del previous_token_count[0]
160
+ return (
161
+ history,
162
+ previous_token_count,
163
+ construct_token_message(sum(previous_token_count)),
164
+ )
165
+
166
 
167
  def delete_last_conversation(chatbot, history, previous_token_count):
168
  if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]: