Update app.py
Browse files
app.py
CHANGED
|
@@ -180,49 +180,77 @@ def bridge_predict_frame(frame, st):
|
|
| 180 |
# 4. Gradio 介面建構
|
| 181 |
# ==========================================
|
| 182 |
|
| 183 |
-
# --- [
|
| 184 |
-
# 這段 CSS 會偵測瀏覽器設定,強制將 Markdown 區塊 (.prose) 的文字顏色反轉
|
| 185 |
adaptive_css = """
|
|
|
|
| 186 |
@media (prefers-color-scheme: dark) {
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 190 |
}
|
| 191 |
-
|
| 192 |
-
|
|
|
|
| 193 |
color: #f8fafc !important;
|
| 194 |
}
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
.prose strong {
|
| 197 |
-
color: #fbbf24 !important; /*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
}
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 201 |
color: #e2e8f0 !important;
|
| 202 |
border-color: #475569 !important;
|
|
|
|
| 203 |
}
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
| 207 |
}
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
color: #e2e8f0 !important;
|
| 211 |
}
|
| 212 |
}
|
| 213 |
|
|
|
|
| 214 |
@media (prefers-color-scheme: light) {
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
color: #1f2937 !important;
|
| 218 |
}
|
| 219 |
-
.prose
|
| 220 |
-
color: #
|
| 221 |
}
|
| 222 |
}
|
| 223 |
"""
|
| 224 |
|
| 225 |
-
# 將原本的 emotion.css 與新的適應
|
| 226 |
combined_css = emotion.css + adaptive_css
|
| 227 |
|
| 228 |
with gr.Blocks(title="AI 心情食堂", css=combined_css) as demo:
|
|
|
|
| 180 |
# 4. Gradio 介面建構
|
| 181 |
# ==========================================
|
| 182 |
|
| 183 |
+
# --- [全面修正] 自動適應深色/淺色模式的 CSS ---
|
|
|
|
| 184 |
adaptive_css = """
|
| 185 |
+
/* === 針對深色模式 (Dark Mode) 的全面覆寫 === */
|
| 186 |
@media (prefers-color-scheme: dark) {
|
| 187 |
+
|
| 188 |
+
/* 1. 全域文字顏色 (預設轉為淺灰) */
|
| 189 |
+
.gradio-container, .gradio-container p, .gradio-container span, .gradio-container div {
|
| 190 |
+
color: #e2e8f0 !important;
|
| 191 |
}
|
| 192 |
+
|
| 193 |
+
/* 2. 標題 (H1-H6) 轉為亮白 */
|
| 194 |
+
h1, h2, h3, h4, h5, h6 {
|
| 195 |
color: #f8fafc !important;
|
| 196 |
}
|
| 197 |
+
|
| 198 |
+
/* 3. 輸入框與文字區 (Textbox, Textarea) - 確保深底白字 */
|
| 199 |
+
textarea, input[type="text"], .gr-input {
|
| 200 |
+
background-color: #1e293b !important; /* 深藍灰背景 */
|
| 201 |
+
color: #ffffff !important; /* 純白文字 */
|
| 202 |
+
border-color: #475569 !important; /* 邊框顏色 */
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
/* 4. 標籤 (Label) 與 選項 (Radio/Checkbox) */
|
| 206 |
+
label, .block-label, span.ml-2 {
|
| 207 |
+
color: #cbd5e1 !important; /* 稍微柔和的淺灰 */
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/* 5. Markdown 內容區塊 (.prose) */
|
| 211 |
+
.prose {
|
| 212 |
+
color: #e2e8f0 !important;
|
| 213 |
+
}
|
| 214 |
.prose strong {
|
| 215 |
+
color: #fbbf24 !important; /* 粗體字顯示金黃色,更明顯 */
|
| 216 |
+
}
|
| 217 |
+
.prose a {
|
| 218 |
+
color: #60a5fa !important; /* 連結顯示亮藍色 */
|
| 219 |
+
}
|
| 220 |
+
.prose code {
|
| 221 |
+
color: #f472b6 !important; /* 程式碼片段顯示粉色 */
|
| 222 |
+
background-color: #334155 !important;
|
| 223 |
}
|
| 224 |
+
|
| 225 |
+
/* 6. 表格 (Dataframe/Table) */
|
| 226 |
+
table, th, td {
|
| 227 |
color: #e2e8f0 !important;
|
| 228 |
border-color: #475569 !important;
|
| 229 |
+
background-color: #0f172a !important; /* 表格深色背景 */
|
| 230 |
}
|
| 231 |
+
|
| 232 |
+
/* 7. 分頁標籤 (Tabs) */
|
| 233 |
+
.tab-nav button.selected {
|
| 234 |
+
color: #3b82f6 !important; /* 選中的 Tab 亮藍色 */
|
| 235 |
+
border-bottom-color: #3b82f6 !important;
|
| 236 |
}
|
| 237 |
+
.tab-nav button {
|
| 238 |
+
color: #94a3b8 !important; /* 未選中的 Tab 灰色 */
|
|
|
|
| 239 |
}
|
| 240 |
}
|
| 241 |
|
| 242 |
+
/* === 針對淺色模式 (Light Mode) 的確保設定 === */
|
| 243 |
@media (prefers-color-scheme: light) {
|
| 244 |
+
.gradio-container {
|
| 245 |
+
background-color: #ffffff !important;
|
|
|
|
| 246 |
}
|
| 247 |
+
.prose, p, label, span {
|
| 248 |
+
color: #1f2937 !important; /* 深灰/黑 */
|
| 249 |
}
|
| 250 |
}
|
| 251 |
"""
|
| 252 |
|
| 253 |
+
# 將原本的 emotion.css 與新的全面適應 CSS 合併
|
| 254 |
combined_css = emotion.css + adaptive_css
|
| 255 |
|
| 256 |
with gr.Blocks(title="AI 心情食堂", css=combined_css) as demo:
|