Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import streamlit_ace as st_ace | |
| from utils import execute_code | |
| from chatbot import render_chatbot | |
| from styles import get_theme_colors, inject_global_css | |
| from layout import init_session_state | |
| # Page configuration | |
| st.set_page_config(page_title="Pro Code Playground", page_icon="💻", layout="wide") | |
| # Session init | |
| init_session_state() | |
| # Dark mode toggle | |
| dm = st.checkbox("🌙 Dark mode", value=st.session_state.dark_mode) | |
| st.session_state.dark_mode = dm | |
| # Theme + CSS injection | |
| colors = get_theme_colors(dm) | |
| inject_global_css(colors) | |
| # 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=colors["ACE_THEME"], | |
| 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(f""" | |
| <div style='text-align:center; margin-top:1rem; color:{colors["TEXT"]}66;'> | |
| Built with ❤️ & Streamlit by Vaibhav | |
| </div> | |
| """, unsafe_allow_html=True) | |