krinya commited on
Commit
ffd8374
·
1 Parent(s): d9a89ae

Refactor CSS handling: Move CSS styles to a separate file and update Streamlit app to use the new CSS variable

Browse files
Files changed (2) hide show
  1. src/css_input.py +120 -0
  2. src/streamlit_app.py +5 -167
src/css_input.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # css_input.py
2
+ # Contains the CSS for the Streamlit app as a string
3
+
4
+ STREAMLIT_CSS = '''
5
+ <style>
6
+ /* Force light theme - completely override dark mode */
7
+ html, body, .stApp, [data-testid="stAppViewContainer"] {
8
+ background-color: #ffffff !important;
9
+ color: #262730 !important;
10
+ color-scheme: light !important;
11
+ }
12
+ @media (prefers-color-scheme: dark) {
13
+ html, body, .stApp, [data-testid="stAppViewContainer"] {
14
+ background-color: #ffffff !important;
15
+ color: #262730 !important;
16
+ }
17
+ }
18
+ * {
19
+ color-scheme: light !important;
20
+ }
21
+ :root {
22
+ --primary-color: #1976d2 !important;
23
+ --background-color: #ffffff !important;
24
+ --secondary-background-color: #f0f2f6 !important;
25
+ --text-color: #262730 !important;
26
+ color-scheme: light !important;
27
+ }
28
+ .stApp *, .stApp {
29
+ color: #262730 !important;
30
+ }
31
+ section[data-testid="stSidebar"], .css-1d391kg {
32
+ background-color: #f0f2f6 !important;
33
+ color: #262730 !important;
34
+ }
35
+ .main .block-container {
36
+ background-color: #ffffff !important;
37
+ color: #262730 !important;
38
+ }
39
+ /* Blue theme for Streamlit with dark mode compatibility */
40
+ .stApp {
41
+ background: linear-gradient(135deg, #e3f2fd 0%, #f5f5f5 100%) !important;
42
+ color: #262730 !important;
43
+ }
44
+ .main-header {
45
+ text-align: center;
46
+ padding: 0.5rem 0.5rem 0.5rem 0.5rem;
47
+ border-bottom: 2px solid #1976d2;
48
+ margin-bottom: 1rem;
49
+ background: linear-gradient(135deg, #2196f3, #1976d2) !important;
50
+ color: white !important;
51
+ border-radius: 8px;
52
+ margin: -0.5rem -0.5rem 1rem -0.5rem;
53
+ }
54
+ .main-header h1, .main-header p {
55
+ color: white !important;
56
+ }
57
+ .chat-container {
58
+ max-height: 500px;
59
+ overflow-y: auto;
60
+ padding: 1rem;
61
+ border-radius: 10px;
62
+ background-color: #f9f9f9 !important;
63
+ border: 1px solid #e3f2fd;
64
+ }
65
+ .stChatMessage {
66
+ border-radius: 10px;
67
+ margin-bottom: 1rem;
68
+ color: #262730 !important;
69
+ }
70
+ .stChatMessage[data-testid="chat-message-user"] {
71
+ background-color: #e3f2fd !important;
72
+ border: 1px solid #2196f3;
73
+ color: #262730 !important;
74
+ }
75
+ .stChatMessage[data-testid="chat-message-assistant"] {
76
+ background-color: #ffffff !important;
77
+ border: 1px solid #1976d2;
78
+ color: #262730 !important;
79
+ }
80
+ .stChatMessage * {
81
+ color: #262730 !important;
82
+ }
83
+ .stButton > button {
84
+ background-color: #1976d2 !important;
85
+ color: white !important;
86
+ border: none;
87
+ border-radius: 5px;
88
+ transition: all 0.3s;
89
+ }
90
+ .stButton > button:hover {
91
+ background-color: #1565c0 !important;
92
+ color: white !important;
93
+ }
94
+ .css-1d391kg, [data-testid="stSidebar"] {
95
+ background-color: #e3f2fd !important;
96
+ }
97
+ .css-1d391kg *, [data-testid="stSidebar"] * {
98
+ color: #262730 !important;
99
+ }
100
+ .stSuccess {
101
+ background-color: #e8f5e8 !important;
102
+ border: 1px solid #4caf50;
103
+ border-radius: 5px;
104
+ color: #2e7d32 !important;
105
+ }
106
+ .stTextInput input, .stChatInput input {
107
+ background-color: white !important;
108
+ color: #262730 !important;
109
+ border: 1px solid #1976d2;
110
+ }
111
+ @media (prefers-color-scheme: dark) {
112
+ .stApp, .stApp * {
113
+ color: #262730 !important;
114
+ }
115
+ .stChatMessage * {
116
+ color: #262730 !important;
117
+ }
118
+ }
119
+ </style>
120
+ '''
src/streamlit_app.py CHANGED
@@ -7,6 +7,7 @@ import csv
7
  from datetime import datetime
8
  from pypdf import PdfReader
9
  from chatbot_data.system_promt import system_prompt
 
10
 
11
  # Load environment variables
12
  load_dotenv()
@@ -22,170 +23,7 @@ st.set_page_config(
22
  initial_sidebar_state="collapsed"
23
  )
24
 
25
- # Force light theme and disable dark mode
26
- st.markdown("""
27
- <style>
28
- /* Force light theme - completely override dark mode */
29
- html, body, .stApp, [data-testid="stAppViewContainer"] {
30
- background-color: #ffffff !important;
31
- color: #262730 !important;
32
- color-scheme: light !important;
33
- }
34
-
35
- /* Override system dark mode preference */
36
- @media (prefers-color-scheme: dark) {
37
- html, body, .stApp, [data-testid="stAppViewContainer"] {
38
- background-color: #ffffff !important;
39
- color: #262730 !important;
40
- }
41
- }
42
-
43
- /* Force all elements to use light theme colors */
44
- * {
45
- color-scheme: light !important;
46
- }
47
-
48
- /* Override Streamlit's dark theme CSS variables */
49
- :root {
50
- --primary-color: #1976d2 !important;
51
- --background-color: #ffffff !important;
52
- --secondary-background-color: #f0f2f6 !important;
53
- --text-color: #262730 !important;
54
- color-scheme: light !important;
55
- }
56
-
57
- /* Ensure all text elements are dark colored */
58
- .stApp *, .stApp {
59
- color: #262730 !important;
60
- }
61
-
62
- /* Force sidebar to light theme */
63
- section[data-testid="stSidebar"], .css-1d391kg {
64
- background-color: #f0f2f6 !important;
65
- color: #262730 !important;
66
- }
67
-
68
- /* Force main content area to light theme */
69
- .main .block-container {
70
- background-color: #ffffff !important;
71
- color: #262730 !important;
72
- }
73
- </style>
74
- """, unsafe_allow_html=True)
75
-
76
- # Custom CSS for blue theme and better styling
77
- st.markdown("""
78
- <style>
79
- /* Blue theme for Streamlit with dark mode compatibility */
80
- .stApp {
81
- background: linear-gradient(135deg, #e3f2fd 0%, #f5f5f5 100%) !important;
82
- color: #262730 !important;
83
- }
84
-
85
- /* Header styling with dark mode override */
86
- .main-header {
87
- text-align: center;
88
- padding: 1rem 0;
89
- border-bottom: 3px solid #1976d2;
90
- margin-bottom: 2rem;
91
- background: linear-gradient(135deg, #2196f3, #1976d2) !important;
92
- color: white !important;
93
- border-radius: 10px;
94
- margin: -1rem -1rem 2rem -1rem;
95
- padding: 2rem 1rem;
96
- }
97
-
98
- .main-header h1, .main-header p {
99
- color: white !important;
100
- }
101
-
102
- /* Chat container styling */
103
- .chat-container {
104
- max-height: 500px;
105
- overflow-y: auto;
106
- padding: 1rem;
107
- border-radius: 10px;
108
- background-color: #f9f9f9 !important;
109
- border: 1px solid #e3f2fd;
110
- }
111
-
112
- /* Chat message styling with dark mode override */
113
- .stChatMessage {
114
- border-radius: 10px;
115
- margin-bottom: 1rem;
116
- color: #262730 !important;
117
- }
118
-
119
- /* User message styling */
120
- .stChatMessage[data-testid="chat-message-user"] {
121
- background-color: #e3f2fd !important;
122
- border: 1px solid #2196f3;
123
- color: #262730 !important;
124
- }
125
-
126
- /* Assistant message styling */
127
- .stChatMessage[data-testid="chat-message-assistant"] {
128
- background-color: #ffffff !important;
129
- border: 1px solid #1976d2;
130
- color: #262730 !important;
131
- }
132
-
133
- /* Ensure all text in chat messages is dark */
134
- .stChatMessage * {
135
- color: #262730 !important;
136
- }
137
-
138
- /* Button styling */
139
- .stButton > button {
140
- background-color: #1976d2 !important;
141
- color: white !important;
142
- border: none;
143
- border-radius: 5px;
144
- transition: all 0.3s;
145
- }
146
-
147
- .stButton > button:hover {
148
- background-color: #1565c0 !important;
149
- color: white !important;
150
- }
151
-
152
- /* Sidebar styling with dark mode override */
153
- .css-1d391kg, [data-testid="stSidebar"] {
154
- background-color: #e3f2fd !important;
155
- }
156
-
157
- /* Sidebar text color */
158
- .css-1d391kg *, [data-testid="stSidebar"] * {
159
- color: #262730 !important;
160
- }
161
-
162
- /* Success message styling */
163
- .stSuccess {
164
- background-color: #e8f5e8 !important;
165
- border: 1px solid #4caf50;
166
- border-radius: 5px;
167
- color: #2e7d32 !important;
168
- }
169
-
170
- /* Input field styling */
171
- .stTextInput input, .stChatInput input {
172
- background-color: white !important;
173
- color: #262730 !important;
174
- border: 1px solid #1976d2;
175
- }
176
-
177
- /* Dark mode media query override */
178
- @media (prefers-color-scheme: dark) {
179
- .stApp, .stApp * {
180
- color: #262730 !important;
181
- }
182
-
183
- .stChatMessage * {
184
- color: #262730 !important;
185
- }
186
- }
187
- </style>
188
- """, unsafe_allow_html=True)
189
 
190
  def load_knowledge_base():
191
  """Load and combine all knowledge base files"""
@@ -375,8 +213,8 @@ def main():
375
  if not st.session_state.messages:
376
  welcome_msg = """👋 **Welcome to Blue Bean Data!**
377
 
378
- I'm your AI assistant for data solutions. Ask me about:
379
- • Data consulting & strategy
380
  • BI dashboards & automation
381
  • Our team & expertise
382
 
@@ -390,7 +228,7 @@ How can I help you today?"""
390
  st.markdown(message["content"])
391
 
392
  # Chat input
393
- if prompt := st.chat_input("How can I help you with your data challenges?"):
394
  # Add user message to chat history
395
  st.session_state.messages.append({"role": "user", "content": prompt})
396
 
 
7
  from datetime import datetime
8
  from pypdf import PdfReader
9
  from chatbot_data.system_promt import system_prompt
10
+ from css_input import STREAMLIT_CSS
11
 
12
  # Load environment variables
13
  load_dotenv()
 
23
  initial_sidebar_state="collapsed"
24
  )
25
 
26
+ st.markdown(STREAMLIT_CSS, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def load_knowledge_base():
29
  """Load and combine all knowledge base files"""
 
213
  if not st.session_state.messages:
214
  welcome_msg = """👋 **Welcome to Blue Bean Data!**
215
 
216
+ I'm your AI assistant for data solutions. Ask me about:
217
+ • Data consulting & strategy
218
  • BI dashboards & automation
219
  • Our team & expertise
220
 
 
228
  st.markdown(message["content"])
229
 
230
  # Chat input
231
+ if prompt := st.chat_input("Type your question here..."):
232
  # Add user message to chat history
233
  st.session_state.messages.append({"role": "user", "content": prompt})
234