Spaces:
Sleeping
Sleeping
Merge pull request #734 from GaiZhenbiao/ui
Browse files- assets/custom.css +36 -2
- assets/custom.js +43 -0
- modules/presets.py +32 -27
assets/custom.css
CHANGED
@@ -144,7 +144,7 @@ footer {
|
|
144 |
display: none !important;
|
145 |
}
|
146 |
.apSlider {
|
147 |
-
background-color: var(--
|
148 |
bottom: 0;
|
149 |
cursor: pointer;
|
150 |
left: 0;
|
@@ -163,13 +163,47 @@ footer {
|
|
163 |
content: "🌞";
|
164 |
}
|
165 |
input:checked + .apSlider {
|
166 |
-
background-color: var(--
|
167 |
}
|
168 |
input:checked + .apSlider::before {
|
169 |
transform: translateX(23px);
|
170 |
content:"🌚";
|
171 |
}
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
#submit_btn, #cancel_btn {
|
174 |
height: 42px !important;
|
175 |
}
|
|
|
144 |
display: none !important;
|
145 |
}
|
146 |
.apSlider {
|
147 |
+
background-color: var(--neutral-200);
|
148 |
bottom: 0;
|
149 |
cursor: pointer;
|
150 |
left: 0;
|
|
|
163 |
content: "🌞";
|
164 |
}
|
165 |
input:checked + .apSlider {
|
166 |
+
background-color: var(--primary-600);
|
167 |
}
|
168 |
input:checked + .apSlider::before {
|
169 |
transform: translateX(23px);
|
170 |
content:"🌚";
|
171 |
}
|
172 |
|
173 |
+
/* Override Slider Styles (for webkit browsers like Safari and Chrome)
|
174 |
+
* 好希望这份提案能早日实现 https://github.com/w3c/csswg-drafts/issues/4410
|
175 |
+
* 进度滑块在各个平台还是太不统一了
|
176 |
+
*/
|
177 |
+
input[type="range"] {
|
178 |
+
-webkit-appearance: none;
|
179 |
+
height: 4px;
|
180 |
+
background: var(--input-background-fill);
|
181 |
+
border-radius: 5px;
|
182 |
+
background-image: linear-gradient(var(--primary-500),var(--primary-500));
|
183 |
+
background-size: 0% 100%;
|
184 |
+
background-repeat: no-repeat;
|
185 |
+
}
|
186 |
+
input[type="range"]::-webkit-slider-thumb {
|
187 |
+
-webkit-appearance: none;
|
188 |
+
height: 20px;
|
189 |
+
width: 20px;
|
190 |
+
border-radius: 50%;
|
191 |
+
border: solid 0.5px #ddd;
|
192 |
+
background-color: white;
|
193 |
+
cursor: ew-resize;
|
194 |
+
box-shadow: var(--input-shadow);
|
195 |
+
transition: background-color .1s ease;
|
196 |
+
}
|
197 |
+
input[type="range"]::-webkit-slider-thumb:hover {
|
198 |
+
background: var(--neutral-50);
|
199 |
+
}
|
200 |
+
input[type=range]::-webkit-slider-runnable-track {
|
201 |
+
-webkit-appearance: none;
|
202 |
+
box-shadow: none;
|
203 |
+
border: none;
|
204 |
+
background: transparent;
|
205 |
+
}
|
206 |
+
|
207 |
#submit_btn, #cancel_btn {
|
208 |
height: 42px !important;
|
209 |
}
|
assets/custom.js
CHANGED
@@ -29,6 +29,15 @@ var historyLoaded = false;
|
|
29 |
var ga = document.getElementsByTagName("gradio-app");
|
30 |
var targetNode = ga[0];
|
31 |
var isInIframe = (window.self !== window.top);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
// gradio 页面加载好了么??? 我能动你的元素了么??
|
34 |
function gradioLoaded(mutations) {
|
@@ -82,6 +91,17 @@ function gradioLoaded(mutations) {
|
|
82 |
}
|
83 |
}
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
function selectHistory() {
|
86 |
user_input_ta = user_input_tb.querySelector("textarea");
|
87 |
if (user_input_ta) {
|
@@ -276,6 +296,25 @@ function setChatbotScroll() {
|
|
276 |
var scrollHeight = chatbotWrap.scrollHeight;
|
277 |
chatbotWrap.scrollTo(0,scrollHeight)
|
278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
280 |
function addChuanhuButton(botElement) {
|
281 |
var rawMessage = null;
|
@@ -455,6 +494,9 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|
455 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
456 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot pre').forEach(addCopyCodeButton);
|
457 |
}
|
|
|
|
|
|
|
458 |
}
|
459 |
for (var node of mmutation.removedNodes) {
|
460 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
@@ -516,6 +558,7 @@ function loadHistoryHtml() {
|
|
516 |
var fakeHistory = document.createElement('div');
|
517 |
fakeHistory.classList.add('history-message');
|
518 |
fakeHistory.innerHTML = tempDiv.innerHTML;
|
|
|
519 |
chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
|
520 |
// var fakeHistory = document.createElement('div');
|
521 |
// fakeHistory.classList.add('history-message');
|
|
|
29 |
var ga = document.getElementsByTagName("gradio-app");
|
30 |
var targetNode = ga[0];
|
31 |
var isInIframe = (window.self !== window.top);
|
32 |
+
var language = navigator.language.slice(0,2);
|
33 |
+
|
34 |
+
var forView_i18n = {
|
35 |
+
'zh': "仅供查看",
|
36 |
+
'en': "For viewing only",
|
37 |
+
'ja': "閲覧専用",
|
38 |
+
'fr': "Pour consultation seulement",
|
39 |
+
'es': "Solo para visualización",
|
40 |
+
};
|
41 |
|
42 |
// gradio 页面加载好了么??? 我能动你的元素了么??
|
43 |
function gradioLoaded(mutations) {
|
|
|
91 |
}
|
92 |
}
|
93 |
|
94 |
+
function webLocale() {
|
95 |
+
console.log("webLocale", language);
|
96 |
+
if (forView_i18n.hasOwnProperty(language)) {
|
97 |
+
var forView = forView_i18n[language];
|
98 |
+
var forViewStyle = document.createElement('style');
|
99 |
+
forViewStyle.innerHTML = '.wrap>.history-message>:last-child::after { content: "' + forView + '"!important; }';
|
100 |
+
document.head.appendChild(forViewStyle);
|
101 |
+
console.log("added forViewStyle", forView);
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
function selectHistory() {
|
106 |
user_input_ta = user_input_tb.querySelector("textarea");
|
107 |
if (user_input_ta) {
|
|
|
296 |
var scrollHeight = chatbotWrap.scrollHeight;
|
297 |
chatbotWrap.scrollTo(0,scrollHeight)
|
298 |
}
|
299 |
+
var rangeInputs = null;
|
300 |
+
var numberInputs = null;
|
301 |
+
function setSlider() {
|
302 |
+
rangeInputs = document.querySelectorAll('input[type="range"]');
|
303 |
+
numberInputs = document.querySelectorAll('input[type="number"]')
|
304 |
+
setSliderRange();
|
305 |
+
rangeInputs.forEach(rangeInput => {
|
306 |
+
rangeInput.addEventListener('input', setSliderRange);
|
307 |
+
});
|
308 |
+
numberInputs.forEach(numberInput => {
|
309 |
+
numberInput.addEventListener('input', setSliderRange);
|
310 |
+
})
|
311 |
+
}
|
312 |
+
function setSliderRange() {
|
313 |
+
var range = document.querySelectorAll('input[type="range"]');
|
314 |
+
range.forEach(range => {
|
315 |
+
range.style.backgroundSize = (range.value - range.min) / (range.max - range.min) * 100 + '% 100%';
|
316 |
+
});
|
317 |
+
}
|
318 |
|
319 |
function addChuanhuButton(botElement) {
|
320 |
var rawMessage = null;
|
|
|
494 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
495 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot pre').forEach(addCopyCodeButton);
|
496 |
}
|
497 |
+
if (node.tagName === 'INPUT' && node.getAttribute('type') === 'range') {
|
498 |
+
setSlider();
|
499 |
+
}
|
500 |
}
|
501 |
for (var node of mmutation.removedNodes) {
|
502 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
|
|
558 |
var fakeHistory = document.createElement('div');
|
559 |
fakeHistory.classList.add('history-message');
|
560 |
fakeHistory.innerHTML = tempDiv.innerHTML;
|
561 |
+
webLocale();
|
562 |
chatbotWrap.insertBefore(fakeHistory, chatbotWrap.firstChild);
|
563 |
// var fakeHistory = document.createElement('div');
|
564 |
// fakeHistory.classList.add('history-message');
|
modules/presets.py
CHANGED
@@ -164,17 +164,18 @@ ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"
|
|
164 |
|
165 |
small_and_beautiful_theme = gr.themes.Soft(
|
166 |
primary_hue=gr.themes.Color(
|
167 |
-
c50="
|
168 |
-
c100="
|
169 |
-
c200="#
|
170 |
-
c300="
|
171 |
-
c400="
|
172 |
-
c500="
|
173 |
-
c600="
|
174 |
-
c700="
|
175 |
-
c800="
|
176 |
-
c900="#
|
177 |
-
c950="#
|
|
|
178 |
),
|
179 |
secondary_hue=gr.themes.Color(
|
180 |
c50="#576b95",
|
@@ -191,8 +192,9 @@ small_and_beautiful_theme = gr.themes.Soft(
|
|
191 |
),
|
192 |
neutral_hue=gr.themes.Color(
|
193 |
name="gray",
|
194 |
-
c50="#
|
195 |
-
c100="#f3f4f6",
|
|
|
196 |
c200="#e5e7eb",
|
197 |
c300="#d1d5db",
|
198 |
c400="#B2B2B2",
|
@@ -200,25 +202,28 @@ small_and_beautiful_theme = gr.themes.Soft(
|
|
200 |
c600="#636363",
|
201 |
c700="#515151",
|
202 |
c800="#393939",
|
203 |
-
c900="#272727",
|
|
|
204 |
c950="#171717",
|
205 |
),
|
206 |
radius_size=gr.themes.sizes.radius_sm,
|
207 |
).set(
|
208 |
-
button_primary_background_fill="
|
209 |
-
button_primary_background_fill_dark="
|
210 |
-
button_primary_background_fill_hover="
|
211 |
-
button_primary_border_color="
|
212 |
-
button_primary_border_color_dark="
|
213 |
-
button_primary_text_color="
|
214 |
-
button_primary_text_color_dark="
|
215 |
-
button_secondary_background_fill="
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
219 |
# background_fill_primary="#F7F7F7",
|
220 |
# background_fill_primary_dark="#1F1F1F",
|
221 |
-
block_title_text_color="*primary_500",
|
222 |
-
|
|
|
223 |
input_background_fill="#F6F6F6",
|
224 |
)
|
|
|
164 |
|
165 |
small_and_beautiful_theme = gr.themes.Soft(
|
166 |
primary_hue=gr.themes.Color(
|
167 |
+
c50="#EBFAF2",
|
168 |
+
c100="#CFF3E1",
|
169 |
+
c200="#A8EAC8",
|
170 |
+
c300="#77DEA9",
|
171 |
+
c400="#3FD086",
|
172 |
+
c500="#02C160",
|
173 |
+
c600="#06AE56",
|
174 |
+
c700="#05974E",
|
175 |
+
c800="#057F45",
|
176 |
+
c900="#04673D",
|
177 |
+
c950="#2E5541",
|
178 |
+
name="small_and_beautiful",
|
179 |
),
|
180 |
secondary_hue=gr.themes.Color(
|
181 |
c50="#576b95",
|
|
|
192 |
),
|
193 |
neutral_hue=gr.themes.Color(
|
194 |
name="gray",
|
195 |
+
c50="#f6f7f8",
|
196 |
+
# c100="#f3f4f6",
|
197 |
+
c100="#F2F2F2",
|
198 |
c200="#e5e7eb",
|
199 |
c300="#d1d5db",
|
200 |
c400="#B2B2B2",
|
|
|
202 |
c600="#636363",
|
203 |
c700="#515151",
|
204 |
c800="#393939",
|
205 |
+
# c900="#272727",
|
206 |
+
c900="#2B2B2B",
|
207 |
c950="#171717",
|
208 |
),
|
209 |
radius_size=gr.themes.sizes.radius_sm,
|
210 |
).set(
|
211 |
+
# button_primary_background_fill="*primary_500",
|
212 |
+
button_primary_background_fill_dark="*primary_600",
|
213 |
+
# button_primary_background_fill_hover="*primary_400",
|
214 |
+
# button_primary_border_color="*primary_500",
|
215 |
+
button_primary_border_color_dark="*primary_600",
|
216 |
+
button_primary_text_color="wihte",
|
217 |
+
button_primary_text_color_dark="white",
|
218 |
+
button_secondary_background_fill="*neutral_100",
|
219 |
+
button_secondary_background_fill_hover="*neutral_50",
|
220 |
+
button_secondary_background_fill_dark="*neutral_900",
|
221 |
+
button_secondary_text_color="*neutral_800",
|
222 |
+
button_secondary_text_color_dark="white",
|
223 |
# background_fill_primary="#F7F7F7",
|
224 |
# background_fill_primary_dark="#1F1F1F",
|
225 |
+
# block_title_text_color="*primary_500",
|
226 |
+
block_title_background_fill_dark="*primary_900",
|
227 |
+
block_label_background_fill_dark="*primary_900",
|
228 |
input_background_fill="#F6F6F6",
|
229 |
)
|