Spaces:
Sleeping
Sleeping
splitting style and layout
Browse files
app.py
CHANGED
|
@@ -1,95 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import streamlit_ace as st_ace
|
| 3 |
-
from utils import execute_code
|
| 4 |
from chatbot import render_chatbot
|
| 5 |
-
import
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
st.set_page_config(
|
| 9 |
-
page_title="Pro Code Playground",
|
| 10 |
-
page_icon="💻",
|
| 11 |
-
layout="wide"
|
| 12 |
-
)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
st.session_state.dark_mode = False # Default is light mode
|
| 17 |
|
|
|
|
| 18 |
dm = st.checkbox("🌙 Dark mode", value=st.session_state.dark_mode)
|
| 19 |
st.session_state.dark_mode = dm
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
TEXT = "#e3e8f1" if dm else "#1a1a1a"
|
| 25 |
-
ACCENT = "#ff5252"
|
| 26 |
-
BORDER = "#2a3240" if dm else "#dddddd"
|
| 27 |
-
SHADOW = "rgba(0,0,0,0.3)" if dm else "rgba(0,0,0,0.1)"
|
| 28 |
-
ACE_THEME = "monokai" if dm else "chrome"
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
st.markdown(f"""
|
| 32 |
-
<style>
|
| 33 |
-
.stApp {{ background-color: {BG}; color: {TEXT}; }}
|
| 34 |
-
[data-testid="stSidebar"] {{ background-color: {PANEL_BG} !important; }}
|
| 35 |
-
.ace_editor, .ace_scroller {{
|
| 36 |
-
background: {PANEL_BG} !important;
|
| 37 |
-
box-shadow: 0 4px 8px {SHADOW} !important;
|
| 38 |
-
border-radius: 8px !important;
|
| 39 |
-
}}
|
| 40 |
-
textarea, input, .stTextArea textarea {{
|
| 41 |
-
background: {PANEL_BG} !important;
|
| 42 |
-
color: {TEXT} !important;
|
| 43 |
-
border: 1px solid {BORDER} !important;
|
| 44 |
-
border-radius: 4px !important;
|
| 45 |
-
}}
|
| 46 |
-
button, .stDownloadButton > button {{
|
| 47 |
-
background-color: {ACCENT} !important;
|
| 48 |
-
color: #fff !important;
|
| 49 |
-
border-radius: 6px !important;
|
| 50 |
-
transition: transform 0.1s;
|
| 51 |
-
}}
|
| 52 |
-
button:hover {{ transform: scale(1.02) !important; }}
|
| 53 |
-
.chat-container {{
|
| 54 |
-
background: {PANEL_BG} !important;
|
| 55 |
-
border: 1px solid {BORDER} !important;
|
| 56 |
-
border-radius: 8px !important;
|
| 57 |
-
padding: 1rem;
|
| 58 |
-
max-height: 480px;
|
| 59 |
-
overflow-y: auto;
|
| 60 |
-
}}
|
| 61 |
-
.chat-message {{ margin-bottom: 1rem; padding: 0.75rem 1rem; border-radius: 12px; }}
|
| 62 |
-
.user-message {{ background: rgba(100,149,237,0.2); align-self: flex-end; }}
|
| 63 |
-
.bot-message {{ background: rgba(200,200,200,0.2); align-self: flex-start; }}
|
| 64 |
-
pre code {{ display: block; padding: 0.5rem; background: rgba(0,0,0,0.1); border-radius: 4px; overflow-x: auto; }}
|
| 65 |
-
label[data-testid="stMarkdownContainer"] > div > div {{
|
| 66 |
-
color: {TEXT} !important;
|
| 67 |
-
}}
|
| 68 |
-
</style>
|
| 69 |
-
""", unsafe_allow_html=True)
|
| 70 |
-
|
| 71 |
-
# 5️⃣ Session state initialization
|
| 72 |
-
if 'code' not in st.session_state:
|
| 73 |
-
st.session_state.code = ""
|
| 74 |
-
|
| 75 |
-
if 'stdin' not in st.session_state:
|
| 76 |
-
st.session_state.stdin = ""
|
| 77 |
-
|
| 78 |
-
# 6️⃣ App header
|
| 79 |
st.title("Pro Code Playground")
|
| 80 |
st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
gen, bot = st.columns((2,1), gap="large")
|
| 84 |
|
| 85 |
with gen:
|
| 86 |
st.subheader("Editor")
|
| 87 |
-
|
| 88 |
code = st_ace.st_ace(
|
| 89 |
value=st.session_state.code,
|
| 90 |
placeholder="Start typing your Python code…",
|
| 91 |
language="python",
|
| 92 |
-
theme=ACE_THEME,
|
| 93 |
keybinding="vscode",
|
| 94 |
font_size=14,
|
| 95 |
min_lines=20,
|
|
@@ -102,7 +46,7 @@ with gen:
|
|
| 102 |
st.session_state.code = code
|
| 103 |
|
| 104 |
user_input = st.text_area(
|
| 105 |
-
"📥 Input (stdin)",
|
| 106 |
value=st.session_state.stdin,
|
| 107 |
placeholder="Enter input() values here, one per line",
|
| 108 |
height=100,
|
|
@@ -130,9 +74,9 @@ with bot:
|
|
| 130 |
st.session_state.get("error_output", "")
|
| 131 |
)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
st.markdown(f"""
|
| 135 |
-
<div style='text-align:center; margin-top:1rem; color:{TEXT}66;'>
|
| 136 |
Built with ❤️ & Streamlit by Vaibhav
|
| 137 |
</div>
|
| 138 |
""", unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import streamlit_ace as st_ace
|
| 3 |
+
from utils import execute_code
|
| 4 |
from chatbot import render_chatbot
|
| 5 |
+
from styles import get_theme_colors, inject_global_css
|
| 6 |
+
from layout import init_session_state
|
| 7 |
|
| 8 |
+
# Page configuration
|
| 9 |
+
st.set_page_config(page_title="Pro Code Playground", page_icon="💻", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Session init
|
| 12 |
+
init_session_state()
|
|
|
|
| 13 |
|
| 14 |
+
# Dark mode toggle
|
| 15 |
dm = st.checkbox("🌙 Dark mode", value=st.session_state.dark_mode)
|
| 16 |
st.session_state.dark_mode = dm
|
| 17 |
|
| 18 |
+
# Theme + CSS injection
|
| 19 |
+
colors = get_theme_colors(dm)
|
| 20 |
+
inject_global_css(colors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Header
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
st.title("Pro Code Playground")
|
| 24 |
st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
|
| 25 |
|
| 26 |
+
# Layout
|
| 27 |
+
gen, bot = st.columns((2, 1), gap="large")
|
| 28 |
|
| 29 |
with gen:
|
| 30 |
st.subheader("Editor")
|
| 31 |
+
|
| 32 |
code = st_ace.st_ace(
|
| 33 |
value=st.session_state.code,
|
| 34 |
placeholder="Start typing your Python code…",
|
| 35 |
language="python",
|
| 36 |
+
theme=colors["ACE_THEME"],
|
| 37 |
keybinding="vscode",
|
| 38 |
font_size=14,
|
| 39 |
min_lines=20,
|
|
|
|
| 46 |
st.session_state.code = code
|
| 47 |
|
| 48 |
user_input = st.text_area(
|
| 49 |
+
"📥 Input (stdin)",
|
| 50 |
value=st.session_state.stdin,
|
| 51 |
placeholder="Enter input() values here, one per line",
|
| 52 |
height=100,
|
|
|
|
| 74 |
st.session_state.get("error_output", "")
|
| 75 |
)
|
| 76 |
|
| 77 |
+
# Footer
|
| 78 |
st.markdown(f"""
|
| 79 |
+
<div style='text-align:center; margin-top:1rem; color:{colors["TEXT"]}66;'>
|
| 80 |
Built with ❤️ & Streamlit by Vaibhav
|
| 81 |
</div>
|
| 82 |
""", unsafe_allow_html=True)
|