Spaces:
Sleeping
Sleeping
Fixing bug
Browse files
layout.py
CHANGED
|
@@ -1,111 +1,102 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
def init_session_state():
|
| 4 |
-
st.session_state
|
| 5 |
-
|
| 6 |
-
st.session_state
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
def apply_theme(theme):
|
| 9 |
-
import streamlit as st
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
-
|
| 16 |
-
"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
DARK = {
|
| 21 |
-
"bg": "#0f1620",
|
| 22 |
-
"panel": "#1c2330",
|
| 23 |
-
"text": "#e3e8f1",
|
| 24 |
-
"border": "#2a3240",
|
| 25 |
-
"button": "#ff5252",
|
| 26 |
-
"button_text": "#ffffff",
|
| 27 |
-
"placeholder": "#999999"
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
colors = DARK if theme == "dark" else LIGHT
|
| 31 |
-
|
| 32 |
-
st.markdown(f"""
|
| 33 |
-
<style>
|
| 34 |
-
/* Background & global text */
|
| 35 |
-
.stApp {{
|
| 36 |
-
background-color: {colors["bg"]};
|
| 37 |
-
color: {colors["text"]};
|
| 38 |
-
}}
|
| 39 |
-
|
| 40 |
-
/* Sidebar */
|
| 41 |
-
[data-testid="stSidebar"] {{
|
| 42 |
-
background-color: {colors["panel"]} !important;
|
| 43 |
-
}}
|
| 44 |
|
| 45 |
-
/* Form elements */
|
| 46 |
-
textarea, input[type="text"], .stTextArea textarea {{
|
| 47 |
-
background-color: {colors["panel"]} !important;
|
| 48 |
-
color: {colors["text"]} !important;
|
| 49 |
-
border: 1px solid {colors["border"]} !important;
|
| 50 |
-
border-radius: 4px !important;
|
| 51 |
-
}}
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
input::placeholder {{
|
| 56 |
-
color: {colors["placeholder"]} !important;
|
| 57 |
-
}}
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
border-radius: 6px !important;
|
| 69 |
-
border: none !important;
|
| 70 |
-
transition: transform 0.1s;
|
| 71 |
-
}}
|
| 72 |
-
button:hover {{
|
| 73 |
-
transform: scale(1.02) !important;
|
| 74 |
-
}}
|
| 75 |
-
|
| 76 |
-
/* Radio buttons */
|
| 77 |
-
.stRadio > label {{
|
| 78 |
-
color: {colors["text"]} !important;
|
| 79 |
-
}}
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
</style>
|
| 111 |
-
""",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = ""
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def theme_toggle():
|
| 13 |
+
theme_choice = st.radio(
|
| 14 |
+
"🎨 Theme",
|
| 15 |
+
options=["☀️", "🌙"],
|
| 16 |
+
horizontal=True,
|
| 17 |
+
label_visibility="collapsed"
|
| 18 |
+
)
|
| 19 |
+
st.session_state.dark_mode = (theme_choice == "🌙")
|
| 20 |
+
return st.session_state.dark_mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
def apply_theme():
|
| 24 |
+
dm = st.session_state.dark_mode
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
colors = {
|
| 27 |
+
"bg": "#0f1620" if dm else "#f5f5f5",
|
| 28 |
+
"panel_bg": "#1c2330" if dm else "#ffffff",
|
| 29 |
+
"text": "#e3e8f1" if dm else "#1a1a1a",
|
| 30 |
+
"accent": "#ff5252",
|
| 31 |
+
"border": "#2a3240" if dm else "#dddddd",
|
| 32 |
+
"shadow": "rgba(0,0,0,0.3)" if dm else "rgba(0,0,0,0.1)",
|
| 33 |
+
"ace_theme": "monokai" if dm else "chrome",
|
| 34 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
st.markdown(
|
| 37 |
+
f"""
|
| 38 |
+
<style>
|
| 39 |
+
.stApp {{
|
| 40 |
+
background-color: {colors["bg"]};
|
| 41 |
+
color: {colors["text"]};
|
| 42 |
+
}}
|
| 43 |
+
[data-testid="stSidebar"] {{
|
| 44 |
+
background-color: {colors["panel_bg"]} !important;
|
| 45 |
+
}}
|
| 46 |
+
.ace_editor, .ace_scroller {{
|
| 47 |
+
background: {colors["panel_bg"]} !important;
|
| 48 |
+
box-shadow: 0 4px 8px {colors["shadow"]} !important;
|
| 49 |
+
border-radius: 8px !important;
|
| 50 |
+
}}
|
| 51 |
+
textarea, input, .stTextArea textarea {{
|
| 52 |
+
background: {colors["panel_bg"]} !important;
|
| 53 |
+
color: {colors["text"]} !important;
|
| 54 |
+
border: 1px solid {colors["border"]} !important;
|
| 55 |
+
border-radius: 4px !important;
|
| 56 |
+
}}
|
| 57 |
+
label, .stTextLabel, .stTextArea label {{
|
| 58 |
+
color: {colors["text"]} !important;
|
| 59 |
+
}}
|
| 60 |
+
button, .stDownloadButton > button {{
|
| 61 |
+
background-color: {colors["accent"]} !important;
|
| 62 |
+
color: #fff !important;
|
| 63 |
+
border-radius: 6px !important;
|
| 64 |
+
transition: transform 0.1s;
|
| 65 |
+
}}
|
| 66 |
+
button:hover {{
|
| 67 |
+
transform: scale(1.02) !important;
|
| 68 |
+
}}
|
| 69 |
+
.chat-container {{
|
| 70 |
+
background: {colors["panel_bg"]} !important;
|
| 71 |
+
border: 1px solid {colors["border"]} !important;
|
| 72 |
+
border-radius: 8px !important;
|
| 73 |
+
padding: 1rem;
|
| 74 |
+
max-height: 480px;
|
| 75 |
+
overflow-y: auto;
|
| 76 |
+
}}
|
| 77 |
+
.chat-message {{
|
| 78 |
+
margin-bottom: 1rem;
|
| 79 |
+
padding: 0.75rem 1rem;
|
| 80 |
+
border-radius: 12px;
|
| 81 |
+
}}
|
| 82 |
+
.user-message {{
|
| 83 |
+
background: rgba(100,149,237,0.2);
|
| 84 |
+
align-self: flex-end;
|
| 85 |
+
}}
|
| 86 |
+
.bot-message {{
|
| 87 |
+
background: rgba(200,200,200,0.2);
|
| 88 |
+
align-self: flex-start;
|
| 89 |
+
}}
|
| 90 |
+
pre code {{
|
| 91 |
+
display: block;
|
| 92 |
+
padding: 0.5rem;
|
| 93 |
+
background: rgba(0,0,0,0.1);
|
| 94 |
+
border-radius: 4px;
|
| 95 |
+
overflow-x: auto;
|
| 96 |
+
}}
|
| 97 |
</style>
|
| 98 |
+
""",
|
| 99 |
+
unsafe_allow_html=True,
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
return colors
|