Spaces:
Sleeping
Sleeping
Adding dark mode
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ from utils import execute_code, export_session
|
|
| 4 |
from chatbot import render_chatbot
|
| 5 |
import json
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Page configuration
|
| 8 |
st.set_page_config(
|
| 9 |
page_title="Interactive Code Editor with AI Assistant",
|
|
@@ -24,8 +28,8 @@ Write, execute, and export Python code in this interactive editor.
|
|
| 24 |
The editor supports syntax highlighting and autocompletion.
|
| 25 |
""")
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
col1, col2= st.columns([1, 1])
|
| 29 |
|
| 30 |
with col1:
|
| 31 |
# Code Editor Section
|
|
@@ -33,7 +37,7 @@ with col1:
|
|
| 33 |
code = st_ace.st_ace(
|
| 34 |
placeholder="Write your Python code here...",
|
| 35 |
language="python",
|
| 36 |
-
theme=
|
| 37 |
keybinding="vscode",
|
| 38 |
font_size=14,
|
| 39 |
min_lines=25,
|
|
@@ -44,36 +48,34 @@ with col1:
|
|
| 44 |
auto_update=True
|
| 45 |
)
|
| 46 |
|
| 47 |
-
# Execute button and output
|
| 48 |
if st.button("▶️ Run Code", type="primary"):
|
| 49 |
output, error, exception = execute_code(code)
|
| 50 |
st.session_state.code_output = output
|
| 51 |
st.session_state.error_output = error if error else exception
|
| 52 |
|
| 53 |
-
# Display immediate
|
| 54 |
if st.session_state.code_output:
|
| 55 |
st.text_area("Output", st.session_state.code_output, height=100)
|
| 56 |
if st.session_state.error_output:
|
| 57 |
st.error(st.session_state.error_output)
|
| 58 |
|
| 59 |
with col2:
|
| 60 |
-
# AI Assistant Section
|
| 61 |
st.subheader("🤖 Code Assistant")
|
| 62 |
render_chatbot(code, st.session_state.code_output, st.session_state.error_output)
|
| 63 |
|
| 64 |
-
# Export options
|
| 65 |
st.markdown("---")
|
| 66 |
st.subheader("Export Options")
|
| 67 |
|
| 68 |
-
# Create export data
|
| 69 |
export_data = export_session(
|
| 70 |
code,
|
| 71 |
st.session_state.code_output,
|
| 72 |
st.session_state.error_output
|
| 73 |
)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
col1_export, col2_export= st.columns([5, 4])
|
| 77 |
|
| 78 |
with col1_export:
|
| 79 |
st.download_button(
|
|
@@ -96,4 +98,4 @@ st.markdown("""
|
|
| 96 |
<div style='text-align: center'>
|
| 97 |
<p>Built with Streamlit ❤️</p>
|
| 98 |
</div>
|
| 99 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 4 |
from chatbot import render_chatbot
|
| 5 |
import json
|
| 6 |
|
| 7 |
+
# 1️⃣ Theme selector in the sidebar
|
| 8 |
+
theme = st.sidebar.selectbox("🎨 Editor Theme", ["Light", "Dark"])
|
| 9 |
+
ace_theme = "chrome" if theme == "Light" else "monokai"
|
| 10 |
+
|
| 11 |
# Page configuration
|
| 12 |
st.set_page_config(
|
| 13 |
page_title="Interactive Code Editor with AI Assistant",
|
|
|
|
| 28 |
The editor supports syntax highlighting and autocompletion.
|
| 29 |
""")
|
| 30 |
|
| 31 |
+
# Main layout: two columns
|
| 32 |
+
col1, col2 = st.columns([1, 1])
|
| 33 |
|
| 34 |
with col1:
|
| 35 |
# Code Editor Section
|
|
|
|
| 37 |
code = st_ace.st_ace(
|
| 38 |
placeholder="Write your Python code here...",
|
| 39 |
language="python",
|
| 40 |
+
theme=ace_theme, # ← use selected theme
|
| 41 |
keybinding="vscode",
|
| 42 |
font_size=14,
|
| 43 |
min_lines=25,
|
|
|
|
| 48 |
auto_update=True
|
| 49 |
)
|
| 50 |
|
| 51 |
+
# Execute button and output capture
|
| 52 |
if st.button("▶️ Run Code", type="primary"):
|
| 53 |
output, error, exception = execute_code(code)
|
| 54 |
st.session_state.code_output = output
|
| 55 |
st.session_state.error_output = error if error else exception
|
| 56 |
|
| 57 |
+
# Display immediate results
|
| 58 |
if st.session_state.code_output:
|
| 59 |
st.text_area("Output", st.session_state.code_output, height=100)
|
| 60 |
if st.session_state.error_output:
|
| 61 |
st.error(st.session_state.error_output)
|
| 62 |
|
| 63 |
with col2:
|
| 64 |
+
# AI Assistant Section
|
| 65 |
st.subheader("🤖 Code Assistant")
|
| 66 |
render_chatbot(code, st.session_state.code_output, st.session_state.error_output)
|
| 67 |
|
| 68 |
+
# Export options
|
| 69 |
st.markdown("---")
|
| 70 |
st.subheader("Export Options")
|
| 71 |
|
|
|
|
| 72 |
export_data = export_session(
|
| 73 |
code,
|
| 74 |
st.session_state.code_output,
|
| 75 |
st.session_state.error_output
|
| 76 |
)
|
| 77 |
|
| 78 |
+
col1_export, col2_export = st.columns([5, 4])
|
|
|
|
| 79 |
|
| 80 |
with col1_export:
|
| 81 |
st.download_button(
|
|
|
|
| 98 |
<div style='text-align: center'>
|
| 99 |
<p>Built with Streamlit ❤️</p>
|
| 100 |
</div>
|
| 101 |
+
""", unsafe_allow_html=True)
|