Code_editor / layout.py
vsj0702's picture
fixing bug
67a88a2 verified
raw
history blame
3.11 kB
import streamlit as st
def init_session_state():
if "dark_mode" not in st.session_state:
st.session_state.dark_mode = False
if "code" not in st.session_state:
st.session_state.code = ""
if "stdin" not in st.session_state:
st.session_state.stdin = ""
def theme_toggle():
theme_choice = st.radio(
"🎨 Theme",
options=["β˜€οΈ", "πŸŒ™"],
horizontal=True,
label_visibility="collapsed"
)
st.session_state.dark_mode = (theme_choice == "πŸŒ™")
return st.session_state.dark_mode
def apply_theme():
dm = st.session_state.dark_mode
colors = {
"bg": "#0f1620" if dm else "#f5f5f5",
"panel_bg": "#1c2330" if dm else "#ffffff",
"text": "#e3e8f1" if dm else "#1a1a1a",
"accent": "#ff5252",
"border": "#2a3240" if dm else "#dddddd",
"shadow": "rgba(0,0,0,0.3)" if dm else "rgba(0,0,0,0.1)",
}
ace_theme = "monokai" if dm else "chrome"
st.markdown(
f"""
<style>
.stApp {{
background-color: {colors["bg"]};
color: {colors["text"]};
}}
[data-testid="stSidebar"] {{
background-color: {colors["panel_bg"]} !important;
}}
.ace_editor, .ace_scroller {{
background: {colors["panel_bg"]} !important;
box-shadow: 0 4px 8px {colors["shadow"]} !important;
border-radius: 8px !important;
}}
textarea, input, .stTextArea textarea {{
background: {colors["panel_bg"]} !important;
color: {colors["text"]} !important;
border: 1px solid {colors["border"]} !important;
border-radius: 4px !important;
}}
label, .stTextLabel, .stTextArea label {{
color: {colors["text"]} !important;
}}
button, .stDownloadButton > button {{
background-color: {colors["accent"]} !important;
color: #fff !important;
border-radius: 6px !important;
transition: transform 0.1s;
}}
button:hover {{
transform: scale(1.02) !important;
}}
.chat-container {{
background: {colors["panel_bg"]} !important;
border: 1px solid {colors["border"]} !important;
border-radius: 8px !important;
padding: 1rem;
max-height: 480px;
overflow-y: auto;
}}
.chat-message {{
margin-bottom: 1rem;
padding: 0.75rem 1rem;
border-radius: 12px;
}}
.user-message {{
background: rgba(100,149,237,0.2);
align-self: flex-end;
}}
.bot-message {{
background: rgba(200,200,200,0.2);
align-self: flex-start;
}}
pre code {{
display: block;
padding: 0.5rem;
background: rgba(0,0,0,0.1);
border-radius: 4px;
overflow-x: auto;
}}
</style>
""",
unsafe_allow_html=True,
)
return colors, ace_theme