Tuchuanhuhuhu commited on
Commit
4567189
1 Parent(s): e121fd7

适配gradio 3.32.0

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +1 -0
  2. assets/custom.css +7 -75
  3. modules/overwrites.py +11 -10
ChuanhuChatbot.py CHANGED
@@ -468,6 +468,7 @@ demo.title = i18n("川虎Chat 🚀")
468
  if __name__ == "__main__":
469
  reload_javascript()
470
  demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
 
471
  server_name=server_name,
472
  server_port=server_port,
473
  share=share,
 
468
  if __name__ == "__main__":
469
  reload_javascript()
470
  demo.queue(concurrency_count=CONCURRENT_COUNT).launch(
471
+ blocked_paths=["config.json"],
472
  server_name=server_name,
473
  server_port=server_port,
474
  share=share,
assets/custom.css CHANGED
@@ -418,83 +418,15 @@ pre code {
418
  display: block;
419
  overflow: auto;
420
  white-space: pre;
421
- background-color: hsla(0, 0%, 0%, 80%)!important;
422
- border-radius: 10px;
423
- padding: 1.4em 1.2em 0em 1.4em;
424
- margin: 0.6em 2em 1em 0.2em;
425
  color: #FFF;
426
- box-shadow: 6px 6px 16px hsla(0, 0%, 0%, 0.2);
427
  }
428
  .message pre {
429
  padding: 0 !important;
430
  }
431
- /* 代码高亮样式 */
432
- .highlight .hll { background-color: #49483e }
433
- .highlight .c { color: #75715e } /* Comment */
434
- .highlight .err { color: #960050; background-color: #1e0010 } /* Error */
435
- .highlight .k { color: #66d9ef } /* Keyword */
436
- .highlight .l { color: #ae81ff } /* Literal */
437
- .highlight .n { color: #f8f8f2 } /* Name */
438
- .highlight .o { color: #f92672 } /* Operator */
439
- .highlight .p { color: #f8f8f2 } /* Punctuation */
440
- .highlight .ch { color: #75715e } /* Comment.Hashbang */
441
- .highlight .cm { color: #75715e } /* Comment.Multiline */
442
- .highlight .cp { color: #75715e } /* Comment.Preproc */
443
- .highlight .cpf { color: #75715e } /* Comment.PreprocFile */
444
- .highlight .c1 { color: #75715e } /* Comment.Single */
445
- .highlight .cs { color: #75715e } /* Comment.Special */
446
- .highlight .gd { color: #f92672 } /* Generic.Deleted */
447
- .highlight .ge { font-style: italic } /* Generic.Emph */
448
- .highlight .gi { color: #a6e22e } /* Generic.Inserted */
449
- .highlight .gs { font-weight: bold } /* Generic.Strong */
450
- .highlight .gu { color: #75715e } /* Generic.Subheading */
451
- .highlight .kc { color: #66d9ef } /* Keyword.Constant */
452
- .highlight .kd { color: #66d9ef } /* Keyword.Declaration */
453
- .highlight .kn { color: #f92672 } /* Keyword.Namespace */
454
- .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
455
- .highlight .kr { color: #66d9ef } /* Keyword.Reserved */
456
- .highlight .kt { color: #66d9ef } /* Keyword.Type */
457
- .highlight .ld { color: #e6db74 } /* Literal.Date */
458
- .highlight .m { color: #ae81ff } /* Literal.Number */
459
- .highlight .s { color: #e6db74 } /* Literal.String */
460
- .highlight .na { color: #a6e22e } /* Name.Attribute */
461
- .highlight .nb { color: #f8f8f2 } /* Name.Builtin */
462
- .highlight .nc { color: #a6e22e } /* Name.Class */
463
- .highlight .no { color: #66d9ef } /* Name.Constant */
464
- .highlight .nd { color: #a6e22e } /* Name.Decorator */
465
- .highlight .ni { color: #f8f8f2 } /* Name.Entity */
466
- .highlight .ne { color: #a6e22e } /* Name.Exception */
467
- .highlight .nf { color: #a6e22e } /* Name.Function */
468
- .highlight .nl { color: #f8f8f2 } /* Name.Label */
469
- .highlight .nn { color: #f8f8f2 } /* Name.Namespace */
470
- .highlight .nx { color: #a6e22e } /* Name.Other */
471
- .highlight .py { color: #f8f8f2 } /* Name.Property */
472
- .highlight .nt { color: #f92672 } /* Name.Tag */
473
- .highlight .nv { color: #f8f8f2 } /* Name.Variable */
474
- .highlight .ow { color: #f92672 } /* Operator.Word */
475
- .highlight .w { color: #f8f8f2 } /* Text.Whitespace */
476
- .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
477
- .highlight .mf { color: #ae81ff } /* Literal.Number.Float */
478
- .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
479
- .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
480
- .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
481
- .highlight .sa { color: #e6db74 } /* Literal.String.Affix */
482
- .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
483
- .highlight .sc { color: #e6db74 } /* Literal.String.Char */
484
- .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
485
- .highlight .sd { color: #e6db74 } /* Literal.String.Doc */
486
- .highlight .s2 { color: #e6db74 } /* Literal.String.Double */
487
- .highlight .se { color: #ae81ff } /* Literal.String.Escape */
488
- .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
489
- .highlight .si { color: #e6db74 } /* Literal.String.Interpol */
490
- .highlight .sx { color: #e6db74 } /* Literal.String.Other */
491
- .highlight .sr { color: #e6db74 } /* Literal.String.Regex */
492
- .highlight .s1 { color: #e6db74 } /* Literal.String.Single */
493
- .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
494
- .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
495
- .highlight .fm { color: #a6e22e } /* Name.Function.Magic */
496
- .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
497
- .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
498
- .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
499
- .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
500
- .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
 
418
  display: block;
419
  overflow: auto;
420
  white-space: pre;
421
+ /* padding: 1.4em 1.2em 0em 1.4em; */
422
+ /* margin: 0.6em 2em 1em 0.2em; */
 
 
423
  color: #FFF;
 
424
  }
425
  .message pre {
426
  padding: 0 !important;
427
  }
428
+
429
+ .gradio-container-3-32-0 code[class*=language-], .gradio-container-3-32-0 pre[class*=language-] {
430
+ text-shadow: none;
431
+ background-color: var(--neutral-950) !important;
432
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
modules/overwrites.py CHANGED
@@ -4,6 +4,8 @@ import logging
4
  from typing import List, Tuple
5
  import mdtex2html
6
  from gradio_client import utils as client_utils
 
 
7
 
8
  from modules.presets import *
9
  from modules.index_func import *
@@ -40,14 +42,18 @@ def postprocess(
40
  return processed_messages
41
 
42
  def postprocess_chat_messages(
43
- self, chat_message: str | Tuple | List | None, message_type: str
44
- ) -> str | Dict | None:
45
  if chat_message is None:
46
  return None
47
  elif isinstance(chat_message, (tuple, list)):
48
- filepath = chat_message[0]
 
 
 
 
 
49
  mime_type = client_utils.get_mimetype(filepath)
50
- filepath = self.make_temp_copy_if_needed(filepath)
51
  return {
52
  "name": filepath,
53
  "mime_type": mime_type,
@@ -56,12 +62,7 @@ def postprocess_chat_messages(
56
  "is_file": True,
57
  }
58
  elif isinstance(chat_message, str):
59
- if message_type == "bot":
60
- if not detect_converted_mark(chat_message):
61
- chat_message = convert_mdtext(chat_message)
62
- elif message_type == "user":
63
- if not detect_converted_mark(chat_message):
64
- chat_message = convert_asis(chat_message)
65
  return chat_message
66
  else:
67
  raise ValueError(f"Invalid message for Chatbot component: {chat_message}")
 
4
  from typing import List, Tuple
5
  import mdtex2html
6
  from gradio_client import utils as client_utils
7
+ from gradio import utils
8
+ import inspect
9
 
10
  from modules.presets import *
11
  from modules.index_func import *
 
42
  return processed_messages
43
 
44
  def postprocess_chat_messages(
45
+ self, chat_message: str | tuple | list | None, role: str = "user"
46
+ ) -> str | dict | None:
47
  if chat_message is None:
48
  return None
49
  elif isinstance(chat_message, (tuple, list)):
50
+ file_uri = chat_message[0]
51
+ if utils.validate_url(file_uri):
52
+ filepath = file_uri
53
+ else:
54
+ filepath = self.make_temp_copy_if_needed(file_uri)
55
+
56
  mime_type = client_utils.get_mimetype(filepath)
 
57
  return {
58
  "name": filepath,
59
  "mime_type": mime_type,
 
62
  "is_file": True,
63
  }
64
  elif isinstance(chat_message, str):
65
+ chat_message = inspect.cleandoc(chat_message)
 
 
 
 
 
66
  return chat_message
67
  else:
68
  raise ValueError(f"Invalid message for Chatbot component: {chat_message}")