Keldos commited on
Commit
c06298e
1 Parent(s): ef91b66

dev: 适配gradio 3.41.2

Browse files

dev: 适配 gradio 3.41.0

- 修改avatar样式
- 修复gradio升级带来的代码块样式问题

config_example.json CHANGED
@@ -29,8 +29,8 @@
29
  "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史
30
  "check_update": true, //是否启用检查更新
31
  "default_model": "gpt-3.5-turbo", // 默认模型
32
- "bot_avatar": "default", // 机器人头像,可填写图片链接、Data URL (base64),或者"none"(不显示头像)
33
- "user_avatar": "default", // 用户头像,可填写图片链接、Data URL (base64),或者"none"(不显示头像)
34
 
35
  //== API 用量 ==
36
  "show_api_billing": false, //是否显示OpenAI API用量(启用需要填写sensitive_id)
 
29
  "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史
30
  "check_update": true, //是否启用检查更新
31
  "default_model": "gpt-3.5-turbo", // 默认模型
32
+ "bot_avatar": "default", // 机器人头像,可填写本地或网络图片链接,或者"none"(不显示头像)
33
+ "user_avatar": "default", // 用户头像,可填写本地或网络图片链接,或者"none"(不显示头像)
34
 
35
  //== API 用量 ==
36
  "show_api_billing": false, //是否显示OpenAI API用量(启用需要填写sensitive_id)
modules/config.py CHANGED
@@ -281,8 +281,8 @@ user_avatar = config.get("user_avatar", "default")
281
  if bot_avatar == "" or bot_avatar == "none" or bot_avatar is None:
282
  bot_avatar = None
283
  elif bot_avatar == "default":
284
- bot_avatar = "/web_assets/chatbot.png"
285
  if user_avatar == "" or user_avatar == "none" or user_avatar is None:
286
  user_avatar = None
287
  elif user_avatar == "default":
288
- user_avatar = "NEED TO ADD"
 
281
  if bot_avatar == "" or bot_avatar == "none" or bot_avatar is None:
282
  bot_avatar = None
283
  elif bot_avatar == "default":
284
+ bot_avatar = "web_assets/chatbot.png"
285
  if user_avatar == "" or user_avatar == "none" or user_avatar is None:
286
  user_avatar = None
287
  elif user_avatar == "default":
288
+ user_avatar = "web_assets/user.png"
modules/presets.py CHANGED
@@ -243,6 +243,7 @@ small_and_beautiful_theme = gr.themes.Soft(
243
  block_title_background_fill_dark="*primary_900",
244
  block_label_background_fill_dark="*primary_900",
245
  input_background_fill="#F6F6F6",
246
- chatbot_code_background_color="*neutral_950",
 
247
  chatbot_code_background_color_dark="*neutral_950",
248
  )
 
243
  block_title_background_fill_dark="*primary_900",
244
  block_label_background_fill_dark="*primary_900",
245
  input_background_fill="#F6F6F6",
246
+ # chatbot_code_background_color="*neutral_950",
247
+ # gradio 会把这个几个chatbot打头的变量应用到其他md渲染的地方,鬼晓得怎么想的。。。
248
  chatbot_code_background_color_dark="*neutral_950",
249
  )
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- gradio==3.40.0
2
- gradio_client==0.4.0
3
  pypinyin
4
  tiktoken
5
  socksio
 
1
+ gradio==3.41.2
2
+ gradio_client==0.5.0
3
  pypinyin
4
  tiktoken
5
  socksio
web_assets/javascript/chat-history.js CHANGED
@@ -25,6 +25,12 @@ function loadHistoryHtml() {
25
  return; // logged in, do nothing
26
  }
27
  if (!historyLoaded) {
 
 
 
 
 
 
28
  var fakeHistory = document.createElement('div');
29
  fakeHistory.classList.add('history-message');
30
  fakeHistory.innerHTML = tempDiv.innerHTML;
 
25
  return; // logged in, do nothing
26
  }
27
  if (!historyLoaded) {
28
+ // preprocess, gradio buttons in history lost their event listeners
29
+ var gradioCopyButtons = tempDiv.querySelectorAll('button.copy_code_button');
30
+ for (var i = 0; i < gradioCopyButtons.length; i++) {
31
+ gradioCopyButtons[i].parentNode.removeChild(gradioCopyButtons[i]);
32
+ }
33
+
34
  var fakeHistory = document.createElement('div');
35
  fakeHistory.classList.add('history-message');
36
  fakeHistory.innerHTML = tempDiv.innerHTML;
web_assets/stylesheet/ChuanhuChat.css CHANGED
@@ -37,6 +37,7 @@
37
  }
38
 
39
  #netsetting-warning hr {
 
40
  margin-bottom: 1em;
41
  }
42
 
 
37
  }
38
 
39
  #netsetting-warning hr {
40
+ margin-top: 0.5em;
41
  margin-bottom: 1em;
42
  }
43
 
web_assets/stylesheet/chatbot.css CHANGED
@@ -247,35 +247,12 @@ hr.append-display {
247
  note: find it better without transition animation...;
248
  } */
249
 
250
-
251
- /* .message-row {
252
- flex-direction: row;
253
- display: flex;
254
- gap: 8px;
255
- width: 100%;
256
- }
257
- .bot-message-row {
258
- justify-content: flex-start;
259
- }
260
- .user-message-row {
261
- justify-content: flex-end;
262
  }
263
- .chatbot-avatar {
264
- width: 32px;
265
- height: 32px;
266
  background-color: transparent;
267
  background-size: cover;
268
- border-radius: 5px !important;
269
- }
270
- .chatbot-avatar.bot-avatar {
271
- margin-left: 5px;
272
  }
273
- .chatbot-avatar.user-avatar {
274
- margin-right: 10px;
275
- }
276
- .chatbot-avatar img {
277
- border-radius: 5px !important;
278
- object-fit: cover;
279
- width: 100%;
280
- height: 100%;
281
- } */
 
247
  note: find it better without transition animation...;
248
  } */
249
 
250
+ img.avatar-image {
251
+ border-radius: 5px !important;
 
 
 
 
 
 
 
 
 
 
252
  }
253
+ .avatar-container {
254
+ width: 32px !important;
255
+ height: 32px !important;
256
  background-color: transparent;
257
  background-size: cover;
 
 
 
 
258
  }
 
 
 
 
 
 
 
 
 
web_assets/stylesheet/markdown.css CHANGED
@@ -4,52 +4,57 @@
4
  }
5
 
6
  /* 表格 */
7
- .message table {
8
  margin: 1em 0;
9
  border-collapse: collapse;
10
  empty-cells: show;
11
  }
12
- .message td, .message th {
13
  border: 1.2px solid var(--border-color-primary) !important;
14
  padding: 0.2em;
15
  }
16
- .message thead {
17
  background-color: rgba(175,184,193,0.2);
18
  }
19
- .message thead th {
20
  padding: .5em .2em;
21
  }
22
 
23
  /* 行内代码 */
24
- .message :not(pre) code {
25
  display: inline;
26
  white-space: break-spaces;
27
- font-family: var(--font-mono);
28
- border-radius: 6px;
29
  margin: 0 2px 0 2px;
30
- padding: .2em .4em .1em .4em;
31
- background-color: rgba(175,184,193,0.2);
 
 
32
  }
33
  /* 代码块 */
34
- .message pre,
35
- .message pre[class*=language-] {
36
  color: #fff;
37
  overflow-x: auto;
38
  overflow-y: hidden;
39
- margin: .8em 1em 1em 0em !important;
40
  padding: var(--spacing-xl) 1.2em !important;
41
  border-radius: var(--radius-lg) !important;
 
42
  }
43
- .message pre code,
44
- .message pre code[class*=language-] {
45
  color: #fff;
46
  padding: 0;
47
  margin: 0;
48
  background-color: unset;
49
  text-shadow: none;
50
  font-family: var(--font-mono);
 
 
 
 
51
  }
52
-
53
 
54
  /* 覆盖prism.css */
55
  .language-css .token.string,
 
4
  }
5
 
6
  /* 表格 */
7
+ .md-message table {
8
  margin: 1em 0;
9
  border-collapse: collapse;
10
  empty-cells: show;
11
  }
12
+ .md-message td, .message th {
13
  border: 1.2px solid var(--border-color-primary) !important;
14
  padding: 0.2em;
15
  }
16
+ .md-message thead {
17
  background-color: rgba(175,184,193,0.2);
18
  }
19
+ .md-message thead th {
20
  padding: .5em .2em;
21
  }
22
 
23
  /* 行内代码 */
24
+ .md-message :not(pre) > code {
25
  display: inline;
26
  white-space: break-spaces;
27
+ font-family: var(--font-mono) !important;
28
+ border-radius: 6px !important;
29
  margin: 0 2px 0 2px;
30
+ padding: .1em .4em .08em .4em !important;
31
+ background-color: rgba(175,184,193,0.2) !important;
32
+ border: none !important;
33
+ font-size: var(--text-md) !important;
34
  }
35
  /* 代码块 */
36
+ .md-message pre,
37
+ .md-message pre[class*=language-] {
38
  color: #fff;
39
  overflow-x: auto;
40
  overflow-y: hidden;
 
41
  padding: var(--spacing-xl) 1.2em !important;
42
  border-radius: var(--radius-lg) !important;
43
+ background: var(--neutral-950) !important;
44
  }
45
+ .md-message pre code,
46
+ .md-message pre code[class*=language-] {
47
  color: #fff;
48
  padding: 0;
49
  margin: 0;
50
  background-color: unset;
51
  text-shadow: none;
52
  font-family: var(--font-mono);
53
+ font-size: var(--text-md);
54
+ }
55
+ .md-message .code_wrap {
56
+ margin: .8em 1em 1em 0em;
57
  }
 
58
 
59
  /* 覆盖prism.css */
60
  .language-css .token.string,
web_assets/stylesheet/override-gradio.css CHANGED
@@ -15,14 +15,15 @@ footer {
15
  }
16
 
17
  /* 覆盖 gradio 丑陋的复制按钮样式 */
18
- .message pre button[title="copy"] {
19
- border-radius: 5px;
20
  transition: background-color .2s ease;
 
21
  }
22
- .message pre button[title="copy"]:hover {
23
  background-color: #333232;
24
  }
25
- .message pre button .check {
26
  color: #fff !important;
27
  background: var(--neutral-950) !important;
28
  }
 
15
  }
16
 
17
  /* 覆盖 gradio 丑陋的复制按钮样式 */
18
+ .message .code_wrap button[title="copy"] {
19
+ border-radius: 5px !important;
20
  transition: background-color .2s ease;
21
+ color: white;
22
  }
23
+ .message .code_wrap button[title="copy"]:hover {
24
  background-color: #333232;
25
  }
26
+ .message .code_wrap button .check {
27
  color: #fff !important;
28
  background: var(--neutral-950) !important;
29
  }
web_assets/user.png ADDED