Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
•
f36945f
1
Parent(s):
374ce0c
WIP: self-adaption side blocks
Browse files- ChuanhuChatbot.py +35 -34
- web_assets/javascript/webui.js +86 -6
- web_assets/stylesheet/ChuanhuChat.css +85 -23
ChuanhuChatbot.py
CHANGED
@@ -95,39 +95,38 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
95 |
with gr.Row(elem_id="chuanhu-func-nav"):
|
96 |
gr.HTML(get_html("func_nav.html"))
|
97 |
|
98 |
-
with gr.Column(
|
99 |
-
with gr.
|
100 |
-
|
101 |
-
|
102 |
-
with gr.
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
with gr.
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
with gr.
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
with gr.Column(min_width=50, scale=1):
|
130 |
-
|
131 |
with gr.Accordion(label="Prompt", open=True):
|
132 |
systemPromptTxt = gr.Textbox(
|
133 |
show_label=True,
|
@@ -320,6 +319,9 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
320 |
elem_classes="view-only-textbox no-container",
|
321 |
)
|
322 |
|
|
|
|
|
|
|
323 |
with gr.Box(elem_id="chuanhu-training"):
|
324 |
with gr.Row():
|
325 |
gr.Markdown("## Training")
|
@@ -345,7 +347,6 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
345 |
add_to_models_btn = gr.Button(i18n("添加训练好的模型到模型列表"), interactive=False)
|
346 |
|
347 |
|
348 |
-
gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
|
349 |
gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
|
350 |
|
351 |
# https://github.com/gradio-app/gradio/pull/3296
|
|
|
95 |
with gr.Row(elem_id="chuanhu-func-nav"):
|
96 |
gr.HTML(get_html("func_nav.html"))
|
97 |
|
98 |
+
with gr.Column(elem_id="chuanhu-area", scale=5):
|
99 |
+
with gr.Column(scale=5, elem_id="chatbot-area"):
|
100 |
+
with gr.Row():
|
101 |
+
chatbot = gr.Chatbot(label="Chuanhu Chat", elem_id="chuanhu-chatbot", latex_delimiters=latex_delimiters_set, height=700)
|
102 |
+
with gr.Row():
|
103 |
+
with gr.Column(min_width=225, scale=12):
|
104 |
+
user_input = gr.Textbox(
|
105 |
+
elem_id="user-input-tb",
|
106 |
+
show_label=False, placeholder=i18n("在这里输入"),
|
107 |
+
container=False
|
108 |
+
)
|
109 |
+
with gr.Column(min_width=42, scale=1):
|
110 |
+
submitBtn = gr.Button(value="", variant="primary", elem_id="submit-btn")
|
111 |
+
cancelBtn = gr.Button(value="", variant="secondary", visible=False, elem_id="cancel-btn")
|
112 |
+
with gr.Row(elem_id="chatbot-buttons"):
|
113 |
+
with gr.Column(min_width=120, scale=1):
|
114 |
+
emptyBtn = gr.Button(
|
115 |
+
i18n("🧹 新的对话"), elem_id="empty-btn"
|
116 |
+
)
|
117 |
+
with gr.Column(min_width=120, scale=1):
|
118 |
+
retryBtn = gr.Button(i18n("🔄 重新生成"))
|
119 |
+
with gr.Column(min_width=120, scale=1):
|
120 |
+
delFirstBtn = gr.Button(i18n("🗑️ 删除最旧对话"))
|
121 |
+
with gr.Column(min_width=120, scale=1):
|
122 |
+
delLastBtn = gr.Button(i18n("🗑️ 删除最新对话"))
|
123 |
+
with gr.Row(visible=False) as like_dislike_area:
|
124 |
+
with gr.Column(min_width=20, scale=1):
|
125 |
+
likeBtn = gr.Button(i18n("👍"))
|
126 |
+
with gr.Column(min_width=20, scale=1):
|
127 |
+
dislikeBtn = gr.Button(i18n("👎"))
|
128 |
+
|
129 |
+
with gr.Column(elem_id="toolbox-area", min_width=50, scale=1):
|
|
|
130 |
with gr.Accordion(label="Prompt", open=True):
|
131 |
systemPromptTxt = gr.Textbox(
|
132 |
show_label=True,
|
|
|
319 |
elem_classes="view-only-textbox no-container",
|
320 |
)
|
321 |
|
322 |
+
with gr.Tab(label=i18n("关于")):
|
323 |
+
gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
|
324 |
+
|
325 |
with gr.Box(elem_id="chuanhu-training"):
|
326 |
with gr.Row():
|
327 |
gr.Markdown("## Training")
|
|
|
347 |
add_to_models_btn = gr.Button(i18n("添加训练好的模型到模型列表"), interactive=False)
|
348 |
|
349 |
|
|
|
350 |
gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
|
351 |
|
352 |
# https://github.com/gradio-app/gradio/pull/3296
|
web_assets/javascript/webui.js
CHANGED
@@ -25,6 +25,65 @@ function showMask() {
|
|
25 |
});
|
26 |
}
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
function closeBox() {
|
29 |
chuanhuPopup.classList.remove('showBox');
|
30 |
popupWrapper.classList.remove('showBox');
|
@@ -34,17 +93,38 @@ function closeBox() {
|
|
34 |
document.body.classList.remove('popup-open');
|
35 |
}
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
function menuClick() {
|
38 |
var menu = gradioApp().querySelector('#menu-area');
|
39 |
// var menuBtn = gradioApp().querySelector('.menu-btn');
|
40 |
-
if (menu.classList.contains('
|
41 |
-
menu.classList.remove('
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
} else {
|
44 |
-
|
45 |
-
|
46 |
}
|
47 |
-
setChatAreaWidth();
|
48 |
}
|
49 |
|
50 |
function setHistroyPanel() {
|
|
|
25 |
});
|
26 |
}
|
27 |
|
28 |
+
|
29 |
+
function showSideMask() {
|
30 |
+
const oldSideMask = gradioApp().querySelector('.chuanhu-side-mask');
|
31 |
+
if (oldSideMask) {
|
32 |
+
showOrHideSideMask(oldSideMask);
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
|
36 |
+
function showOrHideSideMask(sideMask) {
|
37 |
+
const windowWidth = window.innerWidth;
|
38 |
+
if (document.querySelector('.showSide')) {
|
39 |
+
|
40 |
+
if (windowWidth < 1024) {
|
41 |
+
if (gradioApp().querySelector('#menu-area').classList.contains('showSide') && gradioApp().querySelector('#toolbox-area').classList.contains('showSide')) {
|
42 |
+
gradioApp().querySelector('#toolbox-area').classList.remove('showSide');
|
43 |
+
// if both menu and toolbox are open, close toolbox...
|
44 |
+
}
|
45 |
+
}
|
46 |
+
// console.log("test in showSide")
|
47 |
+
if (windowWidth <= 768) {
|
48 |
+
document.body.classList.add('popup-open');
|
49 |
+
// sideMask.style.opacity = '0';
|
50 |
+
if (document.querySelector('.chuanhu-side-mask')) {
|
51 |
+
sideMask.style.display = 'block';
|
52 |
+
setTimeout(() => {sideMask.style.opacity = '0.5'; }, 200);
|
53 |
+
} else {
|
54 |
+
sideMask.style.opacity = '0.5';
|
55 |
+
}
|
56 |
+
// sideMask.style.display = 'block';
|
57 |
+
// // sideMask.style.opacity = '0.5';
|
58 |
+
// setTimeout(() => {sideMask.style.opacity = '0.5'; }, 100);
|
59 |
+
|
60 |
+
// sideMask.style.display = 'block';
|
61 |
+
} else {
|
62 |
+
// sideMask.style.display = 'none';
|
63 |
+
document.body.classList.remove('popup-open');
|
64 |
+
sideMask.style.opacity = '0';
|
65 |
+
// sideMask.style.display = 'none';
|
66 |
+
// note: 动画卡,气死我了
|
67 |
+
setTimeout(() => {sideMask.style.display = 'none'; }, 100);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
const sideMask = document.createElement('div');
|
73 |
+
sideMask.classList.add('chuanhu-side-mask');
|
74 |
+
window.addEventListener('resize', () => {
|
75 |
+
showOrHideSideMask(sideMask);
|
76 |
+
});
|
77 |
+
|
78 |
+
gradioApp().appendChild(sideMask);
|
79 |
+
showOrHideSideMask(sideMask);
|
80 |
+
|
81 |
+
|
82 |
+
sideMask.addEventListener('click', () => {
|
83 |
+
closeSide();
|
84 |
+
});
|
85 |
+
}
|
86 |
+
|
87 |
function closeBox() {
|
88 |
chuanhuPopup.classList.remove('showBox');
|
89 |
popupWrapper.classList.remove('showBox');
|
|
|
93 |
document.body.classList.remove('popup-open');
|
94 |
}
|
95 |
|
96 |
+
function closeSide() {
|
97 |
+
|
98 |
+
document.querySelector('.chuanhu-side-mask').style.opacity = '0';
|
99 |
+
setTimeout(() => {document.querySelector('.chuanhu-side-mask').remove();}, 300);
|
100 |
+
document.body.classList.remove('popup-open');
|
101 |
+
|
102 |
+
gradioApp().querySelector('#menu-area').classList.remove('showSide');
|
103 |
+
gradioApp().querySelector('#toolbox-area').classList.remove('showSide');
|
104 |
+
|
105 |
+
}
|
106 |
+
|
107 |
function menuClick() {
|
108 |
var menu = gradioApp().querySelector('#menu-area');
|
109 |
// var menuBtn = gradioApp().querySelector('.menu-btn');
|
110 |
+
if (menu.classList.contains('showSide')) {
|
111 |
+
menu.classList.remove('showSide');
|
112 |
+
closeSide();
|
113 |
+
} else {
|
114 |
+
menu.classList.add('showSide');
|
115 |
+
showSideMask();
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
function toolboxClick() {
|
120 |
+
var toolbox = gradioApp().querySelector('#toolbox-area');
|
121 |
+
if (toolbox.classList.contains('showSide')) {
|
122 |
+
toolbox.classList.remove('showSide');
|
123 |
+
closeSide();
|
124 |
} else {
|
125 |
+
toolbox.classList.add('showSide');
|
126 |
+
showSideMask();
|
127 |
}
|
|
|
128 |
}
|
129 |
|
130 |
function setHistroyPanel() {
|
web_assets/stylesheet/ChuanhuChat.css
CHANGED
@@ -9,6 +9,9 @@
|
|
9 |
--message-bot-background-color-dark: #2C2C2C;
|
10 |
--switch-checkbox-color-light: #e5e7eb;
|
11 |
--switch-checkbox-color-dark: #515151;
|
|
|
|
|
|
|
12 |
}
|
13 |
|
14 |
body.popup-open {
|
@@ -117,25 +120,30 @@ body.popup-open {
|
|
117 |
white-space: nowrap;
|
118 |
}
|
119 |
|
120 |
-
.chuanhu-mask {
|
121 |
background-color: gray;
|
122 |
-
|
123 |
position: fixed;
|
124 |
top: 0;
|
125 |
left: 0;
|
126 |
width: 100%;
|
127 |
height: 100%;
|
128 |
-
z-index:
|
129 |
/* background-color: transparent; */
|
130 |
}
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
132 |
#popup-wrapper {
|
133 |
display: none;
|
134 |
position: fixed;
|
135 |
overflow: auto;
|
136 |
top: 0;
|
137 |
left: 0;
|
138 |
-
z-index:
|
139 |
}
|
140 |
#popup-wrapper.showBox {
|
141 |
display: grid;
|
@@ -144,7 +152,7 @@ body.popup-open {
|
|
144 |
|
145 |
#chuanhu-popup {
|
146 |
display: none;
|
147 |
-
z-index:
|
148 |
width: 680px;
|
149 |
height: 400px;
|
150 |
padding: 0;
|
@@ -160,32 +168,86 @@ body.popup-open {
|
|
160 |
display: none;
|
161 |
}
|
162 |
|
163 |
-
.hideSide {
|
164 |
-
width: 0 !important;
|
165 |
-
/* flex-basis: 0 !important; */
|
166 |
-
display: none !important;
|
167 |
-
}
|
168 |
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
171 |
}
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
|
|
|
|
176 |
min-width: unset !important;
|
177 |
-
|
|
|
|
|
|
|
178 |
}
|
179 |
-
#
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
}
|
182 |
-
#menu-area {
|
183 |
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
-
#toolbox-area {
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
}
|
188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
/* .chuanhu-history-panel ul.options {
|
191 |
position: relative;
|
@@ -254,7 +316,7 @@ body.popup-open {
|
|
254 |
|
255 |
|
256 |
#history-select-wrap {
|
257 |
-
height:
|
258 |
overflow: auto;
|
259 |
overflow-x: hidden;
|
260 |
}
|
|
|
9 |
--message-bot-background-color-dark: #2C2C2C;
|
10 |
--switch-checkbox-color-light: #e5e7eb;
|
11 |
--switch-checkbox-color-dark: #515151;
|
12 |
+
|
13 |
+
--menu-width: 300px;
|
14 |
+
--toolbox-width: 280px;
|
15 |
}
|
16 |
|
17 |
body.popup-open {
|
|
|
120 |
white-space: nowrap;
|
121 |
}
|
122 |
|
123 |
+
.chuanhu-mask, .chuanhu-side-mask {
|
124 |
background-color: gray;
|
125 |
+
transition: opacity 0.3s ease;
|
126 |
position: fixed;
|
127 |
top: 0;
|
128 |
left: 0;
|
129 |
width: 100%;
|
130 |
height: 100%;
|
131 |
+
z-index: 999;
|
132 |
/* background-color: transparent; */
|
133 |
}
|
134 |
+
.chuanhu-mask {
|
135 |
+
opacity: 0.5;
|
136 |
+
}
|
137 |
+
.chuanhu-side-mask {
|
138 |
+
opacity: 0;
|
139 |
+
}
|
140 |
#popup-wrapper {
|
141 |
display: none;
|
142 |
position: fixed;
|
143 |
overflow: auto;
|
144 |
top: 0;
|
145 |
left: 0;
|
146 |
+
z-index: 99999;
|
147 |
}
|
148 |
#popup-wrapper.showBox {
|
149 |
display: grid;
|
|
|
152 |
|
153 |
#chuanhu-popup {
|
154 |
display: none;
|
155 |
+
z-index: 99999;
|
156 |
width: 680px;
|
157 |
height: 400px;
|
158 |
padding: 0;
|
|
|
168 |
display: none;
|
169 |
}
|
170 |
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
+
|
173 |
+
#chuanhu-body {
|
174 |
+
flex-wrap: nowrap;
|
175 |
+
gap: 0;
|
176 |
+
overflow: hidden;
|
177 |
+
display: inline-flex;
|
178 |
+
/* height: calc(100vh - 72px); */
|
179 |
}
|
180 |
+
|
181 |
+
/* default invisible */
|
182 |
+
#menu-area, #toolbox-area {
|
183 |
+
height: 0;
|
184 |
+
width: 0;
|
185 |
+
transition: width 0.3s ease;
|
186 |
+
visibility: hidden;
|
187 |
+
flex: unset;
|
188 |
min-width: unset !important;
|
189 |
+
display: flex;
|
190 |
+
flex-shrink: 0;
|
191 |
+
overflow: hidden;
|
192 |
+
flex-wrap: nowrap;
|
193 |
}
|
194 |
+
#menu-area > div {
|
195 |
+
width: var(--menu-width);
|
196 |
+
}
|
197 |
+
#toolbox-area > div {
|
198 |
+
width: var(--toolbox-width);
|
199 |
+
}
|
200 |
+
#menu-area.showSide {
|
201 |
+
width: var(--menu-width);
|
202 |
+
height: 100%;
|
203 |
+
visibility: visible;
|
204 |
+
margin-right: 16px;
|
205 |
}
|
|
|
206 |
|
207 |
+
#toolbox-area.showSide {
|
208 |
+
width: var(--toolbox-width);
|
209 |
+
height: 100%;
|
210 |
+
visibility: visible;
|
211 |
+
margin-left: 16px;
|
212 |
}
|
|
|
213 |
|
214 |
+
#chuanhu-area {
|
215 |
+
flex: unset;
|
216 |
+
width: 100%;
|
217 |
+
flex-wrap: nowrap;
|
218 |
+
gap: 0;
|
219 |
+
justify-content: center;
|
220 |
+
overflow: hidden;
|
221 |
+
flex-direction: row;
|
222 |
+
padding-bottom: 6px;
|
223 |
}
|
224 |
|
225 |
+
@media screen and (max-width: 767px) {
|
226 |
+
#menu-area {
|
227 |
+
position: absolute;
|
228 |
+
transition: left 0.3s ease, visibility 0.1s ease;
|
229 |
+
left: calc(0px - var(--menu-width));
|
230 |
+
z-index: 9999;
|
231 |
+
overflow: unset;
|
232 |
+
}
|
233 |
+
#menu-area.showSide {
|
234 |
+
left: 0;
|
235 |
+
margin-left: -16px;
|
236 |
+
}
|
237 |
+
#toolbox-area {
|
238 |
+
position: absolute;
|
239 |
+
transition: right 0.3s ease, visibility 0.1s ease;
|
240 |
+
right: calc(0px - var(--toolbox-width));
|
241 |
+
z-index: 9999;
|
242 |
+
overflow: unset;
|
243 |
+
}
|
244 |
+
#toolbox-area.showSide {
|
245 |
+
right: 0;
|
246 |
+
}
|
247 |
+
/* #menu-area.showSide, #toolbox-area.showSide {
|
248 |
+
z-index: 9999;
|
249 |
+
} */
|
250 |
+
}
|
251 |
|
252 |
/* .chuanhu-history-panel ul.options {
|
253 |
position: relative;
|
|
|
316 |
|
317 |
|
318 |
#history-select-wrap {
|
319 |
+
height: 300px;
|
320 |
overflow: auto;
|
321 |
overflow-x: hidden;
|
322 |
}
|