Code_editor / app.py
vsj0702's picture
adding dark mode
1a353ec verified
raw
history blame
2.37 kB
import streamlit as st
import streamlit_ace as st_ace
from utils import execute_code
from chatbot import render_chatbot
from layout import init_session_state, apply_theme
# Set initial page config
st.set_page_config(page_title="Pro Code Playground", page_icon="💻", layout="wide")
# Init session
init_session_state()
# Theme Toggle
theme_option = st.radio("🎨 Theme", options=["Light", "Dark"], index=0 if st.session_state.theme == "light" else 1, horizontal=True)
st.session_state.theme = "light" if theme_option == "Light" else "dark"
apply_theme(st.session_state.theme)
# App Header
st.title("Pro Code Playground")
st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
# Layout
gen, bot = st.columns((2, 1), gap="large")
with gen:
st.subheader("Editor")
code = st_ace.st_ace(
value=st.session_state.code,
placeholder="Start typing your Python code…",
language="python",
theme="chrome" if st.session_state.theme == "light" else "monokai",
keybinding="vscode",
font_size=14,
min_lines=20,
show_gutter=True,
wrap=True,
auto_update=True,
key="editor_code"
)
if code != st.session_state.code:
st.session_state.code = code
user_input = st.text_area(
"📥 Input (stdin)",
value=st.session_state.stdin,
placeholder="Enter input() values here, one per line",
height=100,
key="stdin_input"
)
if user_input != st.session_state.stdin:
st.session_state.stdin = user_input
if st.button("▶️ Run"):
out, err, exc = execute_code(st.session_state.code, st.session_state.stdin)
st.session_state.code_output = out
st.session_state.error_output = err or exc
if st.session_state.get("code_output"):
st.text_area("Output", st.session_state.code_output, height=120)
if st.session_state.get("error_output"):
st.error(st.session_state.error_output)
with bot:
st.subheader("Code Assistant")
render_chatbot(
st.session_state.code,
st.session_state.get("code_output", ""),
st.session_state.get("error_output", "")
)
# Footer
st.markdown("""
<div style='text-align:center; margin-top:1rem; opacity:0.6;'>
Built with ❤️ & Streamlit by Vaibhav
</div>
""", unsafe_allow_html=True)