AlauStone commited on
Commit
68e6cc4
·
verified ·
1 Parent(s): d25e7c1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -74
app.py CHANGED
@@ -26,23 +26,57 @@ st.set_page_config(page_title="智答 AI 助手", page_icon="🤖", layout="wide
26
 
27
 
28
 
29
- @st.cache_data
30
  def _get_custom_css():
31
  return """
32
  <style>
33
- /* 暗色模式适配 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  @media (prefers-color-scheme: dark) {
35
  .main-title {
36
  background: #0e1117 !important;
 
37
  }
38
- .main-title h1, .main-title div {
39
  color: #fafafa !important;
40
  }
 
 
 
 
 
 
41
  [data-testid="stChatInput"] {
42
  background: #0e1117 !important;
43
  }
44
- /* 欢迎页文字颜色 */
45
- .welcome-marker, .welcome-marker * {
 
 
 
 
46
  color: #ccc !important;
47
  }
48
  .welcome-marker b {
@@ -51,7 +85,6 @@ def _get_custom_css():
51
  .welcome-hint {
52
  color: #888 !important;
53
  }
54
- /* 快捷问题按钮 */
55
  .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"] {
56
  color: #58a6ff !important;
57
  }
@@ -61,7 +94,6 @@ def _get_custom_css():
61
  .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"]:hover {
62
  background: rgba(255,255,255,0.1) !important;
63
  }
64
- /* 工具栏按钮 */
65
  .stMainBlockContainer > div > div > div:has(.toolbar-marker) button:hover {
66
  background: rgba(255,255,255,0.1) !important;
67
  }
@@ -70,60 +102,9 @@ def _get_custom_css():
70
  .stMainBlockContainer > div > div > div:has(.toolbar-marker) [data-testid="stMarkdownContainer"] p {
71
  color: #aaa !important;
72
  }
73
- /* 聊天消息气泡 */
74
  [data-testid="stChatMessage"] {
75
  border-color: #333 !important;
76
  }
77
- /* 用户消息背景 */
78
- [data-testid="stChatMessage"]:has([data-testid="chatAvatarIcon-user"]) {
79
- background: #1a1a2e !important;
80
- }
81
- }
82
- /* Streamlit 暗色主题适配 */
83
- [data-theme="dark"] .main-title,
84
- .stApp[data-theme="dark"] .main-title {
85
- background: #0e1117 !important;
86
- }
87
- [data-theme="dark"] .main-title h1,
88
- [data-theme="dark"] .main-title div,
89
- .stApp[data-theme="dark"] .main-title h1,
90
- .stApp[data-theme="dark"] .main-title div {
91
- color: #fafafa !important;
92
- }
93
- [data-theme="dark"] [data-testid="stChatInput"],
94
- .stApp[data-theme="dark"] [data-testid="stChatInput"] {
95
- background: #0e1117 !important;
96
- }
97
- /* Streamlit 暗色主题 - 欢迎页文字 */
98
- [data-theme="dark"] .welcome-marker,
99
- [data-theme="dark"] .welcome-marker *,
100
- .stApp[data-theme="dark"] .welcome-marker,
101
- .stApp[data-theme="dark"] .welcome-marker * {
102
- color: #ccc !important;
103
- }
104
- [data-theme="dark"] .welcome-marker b,
105
- .stApp[data-theme="dark"] .welcome-marker b {
106
- color: #fff !important;
107
- }
108
- [data-theme="dark"] .welcome-hint,
109
- .stApp[data-theme="dark"] .welcome-hint {
110
- color: #888 !important;
111
- }
112
- /* Streamlit 暗色主题 - 快捷问题按钮 */
113
- [data-theme="dark"] .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"],
114
- .stApp[data-theme="dark"] .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"] {
115
- color: #58a6ff !important;
116
- }
117
- [data-theme="dark"] .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"] p,
118
- .stApp[data-theme="dark"] .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"] p {
119
- color: #58a6ff !important;
120
- }
121
- /* Streamlit 暗色主题 - 工具栏按钮 */
122
- [data-theme="dark"] .stMainBlockContainer > div > div > div:has(.toolbar-marker) button p,
123
- [data-theme="dark"] .stMainBlockContainer > div > div > div:has(.toolbar-marker) button span,
124
- .stApp[data-theme="dark"] .stMainBlockContainer > div > div > div:has(.toolbar-marker) button p,
125
- .stApp[data-theme="dark"] .stMainBlockContainer > div > div > div:has(.toolbar-marker) button span {
126
- color: #aaa !important;
127
  }
128
 
129
  /* 隐藏工具栏标记 */
@@ -131,21 +112,12 @@ def _get_custom_css():
131
  display: none !important;
132
  }
133
 
134
- /* 游客提示颜色 - 默认浅色模式 */
135
  .guest-tip {
136
- color: #666 !important;
137
  }
138
  .guest-tip b {
139
- color: #444 !important;
140
- }
141
- /* 暗色模式下游客提示 */
142
- @media (prefers-color-scheme: dark) {
143
- .guest-tip {
144
- color: #999 !important;
145
- }
146
- .guest-tip b {
147
- color: #ccc !important;
148
- }
149
  }
150
 
151
  [data-testid="stSidebarContent"] { padding-top: 1.5rem !important; }
@@ -261,9 +233,14 @@ def _get_custom_css():
261
  left: 0 !important;
262
  right: 0 !important;
263
  z-index: 9999 !important;
264
- background: var(--background-color, white) !important;
265
  padding: 0.3rem 1rem !important;
266
  }
 
 
 
 
 
267
 
268
  /* 固定搜索框在底部 */
269
  [data-testid="stChatInput"] {
@@ -274,7 +251,12 @@ def _get_custom_css():
274
  width: calc(100% - 2rem) !important;
275
  max-width: 730px !important;
276
  z-index: 9999 !important;
277
- background: var(--background-color, white) !important;
 
 
 
 
 
278
  }
279
  /* 搜索框聚焦时去掉红色边框 */
280
  [data-testid="stChatInput"] textarea:focus,
@@ -283,16 +265,34 @@ def _get_custom_css():
283
  border-color: #ddd !important;
284
  box-shadow: none !important;
285
  }
286
- /* 暗色模式下搜索框边框 */
287
  @media (prefers-color-scheme: dark) {
 
 
 
 
288
  [data-testid="stChatInput"] textarea,
289
- [data-testid="stChatInput"] div {
 
 
 
290
  border-color: #333 !important;
 
 
 
 
291
  }
292
  [data-testid="stChatInput"] textarea:focus,
293
  [data-testid="stChatInput"] div:focus-within {
294
  border-color: #555 !important;
295
  }
 
 
 
 
 
 
 
296
  }
297
 
298
  /* 底部工具栏固定在搜索框下方 - 使用 toolbar-marker 精确定位 */
 
26
 
27
 
28
 
29
+ # 移除缓存,确保CSS即时更新
30
  def _get_custom_css():
31
  return """
32
  <style>
33
+ /* ===== 暗色模式全面适配 ===== */
34
+ /* 使用多种选择器确保覆盖所有暗色模式情况 */
35
+ @media (prefers-color-scheme: dark) {
36
+ :root {
37
+ --bg-color: #0e1117;
38
+ --text-color: #fafafa;
39
+ --text-muted: #ccc;
40
+ --text-hint: #888;
41
+ --border-color: #333;
42
+ --link-color: #58a6ff;
43
+ }
44
+ }
45
+ @media (prefers-color-scheme: light) {
46
+ :root {
47
+ --bg-color: white;
48
+ --text-color: #333;
49
+ --text-muted: #666;
50
+ --text-hint: #999;
51
+ --border-color: #ddd;
52
+ --link-color: #1a73e8;
53
+ }
54
+ }
55
+
56
+ /* 暗色模式 - 系统级 */
57
  @media (prefers-color-scheme: dark) {
58
  .main-title {
59
  background: #0e1117 !important;
60
+ color: #fafafa !important;
61
  }
62
+ .main-title h1 {
63
  color: #fafafa !important;
64
  }
65
+ .guest-tip {
66
+ color: #999 !important;
67
+ }
68
+ .guest-tip b {
69
+ color: #ccc !important;
70
+ }
71
  [data-testid="stChatInput"] {
72
  background: #0e1117 !important;
73
  }
74
+ [data-testid="stChatInput"] textarea,
75
+ [data-testid="stChatInput"] > div {
76
+ border-color: #333 !important;
77
+ background: #0e1117 !important;
78
+ }
79
+ .welcome-marker {
80
  color: #ccc !important;
81
  }
82
  .welcome-marker b {
 
85
  .welcome-hint {
86
  color: #888 !important;
87
  }
 
88
  .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"] {
89
  color: #58a6ff !important;
90
  }
 
94
  .block-container:has(.welcome-marker) [data-testid="stBaseButton-secondary"]:hover {
95
  background: rgba(255,255,255,0.1) !important;
96
  }
 
97
  .stMainBlockContainer > div > div > div:has(.toolbar-marker) button:hover {
98
  background: rgba(255,255,255,0.1) !important;
99
  }
 
102
  .stMainBlockContainer > div > div > div:has(.toolbar-marker) [data-testid="stMarkdownContainer"] p {
103
  color: #aaa !important;
104
  }
 
105
  [data-testid="stChatMessage"] {
106
  border-color: #333 !important;
107
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  }
109
 
110
  /* 隐藏工具栏标记 */
 
112
  display: none !important;
113
  }
114
 
115
+ /* 游客提示颜色 - 浅色模式默认 */
116
  .guest-tip {
117
+ color: #666;
118
  }
119
  .guest-tip b {
120
+ color: #444;
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
  [data-testid="stSidebarContent"] { padding-top: 1.5rem !important; }
 
233
  left: 0 !important;
234
  right: 0 !important;
235
  z-index: 9999 !important;
236
+ background: white !important;
237
  padding: 0.3rem 1rem !important;
238
  }
239
+ @media (prefers-color-scheme: dark) {
240
+ .main-title {
241
+ background: #0e1117 !important;
242
+ }
243
+ }
244
 
245
  /* 固定搜索框在底部 */
246
  [data-testid="stChatInput"] {
 
251
  width: calc(100% - 2rem) !important;
252
  max-width: 730px !important;
253
  z-index: 9999 !important;
254
+ background: white !important;
255
+ }
256
+ @media (prefers-color-scheme: dark) {
257
+ [data-testid="stChatInput"] {
258
+ background: #0e1117 !important;
259
+ }
260
  }
261
  /* 搜索框聚焦时去掉红色边框 */
262
  [data-testid="stChatInput"] textarea:focus,
 
265
  border-color: #ddd !important;
266
  box-shadow: none !important;
267
  }
268
+ /* 暗色模式下搜索框全面适配 */
269
  @media (prefers-color-scheme: dark) {
270
+ [data-testid="stChatInput"] {
271
+ background: #0e1117 !important;
272
+ }
273
+ [data-testid="stChatInput"] > div,
274
  [data-testid="stChatInput"] textarea,
275
+ [data-testid="stChatInput"] [data-testid="stChatInputContainer"],
276
+ [data-testid="stChatInput"] form,
277
+ [data-testid="stChatInput"] form > div {
278
+ background: #0e1117 !important;
279
  border-color: #333 !important;
280
+ color: #fafafa !important;
281
+ }
282
+ [data-testid="stChatInput"] textarea::placeholder {
283
+ color: #888 !important;
284
  }
285
  [data-testid="stChatInput"] textarea:focus,
286
  [data-testid="stChatInput"] div:focus-within {
287
  border-color: #555 !important;
288
  }
289
+ [data-testid="stChatInput"] button {
290
+ background: transparent !important;
291
+ color: #aaa !important;
292
+ }
293
+ [data-testid="stChatInput"] button svg {
294
+ fill: #aaa !important;
295
+ }
296
  }
297
 
298
  /* 底部工具栏固定在搜索框下方 - 使用 toolbar-marker 精确定位 */