Tuchuanhuhuhu commited on
Commit
6c63da2
2 Parent(s): 2c4fed5 0d358c4

Merge branch 'main' of https://github.com/GaiZhenbiao/ChuanhuChatGPT

Browse files
CITATION.cff ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ cff-version: 1.2.0
2
+ title: ChuanhuChatGPT
3
+ message: >-
4
+ If you use this software, please cite it using these
5
+ metadata.
6
+ type: software
7
+ authors:
8
+ - given-names: Chuanhu
9
+ orcid: https://orcid.org/0000-0001-8954-8598
10
+ - given-names: MZhao
11
+ orcid: https://orcid.org/0000-0003-2298-6213
12
+ - given-names: Keldos
13
+ orcid: https://orcid.org/0009-0005-0357-272X
14
+ repository-code: 'https://github.com/GaiZhenbiao/ChuanhuChatGPT'
15
+ url: 'https://github.com/GaiZhenbiao/ChuanhuChatGPT'
16
+ abstract: Provided a light and easy to use interface for ChatGPT API
17
+ license: GPL-3.0
18
+ commit: bd0034c37e5af6a90bd9c2f7dd073f6cd27c61af
19
+ version: '20230405'
20
+ date-released: '2023-04-05'
ChuanhuChatbot.py CHANGED
@@ -30,10 +30,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
30
  topic = gr.State("未命名对话历史记录")
31
 
32
  with gr.Row():
33
- with gr.Column():
34
- gr.HTML(title)
35
- user_info = gr.Markdown(value="", elem_id="user_info")
36
  status_display = gr.Markdown(get_geoip(), elem_id="status_display")
 
 
37
 
38
  # https://github.com/gradio-app/gradio/pull/3296
39
  def create_greeting(request: gr.Request):
@@ -49,14 +49,14 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
49
  with gr.Row():
50
  chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
51
  with gr.Row():
52
- with gr.Column(scale=12):
53
  user_input = gr.Textbox(
54
  elem_id="user_input_tb",
55
  show_label=False, placeholder="在这里输入"
56
  ).style(container=False)
57
- with gr.Column(min_width=70, scale=1):
58
- submitBtn = gr.Button("发送", variant="primary")
59
- cancelBtn = gr.Button("取消", variant="secondary", visible=False)
60
  with gr.Row():
61
  emptyBtn = gr.Button(
62
  "🧹 新的对话",
 
30
  topic = gr.State("未命名对话历史记录")
31
 
32
  with gr.Row():
33
+ gr.HTML(title, elem_id="app_title")
 
 
34
  status_display = gr.Markdown(get_geoip(), elem_id="status_display")
35
+ with gr.Row(elem_id="float_display"):
36
+ user_info = gr.Markdown(value="getting user info...", elem_id="user_info")
37
 
38
  # https://github.com/gradio-app/gradio/pull/3296
39
  def create_greeting(request: gr.Request):
 
49
  with gr.Row():
50
  chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
51
  with gr.Row():
52
+ with gr.Column(min_width=225, scale=12):
53
  user_input = gr.Textbox(
54
  elem_id="user_input_tb",
55
  show_label=False, placeholder="在这里输入"
56
  ).style(container=False)
57
+ with gr.Column(min_width=42, scale=1):
58
+ submitBtn = gr.Button(value="", variant="primary", elem_id="submit_btn")
59
+ cancelBtn = gr.Button(value="", variant="secondary", visible=False, elem_id="cancel_btn")
60
  with gr.Row():
61
  emptyBtn = gr.Button(
62
  "🧹 新的对话",
assets/custom.css CHANGED
@@ -3,14 +3,18 @@
3
  --chatbot-color-dark: #121111;
4
  }
5
 
 
 
 
 
6
  /* 覆盖gradio的页脚信息QAQ */
7
  footer {
8
  display: none !important;
9
  }
10
- #footer{
11
  text-align: center;
12
  }
13
- #footer div{
14
  display: inline-block;
15
  }
16
  #footer .versions{
@@ -18,16 +22,34 @@ footer {
18
  opacity: 0.85;
19
  }
20
 
21
- /* user_info */
 
 
 
 
22
  #user_info {
23
  white-space: nowrap;
24
- margin-top: -1.3em !important;
25
- padding-left: 112px !important;
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
  #user_info p {
28
- font-size: .85em;
29
- font-family: monospace;
30
- color: var(--body-text-color-subdued);
 
 
 
31
  }
32
 
33
  /* status_display */
@@ -74,7 +96,7 @@ footer {
74
  overflow: hidden;
75
  }
76
  .progress {
77
- background-color: var(--block-title-background-fill);;
78
  height: 100%;
79
  border-radius: 10px;
80
  text-align: right;
@@ -88,6 +110,18 @@ footer {
88
  padding-right: 10px;
89
  line-height: 20px;
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
91
  /* list */
92
  ol:not(.options), ul:not(.options) {
93
  padding-inline-start: 2em !important;
@@ -139,6 +173,12 @@ ol:not(.options), ul:not(.options) {
139
  #chuanhu_chatbot .wrap {
140
  max-height: calc(100vh - 140px - var(--line-sm)*1rem - 2*var(--block-label-margin) );
141
  }
 
 
 
 
 
 
142
  }
143
  /* 对话气泡 */
144
  [class *= "message"] {
 
3
  --chatbot-color-dark: #121111;
4
  }
5
 
6
+ #app_title {
7
+ margin-top: 6px;
8
+ white-space: nowrap;
9
+ }
10
  /* 覆盖gradio的页脚信息QAQ */
11
  footer {
12
  display: none !important;
13
  }
14
+ #footer {
15
  text-align: center;
16
  }
17
+ #footer div {
18
  display: inline-block;
19
  }
20
  #footer .versions{
 
22
  opacity: 0.85;
23
  }
24
 
25
+ #float_display {
26
+ position: absolute;
27
+ max-height: 30px;
28
+ }
29
+ /* user_info */
30
  #user_info {
31
  white-space: nowrap;
32
+ position: absolute; left: 8em; top: .2em;
33
+ z-index: var(--layer-2);
34
+ box-shadow: var(--block-shadow);
35
+ border: none; border-radius: var(--block-label-radius);
36
+ background: var(--color-accent);
37
+ padding: var(--block-label-padding);
38
+ font-size: var(--block-label-text-size); line-height: var(--line-sm);
39
+ width: auto; min-height: 30px!important;
40
+ opacity: 1;
41
+ transition: opacity 0.3s ease-in-out;
42
+ }
43
+ #user_info .wrap {
44
+ opacity: 0;
45
  }
46
  #user_info p {
47
+ color: white;
48
+ font-weight: var(--block-label-text-weight);
49
+ }
50
+ #user_info.hideK {
51
+ opacity: 0;
52
+ transition: opacity 1s ease-in-out;
53
  }
54
 
55
  /* status_display */
 
96
  overflow: hidden;
97
  }
98
  .progress {
99
+ background-color: var(--block-title-background-fill);
100
  height: 100%;
101
  border-radius: 10px;
102
  text-align: right;
 
110
  padding-right: 10px;
111
  line-height: 20px;
112
  }
113
+
114
+ #submit_btn, #cancel_btn {
115
+ height: 42px !important;
116
+ }
117
+ #submit_btn::before {
118
+ content: url("data:image/svg+xml, %3Csvg width='21px' height='20px' viewBox='0 0 21 20' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E %3Cg id='page' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E %3Cg id='send' transform='translate(0.435849, 0.088463)' fill='%23FFFFFF' fill-rule='nonzero'%3E %3Cpath d='M0.579148261,0.0428666046 C0.301105539,-0.0961547561 -0.036517765,0.122307382 0.0032026237,0.420210298 L1.4927172,18.1553639 C1.5125774,18.4334066 1.79062012,18.5922882 2.04880264,18.4929872 L8.24518329,15.8913017 L11.6412765,19.7441794 C11.8597387,19.9825018 12.2370824,19.8832008 12.3165231,19.5852979 L13.9450591,13.4882182 L19.7839562,11.0255541 C20.0619989,10.8865327 20.0818591,10.4694687 19.7839562,10.3105871 L0.579148261,0.0428666046 Z M11.6138902,17.0883151 L9.85385903,14.7195502 L0.718169621,0.618812241 L12.69945,12.9346347 L11.6138902,17.0883151 Z' id='shape'%3E%3C/path%3E %3C/g%3E %3C/g%3E %3C/svg%3E");
119
+ height: 21px;
120
+ }
121
+ #cancel_btn::before {
122
+ content: url("data:image/svg+xml,%3Csvg width='21px' height='21px' viewBox='0 0 21 21' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E %3Cg id='pg' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E %3Cpath d='M10.2072007,20.088463 C11.5727865,20.088463 12.8594566,19.8259823 14.067211,19.3010209 C15.2749653,18.7760595 16.3386126,18.0538087 17.2581528,17.1342685 C18.177693,16.2147282 18.8982283,15.1527965 19.4197586,13.9484733 C19.9412889,12.7441501 20.202054,11.4557644 20.202054,10.0833163 C20.202054,8.71773046 19.9395733,7.43106036 19.4146119,6.22330603 C18.8896505,5.01555169 18.1673997,3.95018885 17.2478595,3.0272175 C16.3283192,2.10424615 15.2646719,1.3837109 14.0569176,0.865611739 C12.8491633,0.34751258 11.5624932,0.088463 10.1969073,0.088463 C8.83132146,0.088463 7.54636692,0.34751258 6.34204371,0.865611739 C5.1377205,1.3837109 4.07407321,2.10424615 3.15110186,3.0272175 C2.22813051,3.95018885 1.5058797,5.01555169 0.984349419,6.22330603 C0.46281914,7.43106036 0.202054,8.71773046 0.202054,10.0833163 C0.202054,11.4557644 0.4645347,12.7441501 0.9894961,13.9484733 C1.5144575,15.1527965 2.23670831,16.2147282 3.15624854,17.1342685 C4.07578877,18.0538087 5.1377205,18.7760595 6.34204371,19.3010209 C7.54636692,19.8259823 8.83475258,20.088463 10.2072007,20.088463 Z M10.2072007,18.2562448 C9.07493099,18.2562448 8.01471483,18.0452309 7.0265522,17.6232031 C6.03838956,17.2011753 5.17031614,16.6161693 4.42233192,15.8681851 C3.6743477,15.1202009 3.09105726,14.2521274 2.67246059,13.2639648 C2.25386392,12.2758022 2.04456558,11.215586 2.04456558,10.0833163 C2.04456558,8.95104663 2.25386392,7.89083047 2.67246059,6.90266784 C3.09105726,5.9145052 3.6743477,5.04643178 4.42233192,4.29844756 C5.17031614,3.55046334 6.036674,2.9671729 7.02140552,2.54857623 C8.00613703,2.12997956 9.06463763,1.92068122 10.1969073,1.92068122 C11.329177,1.92068122 12.3911087,2.12997956 13.3827025,2.54857623 C14.3742962,2.9671729 15.2440852,3.55046334 15.9920694,4.29844756 C16.7400537,5.04643178 17.3233441,5.9145052 17.7419408,6.90266784 C18.1605374,7.89083047 18.3698358,8.95104663 18.3698358,10.0833163 C18.3698358,11.215586 18.1605374,12.2758022 17.7419408,13.2639648 C17.3233441,14.2521274 16.7400537,15.1202009 15.9920694,15.8681851 C15.2440852,16.6161693 14.3760118,17.2011753 13.3878492,17.6232031 C12.3996865,18.0452309 11.3394704,18.2562448 10.2072007,18.2562448 Z M7.65444721,13.6242324 L12.7496608,13.6242324 C13.0584616,13.6242324 13.3003556,13.5384544 13.4753427,13.3668984 C13.6503299,13.1953424 13.7378234,12.9585951 13.7378234,12.6566565 L13.7378234,7.49968276 C13.7378234,7.19774418 13.6503299,6.96099688 13.4753427,6.78944087 C13.3003556,6.61788486 13.0584616,6.53210685 12.7496608,6.53210685 L7.65444721,6.53210685 C7.33878414,6.53210685 7.09345904,6.61788486 6.91847191,6.78944087 C6.74348478,6.96099688 6.65599121,7.19774418 6.65599121,7.49968276 L6.65599121,12.6566565 C6.65599121,12.9585951 6.74348478,13.1953424 6.91847191,13.3668984 C7.09345904,13.5384544 7.33878414,13.6242324 7.65444721,13.6242324 Z' id='shape' fill='%23FF3B30' fill-rule='nonzero'%3E%3C/path%3E %3C/g%3E %3C/svg%3E");
123
+ height: 21px;
124
+ }
125
  /* list */
126
  ol:not(.options), ul:not(.options) {
127
  padding-inline-start: 2em !important;
 
173
  #chuanhu_chatbot .wrap {
174
  max-height: calc(100vh - 140px - var(--line-sm)*1rem - 2*var(--block-label-margin) );
175
  }
176
+ [data-testid = "bot"] {
177
+ max-width: 98% !important;
178
+ }
179
+ #app_title h1{
180
+ letter-spacing: -1px; font-size: 22px;
181
+ }
182
  }
183
  /* 对话气泡 */
184
  [class *= "message"] {
assets/custom.js CHANGED
@@ -1,70 +1,215 @@
 
1
  // custom javascript here
 
2
  const MAX_HISTORY_LENGTH = 32;
3
 
4
  var key_down_history = [];
5
  var currentIndex = -1;
6
  var user_input_ta;
7
 
 
 
 
 
 
 
 
8
  var ga = document.getElementsByTagName("gradio-app");
9
  var targetNode = ga[0];
10
- var observer = new MutationObserver(function(mutations) {
 
 
 
11
  for (var i = 0; i < mutations.length; i++) {
12
- if (mutations[i].addedNodes.length) {
13
- var user_input_tb = document.getElementById('user_input_tb');
14
- if (user_input_tb) {
15
- // 监听到user_input_tb被添加到DOM树中
16
- // 这里可以编写元素加载完成后需要执行的代码
17
- user_input_ta = user_input_tb.querySelector("textarea");
18
- if (user_input_ta){
19
- observer.disconnect(); // 停止监听
20
- // 在 textarea 上监听 keydown 事件
21
- user_input_ta.addEventListener("keydown", function (event) {
22
- var value = user_input_ta.value.trim();
23
- // 判断按下的是否为方向键
24
- if (event.code === 'ArrowUp' || event.code === 'ArrowDown') {
25
- // 如果按下的是方向键,且输入框中有内容,且历史记录中没有该内容,则不执行操作
26
- if(value && key_down_history.indexOf(value) === -1)
27
- return;
28
- // 对于需要响应的动作,阻止默认行为。
29
- event.preventDefault();
30
- var length = key_down_history.length;
31
- if(length === 0) {
32
- currentIndex = -1; // 如果历史记录为空,直接将当前选中的记录重置
33
- return;
34
- }
35
- if (currentIndex === -1) {
36
- currentIndex = length;
37
- }
38
- if (event.code === 'ArrowUp' && currentIndex > 0) {
39
- currentIndex--;
40
- user_input_ta.value = key_down_history[currentIndex];
41
- } else if (event.code === 'ArrowDown' && currentIndex < length - 1) {
42
- currentIndex++;
43
- user_input_ta.value = key_down_history[currentIndex];
44
- }
45
- user_input_ta.selectionStart = user_input_ta.value.length;
46
- user_input_ta.selectionEnd = user_input_ta.value.length;
47
- const input_event = new InputEvent("input", {bubbles: true, cancelable: true});
48
- user_input_ta.dispatchEvent(input_event);
49
- }else if(event.code === "Enter") {
50
- if (value) {
51
- currentIndex = -1;
52
- if(key_down_history.indexOf(value) === -1){
53
- key_down_history.push(value);
54
- if (key_down_history.length > MAX_HISTORY_LENGTH) {
55
- key_down_history.shift();
56
- }
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
  }
60
- });
61
- break;
62
  }
63
- }
 
 
 
 
 
 
 
 
 
64
  }
65
- }
66
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- // 监听目标节点的子节点列表是否发生变化
69
- observer.observe(targetNode, { childList: true , subtree: true });
 
 
 
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
  // custom javascript here
3
+
4
  const MAX_HISTORY_LENGTH = 32;
5
 
6
  var key_down_history = [];
7
  var currentIndex = -1;
8
  var user_input_ta;
9
 
10
+ var gradioContainer = null;
11
+ var user_input_ta = null;
12
+ 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];
19
+ var isInIframe = (window.self !== window.top);
20
+
21
+ // gradio 页面加载好了么??? 我能动你的元素了么??
22
+ function gradioLoaded(mutations) {
23
  for (var i = 0; i < mutations.length; i++) {
24
+ if (mutations[i].addedNodes.length) {
25
+ gradioContainer = document.querySelector(".gradio-container");
26
+ user_input_tb = document.getElementById('user_input_tb');
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 加载出来了没?
35
+ selectHistory();
36
+ }
37
+ if (userInfoDiv && appTitleDiv) { // userInfoDiv 和 appTitleDiv 加载出来了没?
38
+ setTimeout(showOrHideUserInfo(), 2000);
39
+ }
40
+ if (chatbot) { // chatbot 加载出来了没?
41
+ setChatbotHeight()
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ function selectHistory() {
48
+ user_input_ta = user_input_tb.querySelector("textarea");
49
+ if (user_input_ta) {
50
+ observer.disconnect(); // 停止监听
51
+ // 在 textarea 上监听 keydown 事件
52
+ user_input_ta.addEventListener("keydown", function (event) {
53
+ var value = user_input_ta.value.trim();
54
+ // 判断按下的是否为方向键
55
+ if (event.code === 'ArrowUp' || event.code === 'ArrowDown') {
56
+ // 如果按下的是方向键,且输入框中有内容,且历史记录中没有该内容,则不执行操作
57
+ if (value && key_down_history.indexOf(value) === -1)
58
+ return;
59
+ // 对于需要响应的动作,阻止默认行为。
60
+ event.preventDefault();
61
+ var length = key_down_history.length;
62
+ if (length === 0) {
63
+ currentIndex = -1; // 如果历史记录为空,直接将当前选中的记录重置
64
+ return;
65
+ }
66
+ if (currentIndex === -1) {
67
+ currentIndex = length;
68
+ }
69
+ if (event.code === 'ArrowUp' && currentIndex > 0) {
70
+ currentIndex--;
71
+ user_input_ta.value = key_down_history[currentIndex];
72
+ } else if (event.code === 'ArrowDown' && currentIndex < length - 1) {
73
+ currentIndex++;
74
+ user_input_ta.value = key_down_history[currentIndex];
75
+ }
76
+ user_input_ta.selectionStart = user_input_ta.value.length;
77
+ user_input_ta.selectionEnd = user_input_ta.value.length;
78
+ const input_event = new InputEvent("input", { bubbles: true, cancelable: true });
79
+ user_input_ta.dispatchEvent(input_event);
80
+ } else if (event.code === "Enter") {
81
+ if (value) {
82
+ currentIndex = -1;
83
+ if (key_down_history.indexOf(value) === -1) {
84
+ key_down_history.push(value);
85
+ if (key_down_history.length > MAX_HISTORY_LENGTH) {
86
+ key_down_history.shift();
87
  }
88
  }
89
+ }
 
90
  }
91
+ });
92
+ }
93
+ }
94
+
95
+ function toggleUserInfoVisibility(shouldHide) {
96
+ if (userInfoDiv) {
97
+ if (shouldHide) {
98
+ userInfoDiv.classList.add("hideK");
99
+ } else {
100
+ userInfoDiv.classList.remove("hideK");
101
  }
102
+ }
103
+ }
104
+ function showOrHideUserInfo() {
105
+ var sendBtn = document.getElementById("submit_btn");
106
+
107
+ // Bind mouse/touch events to show/hide user info
108
+ appTitleDiv.addEventListener("mouseenter", function () {
109
+ toggleUserInfoVisibility(false);
110
+ });
111
+ userInfoDiv.addEventListener("mouseenter", function () {
112
+ toggleUserInfoVisibility(false);
113
+ });
114
+ sendBtn.addEventListener("mouseenter", function () {
115
+ toggleUserInfoVisibility(false);
116
+ });
117
+
118
+ appTitleDiv.addEventListener("mouseleave", function () {
119
+ toggleUserInfoVisibility(true);
120
+ });
121
+ userInfoDiv.addEventListener("mouseleave", function () {
122
+ toggleUserInfoVisibility(true);
123
+ });
124
+ sendBtn.addEventListener("mouseleave", function () {
125
+ toggleUserInfoVisibility(true);
126
+ });
127
+
128
+ appTitleDiv.ontouchstart = function () {
129
+ toggleUserInfoVisibility(false);
130
+ };
131
+ userInfoDiv.ontouchstart = function () {
132
+ toggleUserInfoVisibility(false);
133
+ };
134
+ sendBtn.ontouchstart = function () {
135
+ toggleUserInfoVisibility(false);
136
+ };
137
+
138
+ appTitleDiv.ontouchend = function () {
139
+ setTimeout(function () {
140
+ toggleUserInfoVisibility(true);
141
+ }, 3000);
142
+ };
143
+ userInfoDiv.ontouchend = function () {
144
+ setTimeout(function () {
145
+ toggleUserInfoVisibility(true);
146
+ }, 3000);
147
+ };
148
+ sendBtn.ontouchend = function () {
149
+ setTimeout(function () {
150
+ toggleUserInfoVisibility(true);
151
+ }, 3000); // Delay 1 second to hide user info
152
+ };
153
 
154
+ // Hide user info after 2 second
155
+ setTimeout(function () {
156
+ toggleUserInfoVisibility(true);
157
+ }, 2000);
158
+ }
159
 
160
+ function toggleDarkMode(isEnabled) {
161
+ gradioContainer = document.querySelector(".gradio-container");
162
+ if (isEnabled) {
163
+ gradioContainer.classList.add("dark");
164
+ document.body.style.backgroundColor = "";
165
+ } else {
166
+ gradioContainer.classList.remove("dark");
167
+ }
168
+ }
169
+ function adjustDarkMode() {
170
+ const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
171
+ // 根据当前颜色模式设置初始状态
172
+ toggleDarkMode(darkModeQuery.matches);
173
+ // 监听颜色模式变化
174
+ darkModeQuery.addEventListener("change", (e) => {
175
+ toggleDarkMode(e.matches);
176
+ });
177
+ }
178
+
179
+ function setChatbotHeight() {
180
+ const screenWidth = window.innerWidth;
181
+ const statusDisplay = document.querySelector('#status_display');
182
+ const statusDisplayHeight = statusDisplay ? statusDisplay.offsetHeight : 0;
183
+ const wrap = chatbot.querySelector('.wrap');
184
+ const vh = window.innerHeight * 0.01;
185
+ document.documentElement.style.setProperty('--vh', `${vh}px`);
186
+ if (isInIframe) {
187
+ chatbot.style.height = `700px`;
188
+ wrap.style.maxHeight = `calc(700px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`
189
+ } else {
190
+ if (screenWidth <= 320) {
191
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 150}px)`;
192
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 150}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
193
+ } else if (screenWidth <= 499) {
194
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 100}px)`;
195
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 100}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
196
+ } else {
197
+ chatbot.style.height = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 160}px)`;
198
+ wrap.style.maxHeight = `calc(var(--vh, 1vh) * 100 - ${statusDisplayHeight + 160}px - var(--line-sm) * 1rem - 2 * var(--block-label-margin))`;
199
+ }
200
+ }
201
+ }
202
+
203
+ // 监视页面内部 DOM 变动
204
+ var observer = new MutationObserver(function (mutations) {
205
+ gradioLoaded(mutations);
206
+ });
207
+ observer.observe(targetNode, { childList: true, subtree: true });
208
+
209
+ // 监视页面变化
210
+ window.addEventListener("DOMContentLoaded", function () {
211
+ isInIframe = (window.self !== window.top);
212
+ });
213
+ window.addEventListener('resize', setChatbotHeight);
214
+ window.addEventListener('scroll', setChatbotHeight);
215
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", adjustDarkMode);
config_example.json CHANGED
@@ -1,14 +1,20 @@
1
  {
 
 
2
  "openai_api_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxx",
3
- "https_proxy": "http://127.0.0.1:1079",
4
- "http_proxy": "http://127.0.0.1:1079",
5
- "users": [],
 
6
  "advance_docs": {
7
  "pdf": {
 
8
  "two_column": false,
 
9
  "formula_ocr": true
10
  }
11
  },
 
12
  "multi_api_key": false,
13
  "api_key_list": [
14
  "sk-xxxxxxxxxxxxxxxxxxxxxxxx1",
 
1
  {
2
+ // 你的OpenAI API Key,一般必填,
3
+ // 若缺省填为 "openai_api_key": "" 则必须再在图形界面中填入API Key
4
  "openai_api_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxx",
5
+ // 如果使用代理,请取消注释下面的两行,并替换代理URL
6
+ // "https_proxy": "http://127.0.0.1:1079",
7
+ // "http_proxy": "http://127.0.0.1:1079",
8
+ "users": [],
9
  "advance_docs": {
10
  "pdf": {
11
+ // 是否认为PDF是双栏的
12
  "two_column": false,
13
+ // 是否使用OCR识别PDF中的公式
14
  "formula_ocr": true
15
  }
16
  },
17
+ // 是否多个API Key轮换使用
18
  "multi_api_key": false,
19
  "api_key_list": [
20
  "sk-xxxxxxxxxxxxxxxxxxxxxxxx1",
modules/config.py CHANGED
@@ -3,7 +3,7 @@ from contextlib import contextmanager
3
  import os
4
  import logging
5
  import sys
6
- import json
7
 
8
  from . import shared
9
 
 
3
  import os
4
  import logging
5
  import sys
6
+ import commentjson as json
7
 
8
  from . import shared
9
 
modules/presets.py CHANGED
@@ -30,7 +30,7 @@ CONCURRENT_COUNT = 100 # 允许同时使用的用户数量
30
  SIM_K = 5
31
  INDEX_QUERY_TEMPRATURE = 1.0
32
 
33
- title = """<h1 align="left" style="min-width:200px; margin-top:6px; white-space: nowrap;">川虎ChatGPT 🚀</h1>"""
34
  description = """\
35
  <div align="center" style="margin:16px 0">
36
 
@@ -42,9 +42,7 @@ description = """\
42
  </div>
43
  """
44
 
45
- footer = """\
46
- <div class="versions">{versions}</div>
47
- """
48
 
49
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
50
 
 
30
  SIM_K = 5
31
  INDEX_QUERY_TEMPRATURE = 1.0
32
 
33
+ title = """<h1 align="left">川虎ChatGPT 🚀</h1>"""
34
  description = """\
35
  <div align="center" style="margin:16px 0">
36
 
 
42
  </div>
43
  """
44
 
45
+ footer = """<div class="versions">{versions}</div>"""
 
 
46
 
47
  summarize_prompt = "你是谁?我们刚才聊了什么?" # 总结对话时的 prompt
48
 
requirements.txt CHANGED
@@ -13,3 +13,4 @@ markdown
13
  PyPDF2
14
  pdfplumber
15
  pandas
 
 
13
  PyPDF2
14
  pdfplumber
15
  pandas
16
+ commentjson