vsj0702 commited on
Commit
d48e8d9
·
verified ·
1 Parent(s): 88377db

Adding input section

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -4,21 +4,21 @@ from utils import execute_code, export_session
4
  from chatbot import render_chatbot
5
  import json
6
 
7
- # 1️⃣ Page configuration (must be first)
8
  st.set_page_config(
9
  page_title="Pro Code Playground",
10
  page_icon="💻",
11
  layout="wide"
12
  )
13
 
14
- # 2️⃣ Dark mode toggle (default OFF)
15
  if 'dark_mode' not in st.session_state:
16
- st.session_state.dark_mode = False # Dark mode OFF by default
17
 
18
  dm = st.checkbox("🌙 Dark mode", value=st.session_state.dark_mode)
19
  st.session_state.dark_mode = dm
20
 
21
- # 3️⃣ Theme variables
22
  BG = "#0f1620" if dm else "#f5f5f5"
23
  PANEL_BG = "#1c2330" if dm else "#ffffff"
24
  TEXT = "#e3e8f1" if dm else "#1a1a1a"
@@ -27,28 +27,22 @@ 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
- # 4️⃣ Global CSS styling
31
  st.markdown(f"""
32
  <style>
33
  .stApp {{ background-color: {BG}; color: {TEXT}; }}
34
  [data-testid="stSidebar"] {{ background-color: {PANEL_BG} !important; }}
35
-
36
- /* Editor styling */
37
  .ace_editor, .ace_scroller {{
38
  background: {PANEL_BG} !important;
39
  box-shadow: 0 4px 8px {SHADOW} !important;
40
  border-radius: 8px !important;
41
  }}
42
-
43
- /* Input & textarea styling */
44
  textarea, input, .stTextArea textarea {{
45
  background: {PANEL_BG} !important;
46
  color: {TEXT} !important;
47
  border: 1px solid {BORDER} !important;
48
  border-radius: 4px !important;
49
  }}
50
-
51
- /* Button styling */
52
  button, .stDownloadButton > button {{
53
  background-color: {ACCENT} !important;
54
  color: #fff !important;
@@ -56,8 +50,6 @@ st.markdown(f"""
56
  transition: transform 0.1s;
57
  }}
58
  button:hover {{ transform: scale(1.02) !important; }}
59
-
60
- /* Chat styling */
61
  .chat-container {{
62
  background: {PANEL_BG} !important;
63
  border: 1px solid {BORDER} !important;
@@ -70,8 +62,6 @@ st.markdown(f"""
70
  .user-message {{ background: rgba(100,149,237,0.2); align-self: flex-end; }}
71
  .bot-message {{ background: rgba(200,200,200,0.2); align-self: flex-start; }}
72
  pre code {{ display: block; padding: 0.5rem; background: rgba(0,0,0,0.1); border-radius: 4px; overflow-x: auto; }}
73
-
74
- /* 🌙 Dark mode checkbox label styling */
75
  label[data-testid="stMarkdownContainer"] > div > div {{
76
  color: {TEXT} !important;
77
  }}
@@ -82,11 +72,12 @@ st.markdown(f"""
82
  st.title("Pro Code Playground")
83
  st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
84
 
85
- # 6️⃣ Main layout
86
  gen, bot = st.columns((2,1), gap="large")
87
 
88
  with gen:
89
  st.subheader("Editor")
 
90
  code = st_ace.st_ace(
91
  placeholder="Start typing your Python code…",
92
  language="python",
@@ -98,12 +89,21 @@ with gen:
98
  wrap=True,
99
  auto_update=True
100
  )
 
 
 
 
 
 
 
101
  if st.button("▶️ Run"):
102
- out, err, exc = execute_code(code)
103
  st.session_state.code_output = out
104
  st.session_state.error_output = err or exc
 
105
  if st.session_state.get("code_output"):
106
  st.text_area("Output", st.session_state.code_output, height=120)
 
107
  if st.session_state.get("error_output"):
108
  st.error(st.session_state.error_output)
109
 
 
4
  from chatbot import render_chatbot
5
  import json
6
 
7
+ # 1️⃣ Page configuration
8
  st.set_page_config(
9
  page_title="Pro Code Playground",
10
  page_icon="💻",
11
  layout="wide"
12
  )
13
 
14
+ # 2️⃣ Dark mode toggle
15
  if 'dark_mode' not in st.session_state:
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
+ # 3️⃣ Theme settings
22
  BG = "#0f1620" if dm else "#f5f5f5"
23
  PANEL_BG = "#1c2330" if dm else "#ffffff"
24
  TEXT = "#e3e8f1" if dm else "#1a1a1a"
 
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
+ # 4️⃣ CSS
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;
 
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;
 
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
  }}
 
72
  st.title("Pro Code Playground")
73
  st.markdown("Write, execute & export Python snippets, with built‑in AI assistance.")
74
 
75
+ # 6️⃣ Layout
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",
 
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, user_input)
101
  st.session_state.code_output = out
102
  st.session_state.error_output = err or exc
103
+
104
  if st.session_state.get("code_output"):
105
  st.text_area("Output", st.session_state.code_output, height=120)
106
+
107
  if st.session_state.get("error_output"):
108
  st.error(st.session_state.error_output)
109