Spaces:
Running
Running
Adding session to fix minor bugs
Browse files
app.py
CHANGED
|
@@ -68,17 +68,25 @@ st.markdown(f"""
|
|
| 68 |
</style>
|
| 69 |
""", unsafe_allow_html=True)
|
| 70 |
|
| 71 |
-
# 5️⃣
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
st.title("Pro Code Playground")
|
| 73 |
st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
|
| 74 |
|
| 75 |
-
#
|
| 76 |
gen, bot = st.columns((2,1), gap="large")
|
| 77 |
|
| 78 |
with gen:
|
| 79 |
st.subheader("Editor")
|
| 80 |
|
| 81 |
code = st_ace.st_ace(
|
|
|
|
| 82 |
placeholder="Start typing your Python code…",
|
| 83 |
language="python",
|
| 84 |
theme=ACE_THEME,
|
|
@@ -87,17 +95,24 @@ with gen:
|
|
| 87 |
min_lines=20,
|
| 88 |
show_gutter=True,
|
| 89 |
wrap=True,
|
| 90 |
-
auto_update=True
|
|
|
|
| 91 |
)
|
|
|
|
|
|
|
| 92 |
|
| 93 |
user_input = st.text_area(
|
| 94 |
"📥 Input (stdin)",
|
|
|
|
| 95 |
placeholder="Enter input() values here, one per line",
|
| 96 |
-
height=100
|
|
|
|
| 97 |
)
|
|
|
|
|
|
|
| 98 |
|
| 99 |
if st.button("▶️ Run"):
|
| 100 |
-
out, err, exc = execute_code(code,
|
| 101 |
st.session_state.code_output = out
|
| 102 |
st.session_state.error_output = err or exc
|
| 103 |
|
|
@@ -110,7 +125,7 @@ with gen:
|
|
| 110 |
with bot:
|
| 111 |
st.subheader("Code Assistant")
|
| 112 |
render_chatbot(
|
| 113 |
-
code,
|
| 114 |
st.session_state.get("code_output", ""),
|
| 115 |
st.session_state.get("error_output", "")
|
| 116 |
)
|
|
|
|
| 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 |
+
# 7️⃣ Layout
|
| 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,
|
|
|
|
| 95 |
min_lines=20,
|
| 96 |
show_gutter=True,
|
| 97 |
wrap=True,
|
| 98 |
+
auto_update=True,
|
| 99 |
+
key="editor_code"
|
| 100 |
)
|
| 101 |
+
if code != st.session_state.code:
|
| 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,
|
| 109 |
+
key="stdin_input"
|
| 110 |
)
|
| 111 |
+
if user_input != st.session_state.stdin:
|
| 112 |
+
st.session_state.stdin = user_input
|
| 113 |
|
| 114 |
if st.button("▶️ Run"):
|
| 115 |
+
out, err, exc = execute_code(st.session_state.code, st.session_state.stdin)
|
| 116 |
st.session_state.code_output = out
|
| 117 |
st.session_state.error_output = err or exc
|
| 118 |
|
|
|
|
| 125 |
with bot:
|
| 126 |
st.subheader("Code Assistant")
|
| 127 |
render_chatbot(
|
| 128 |
+
st.session_state.code,
|
| 129 |
st.session_state.get("code_output", ""),
|
| 130 |
st.session_state.get("error_output", "")
|
| 131 |
)
|