vsj0702 commited on
Commit
b966d8e
·
verified ·
1 Parent(s): ac889ac

Adding dark mode

Browse files
Files changed (1) hide show
  1. layout.py +40 -6
layout.py CHANGED
@@ -1,9 +1,43 @@
1
  import streamlit as st
2
 
3
  def init_session_state():
4
- if 'dark_mode' not in st.session_state:
5
- st.session_state.dark_mode = False
6
- if 'code' not in st.session_state:
7
- st.session_state.code = ""
8
- if 'stdin' not in st.session_state:
9
- st.session_state.stdin = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
  def init_session_state():
4
+ st.session_state.setdefault("code", "")
5
+ st.session_state.setdefault("stdin", "")
6
+ st.session_state.setdefault("theme", "light")
7
+
8
+ def apply_theme(theme):
9
+ LIGHT = {
10
+ "bg": "#f5f5f5",
11
+ "panel": "#ffffff",
12
+ "text": "#1a1a1a",
13
+ "border": "#dddddd"
14
+ }
15
+ DARK = {
16
+ "bg": "#0f1620",
17
+ "panel": "#1c2330",
18
+ "text": "#e3e8f1",
19
+ "border": "#2a3240"
20
+ }
21
+
22
+ colors = DARK if theme == "dark" else LIGHT
23
+
24
+ st.markdown(f"""
25
+ <style>
26
+ .stApp {{
27
+ background-color: {colors["bg"]};
28
+ color: {colors["text"]};
29
+ }}
30
+ [data-testid="stSidebar"] {{
31
+ background-color: {colors["panel"]} !important;
32
+ }}
33
+ textarea, input, .stTextArea textarea {{
34
+ background-color: {colors["panel"]} !important;
35
+ color: {colors["text"]} !important;
36
+ border: 1px solid {colors["border"]} !important;
37
+ border-radius: 4px !important;
38
+ }}
39
+ label[data-testid="stMarkdownContainer"] > div > div {{
40
+ color: {colors["text"]} !important;
41
+ }}
42
+ </style>
43
+ """, unsafe_allow_html=True)