Tuchuanhuhuhu commited on
Commit
6b15272
·
1 Parent(s): 7601bc3

优化代码结构

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +1 -37
  2. presets.py +36 -0
  3. utils.py +0 -6
ChuanhuChatbot.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import os
4
  import sys
5
  from utils import *
 
6
 
7
  my_api_key = "" # 在这里输入你的 API 密钥
8
  HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
@@ -39,43 +40,6 @@ else:
39
  if username != "" and password != "":
40
  authflag = True
41
 
42
- title = """<h1 align="center">川虎ChatGPT 🚀</h1>"""
43
- description = """<div align=center>
44
-
45
- 由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发
46
-
47
- 访问川虎ChatGPT的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本
48
-
49
- 此App使用 `gpt-3.5-turbo` 大语言模型
50
- </div>
51
- """
52
- customCSS = """
53
- code {
54
- display: inline;
55
- white-space: break-spaces;
56
- border-radius: 6px;
57
- margin: 0 2px 0 2px;
58
- padding: .2em .4em .1em .4em;
59
- background-color: rgba(175,184,193,0.2);
60
- }
61
- pre {
62
- display: block;
63
- white-space: pre;
64
- background-color: hsla(0, 0%, 0%, 72%);
65
- border: solid 5px var(--color-border-primary) !important;
66
- border-radius: 8px;
67
- padding: 0 1.2rem 1.2rem;
68
- margin-top: 1em !important;
69
- color: #FFF;
70
- box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
71
- }
72
- pre code, pre code code {
73
- background-color: transparent !important;
74
- margin: 0;
75
- padding: 0;
76
- }
77
- """
78
-
79
  with gr.Blocks(css=customCSS) as demo:
80
  gr.HTML(title)
81
  keyTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入你的OpenAI API-key...",
 
3
  import os
4
  import sys
5
  from utils import *
6
+ from presets import *
7
 
8
  my_api_key = "" # 在这里输入你的 API 密钥
9
  HIDE_MY_KEY = False # 如果你想在UI中隐藏你的 API 密钥,将此值设置为 True
 
40
  if username != "" and password != "":
41
  authflag = True
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  with gr.Blocks(css=customCSS) as demo:
44
  gr.HTML(title)
45
  keyTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入你的OpenAI API-key...",
presets.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title = """<h1 align="center">川虎ChatGPT 🚀</h1>"""
2
+ description = """<div align=center>
3
+
4
+ 由Bilibili [土川虎虎虎](https://space.bilibili.com/29125536) 和 [明昭MZhao](https://space.bilibili.com/24807452)开发
5
+
6
+ 访问川虎ChatGPT的 [GitHub项目](https://github.com/GaiZhenbiao/ChuanhuChatGPT) 下载最新版脚本
7
+
8
+ 此App使用 `gpt-3.5-turbo` 大语言模型
9
+ </div>
10
+ """
11
+ customCSS = """
12
+ code {
13
+ display: inline;
14
+ white-space: break-spaces;
15
+ border-radius: 6px;
16
+ margin: 0 2px 0 2px;
17
+ padding: .2em .4em .1em .4em;
18
+ background-color: rgba(175,184,193,0.2);
19
+ }
20
+ pre {
21
+ display: block;
22
+ white-space: pre;
23
+ background-color: hsla(0, 0%, 0%, 72%);
24
+ border: solid 5px var(--color-border-primary) !important;
25
+ border-radius: 8px;
26
+ padding: 0 1.2rem 1.2rem;
27
+ margin-top: 1em !important;
28
+ color: #FFF;
29
+ box-shadow: inset 0px 8px 16px hsla(0, 0%, 0%, .2)
30
+ }
31
+ pre code, pre code code {
32
+ background-color: transparent !important;
33
+ margin: 0;
34
+ padding: 0;
35
+ }
36
+ """
utils.py CHANGED
@@ -62,13 +62,7 @@ def parse_text(text):
62
  else:
63
  if i > 0:
64
  if count % 2 == 1:
65
- # line = line.replace("‘", "'")
66
- # line = line.replace("“", '"')
67
  line = line.replace("`", "\`")
68
- # line = line.replace("\"", "`\"`")
69
- # line = line.replace("\'", "`\'`")
70
- # line = line.replace("'``'", "''")
71
- # line = line.replace("&", "&amp;")
72
  line = line.replace("<", "&lt;")
73
  line = line.replace(">", "&gt;")
74
  line = line.replace(" ", "&nbsp;")
 
62
  else:
63
  if i > 0:
64
  if count % 2 == 1:
 
 
65
  line = line.replace("`", "\`")
 
 
 
 
66
  line = line.replace("<", "&lt;")
67
  line = line.replace(">", "&gt;")
68
  line = line.replace(" ", "&nbsp;")