vsj0702 commited on
Commit
f94219b
Β·
verified Β·
1 Parent(s): 8988e78

Adding dark mode on entire application

Browse files
Files changed (1) hide show
  1. app.py +65 -11
app.py CHANGED
@@ -1,22 +1,76 @@
1
  import streamlit as st
 
 
 
 
2
 
3
- # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
4
- # 1️⃣ PAGE CONFIG (MUST BE FIRST)
5
  st.set_page_config(
6
  page_title="Interactive Code Editor with AI Assistant",
7
  page_icon="πŸ’»",
8
  layout="wide"
9
  )
10
- # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
11
 
12
  # 2️⃣ THEME SELECTOR
13
- theme = st.sidebar.selectbox("🎨 Editor Theme", ["Light", "Dark"])
14
- ace_theme = "chrome" if theme == "Light" else "monokai"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- import streamlit_ace as st_ace
17
- from utils import execute_code, export_session
18
- from chatbot import render_chatbot
19
- import json
20
 
21
  # Initialize session state
22
  if 'code_output' not in st.session_state:
@@ -40,7 +94,7 @@ with col1:
40
  code = st_ace.st_ace(
41
  placeholder="Write your Python code here...",
42
  language="python",
43
- theme=ace_theme, # ← use the selected theme
44
  keybinding="vscode",
45
  font_size=14,
46
  min_lines=25,
@@ -99,6 +153,6 @@ with col2_export:
99
  # Footer
100
  st.markdown("""
101
  <div style='text-align: center'>
102
- <p>Built with Streamlit ❀️</p>
103
  </div>
104
  """, unsafe_allow_html=True)
 
1
  import streamlit as st
2
+ import streamlit_ace as st_ace
3
+ from utils import execute_code, export_session
4
+ from chatbot import render_chatbot
5
+ import json
6
 
7
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
8
+ # 1️⃣ PAGE CONFIG (MUST be the first Streamlit call)
9
  st.set_page_config(
10
  page_title="Interactive Code Editor with AI Assistant",
11
  page_icon="πŸ’»",
12
  layout="wide"
13
  )
14
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
15
 
16
  # 2️⃣ THEME SELECTOR
17
+ theme = st.sidebar.selectbox("🎨 App Theme", ["Light", "Dark"])
18
+ is_dark = (theme == "Dark")
19
+
20
+ # 3️⃣ MAP TO ACE EDITOR THEME
21
+ ace_theme = "monokai" if is_dark else "chrome"
22
+
23
+ # 4️⃣ DEFINE COLORS FOR GLOBAL CSS
24
+ bg_color = "#1e1e1e" if is_dark else "#ffffff"
25
+ text_color = "#e5e5e5" if is_dark else "#000000"
26
+ sidebar_bg = "#252526" if is_dark else "#f0f2f6"
27
+ button_bg = "#3a3d41" if is_dark else "#e7eaf0"
28
+ chat_bg = "#2e2e2e" if is_dark else "#f9f9f9"
29
+ border_color = "#444444" if is_dark else "#dddddd"
30
+ user_bg = "#3d5a80" if is_dark else "#e3f2fd"
31
+ bot_bg = "#555555" if is_dark else "#f5f5f5"
32
+
33
+ # 5️⃣ INJECT GLOBAL CSS
34
+ st.markdown(f"""
35
+ <style>
36
+ /* Main app background and text */
37
+ .stApp {{
38
+ background-color: {bg_color};
39
+ color: {text_color};
40
+ }}
41
+ /* Sidebar styling */
42
+ .css-1d391kg .css-1d391kg {{ /* wrapper class Streamlit uses for sidebar */
43
+ background-color: {sidebar_bg} !important;
44
+ color: {text_color};
45
+ }}
46
+ /* Buttons */
47
+ .stButton>button {{
48
+ background-color: {button_bg} !important;
49
+ color: {text_color} !important;
50
+ }}
51
+ /* Chat container and messages */
52
+ .chat-container {{
53
+ background-color: {chat_bg} !important;
54
+ color: {text_color} !important;
55
+ border: 1px solid {border_color} !important;
56
+ }}
57
+ .user-message {{
58
+ background-color: {user_bg} !important;
59
+ color: {text_color} !important;
60
+ }}
61
+ .bot-message {{
62
+ background-color: {bot_bg} !important;
63
+ color: {text_color} !important;
64
+ }}
65
+ /* Text area output box */
66
+ textarea {{
67
+ background-color: {chat_bg} !important;
68
+ color: {text_color} !important;
69
+ }}
70
+ </style>
71
+ """, unsafe_allow_html=True)
72
 
73
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
 
 
 
74
 
75
  # Initialize session state
76
  if 'code_output' not in st.session_state:
 
94
  code = st_ace.st_ace(
95
  placeholder="Write your Python code here...",
96
  language="python",
97
+ theme=ace_theme, # ← use the selected ACE theme
98
  keybinding="vscode",
99
  font_size=14,
100
  min_lines=25,
 
153
  # Footer
154
  st.markdown("""
155
  <div style='text-align: center'>
156
+ <p>Built with Streamlit By Vibhav with ❀️</p>
157
  </div>
158
  """, unsafe_allow_html=True)