Update app.py
Browse files
app.py
CHANGED
|
@@ -113,40 +113,79 @@ gradio-app { background: #0b1020 !important; }
|
|
| 113 |
.footer{ padding:26px 10px; text-align:center; color:#9eb2d8; }
|
| 114 |
"""
|
| 115 |
) as demo:
|
|
|
|
|
|
|
|
|
|
| 116 |
gr.HTML("""
|
| 117 |
<script>
|
| 118 |
(function(){
|
| 119 |
-
const
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
function paintShadow() {
|
| 125 |
-
const app = document.querySelector('gradio-app');
|
| 126 |
-
if (!app) return false;
|
| 127 |
-
const root = app.shadowRoot;
|
| 128 |
-
if (!root) return false;
|
| 129 |
-
// host 背景
|
| 130 |
-
app.style.background = DARK;
|
| 131 |
-
// shadow 内常见容器
|
| 132 |
-
const box = root.querySelector('.gradio-container');
|
| 133 |
-
if (box) box.style.background = DARK;
|
| 134 |
return true;
|
| 135 |
}
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
})();
|
| 144 |
</script>
|
| 145 |
""")
|
| 146 |
|
| 147 |
|
| 148 |
-
gr.HTML(topbar())
|
| 149 |
-
|
| 150 |
with gr.Row():
|
| 151 |
with gr.Column():
|
| 152 |
with gr.Group():
|
|
|
|
| 113 |
.footer{ padding:26px 10px; text-align:center; color:#9eb2d8; }
|
| 114 |
"""
|
| 115 |
) as demo:
|
| 116 |
+
|
| 117 |
+
gr.HTML(topbar())
|
| 118 |
+
|
| 119 |
gr.HTML("""
|
| 120 |
<script>
|
| 121 |
(function(){
|
| 122 |
+
const DARK_BG = '#0b1020';
|
| 123 |
+
const LIGHT_TXT = '#e7eefc';
|
| 124 |
+
|
| 125 |
+
// 先把外层页面刷成深色,避免初始白一下
|
| 126 |
+
document.documentElement.style.background = DARK_BG;
|
| 127 |
+
document.body.style.background = DARK_BG;
|
| 128 |
+
|
| 129 |
+
function injectIntoShadow() {
|
| 130 |
+
const host = document.querySelector('gradio-app');
|
| 131 |
+
if (!host || !host.shadowRoot) return false;
|
| 132 |
+
|
| 133 |
+
const root = host.shadowRoot;
|
| 134 |
+
|
| 135 |
+
// 1) 直接在 shadowRoot 里插入 <style>,覆盖容器背景 & 主题变量
|
| 136 |
+
const style = document.createElement('style');
|
| 137 |
+
style.setAttribute('data-jugglerl-shadow-style', '1');
|
| 138 |
+
style.textContent = `
|
| 139 |
+
:host, .gradio-container, body, html {
|
| 140 |
+
background: ${DARK_BG} !important;
|
| 141 |
+
color: ${LIGHT_TXT} !important;
|
| 142 |
+
}
|
| 143 |
+
/* 覆盖 Gradio 主题变量(不同版本命名略有区别,这里一次性全覆盖) */
|
| 144 |
+
:root {
|
| 145 |
+
--body-background-fill: ${DARK_BG} !important;
|
| 146 |
+
--background-fill-primary: ${DARK_BG} !important;
|
| 147 |
+
--background-fill-secondary: ${DARK_BG} !important;
|
| 148 |
+
--color-background: ${DARK_BG} !important;
|
| 149 |
+
--body-text-color: ${LIGHT_TXT} !important;
|
| 150 |
+
--color-foreground: ${LIGHT_TXT} !important;
|
| 151 |
+
--block-background-fill: #0f1630 !important;
|
| 152 |
+
--input-background-fill: #0f1630 !important;
|
| 153 |
+
--link-text-color: hsl(211, 100%, 70%) !important;
|
| 154 |
+
}
|
| 155 |
+
/* 常见容器兜底 */
|
| 156 |
+
.app, .container, .main, .content, .gradio-container * {
|
| 157 |
+
background-color: transparent;
|
| 158 |
+
}
|
| 159 |
+
`;
|
| 160 |
+
// 防止重复注入
|
| 161 |
+
if (!root.querySelector('style[data-jugglerl-shadow-style]')) {
|
| 162 |
+
root.appendChild(style);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
// 2) host 自身再兜底一次
|
| 166 |
+
host.style.background = DARK_BG;
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
return true;
|
| 169 |
}
|
| 170 |
|
| 171 |
+
// 尝试多次,直到 Gradio 的 shadowRoot 出现(Safari 上经常延迟)
|
| 172 |
+
let tries = 0;
|
| 173 |
+
const iv = setInterval(() => {
|
| 174 |
+
tries++;
|
| 175 |
+
if (injectIntoShadow() || tries > 100) { // 最多 ~5s
|
| 176 |
+
clearInterval(iv);
|
| 177 |
+
}
|
| 178 |
+
}, 50);
|
| 179 |
+
|
| 180 |
+
// 页面可见性变化时也再尝试一次(避免 Safari 恢复前台时丢样式)
|
| 181 |
+
document.addEventListener('visibilitychange', () => {
|
| 182 |
+
if (document.visibilityState === 'visible') injectIntoShadow();
|
| 183 |
+
});
|
| 184 |
})();
|
| 185 |
</script>
|
| 186 |
""")
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
| 189 |
with gr.Row():
|
| 190 |
with gr.Column():
|
| 191 |
with gr.Group():
|