Spaces:
Sleeping
Sleeping
| 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 = "" | |
| if "language" not in st.session_state: | |
| st.session_state.language = "Python" # Default | |
| def apply_theme(): | |
| dark = st.session_state.dark_mode | |
| colors = { | |
| "bg": "#0f1620" if dark else "#f5f5f5", | |
| "panel_bg": "#1c2330" if dark else "#ffffff", | |
| "text": "#e3e8f1" if dark else "#1a1a1a", | |
| "accent": "#ff5252", | |
| "border": "#2a3240" if dark else "#dddddd", | |
| "shadow": "rgba(0,0,0,0.3)" if dark else "rgba(0,0,0,0.1)", | |
| } | |
| # Map selected language to Ace supported values | |
| language = st.session_state.get("language", "python").lower() | |
| if language == "c++": | |
| language = "c_cpp" | |
| elif language == "c#": | |
| language = "csharp" | |
| elif language == "javascript": | |
| language = "javascript" | |
| elif language == "python": | |
| language = "python" | |
| elif language == "java": | |
| language = "java" | |
| elif language == "c": | |
| language = "c" | |
| ace_theme = "monokai" if dark else "chrome" | |
| # Inject CSS styles | |
| 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 | |